Giter Club home page Giter Club logo

unpacker's Introduction

Unpacker

通过注解处理器生成TCP/串口数据解析器模板代码。

  • 在实体类中的属性上注解 @KField
  • 每个实体类必须有且只有一个 @KId

支持解析数据类型

  • String
  • int
  • long
  • byte

下载

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
}
	
	
dependencies {
    implementation 'com.github.kk-hua.Unpacker:annotation:v0.0.1-alpha'
    kapt 'com.github.kk-hua.Unpacker:processor:v0.0.1-alpha'
}

示例

//数据实体类
public class Test {

    //cmd指令编号,可以是数据中的某个值,但必须是唯一的,跟其它帧数据不能相同
    //value描述信息,说明Test是什么数据
    @KId(cmd = 1, value = "测试指令") 
    @KField(index = 0)
    private String head;
    
    //index表示在帧数据中的开始下标
    //byteLen表示字节长度,默认是一个byte
    @KField(index = 1, byteLen = 2)
    private int length;
    @KField(index = 3, byteLen = 4)
    private int bi;
    @KField(index = 7,byteLen = 3)
    private long bo;

    public String getHead() {
        return head;
    }

    public void setHead(String head) {
        this.head = head;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getBi() {
        return bi;
    }

    public void setBi(int bi) {
        this.bi = bi;
    }

    public long getBo() {
        return bo;
    }

    public void setBo(long bo) {
        this.bo = bo;
    }

    @Override
    public String toString() {
        return "Test{" +
                "head='" + head + '\'' +
                ", length=" + length +
                ", bi=" + bi +
                ", bo=" + bo +
                '}';
    }
}
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun test(view: View) {
        val render: Test =
            RenderPool.get(1)
                .render(byteArrayOf(0x0, 0x1, 0x2, 0x0, 0x0, 0x5, 0x6, 0x7, 0x8, 0x9)) as Test
        Log.e("MainActivity", "obj=$render")
    }
}

//日志输出:
//MainActivity: obj=Test{head='00', length=258, bi=1286, bo=460809}

unpacker's People

Contributors

kk-hua avatar

Stargazers

李小义 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.