Giter Site home page Giter Site logo

tarscompiler's Introduction

TarsCompiler

Tars generated readFrom writeTo method by inherit

    implementation project(':TarsCompiler')
    annotationProcessor project(':TarsCompiler')
//  kotlin use kapt project(':TarsCompiler')

kotlin

@Tars
open class Test : TarsStructBase() {

    @JvmField
    @TarsId(tag = 1)
    var field1 = "s"

    @JvmField
    @TarsId(tag = 2)
    var field2 = 188

    @JvmField
//    @TarsId(tag = 3)
    var field3 = "188"

    override fun writeTo(output: TarsOutputStream) {
//        custom field3 code 
        if (field3 != "xxx")
            output.write(field3, 3)
    }
}

java

@Tars
public class Test1 extends TarsStructBase {
    @TarsId(tag = 1, require = true)
    protected String txt;
    @TarsId(tag = 3)
    public int anInt;
    @TarsId(tag = 6, require = true)
    char aChar;
    @TarsId(tag = 10)
    Map<String, Object> map;
}

Attention modifier not support private

call

    // original
    println(Test().toByteArray())
    // new add Tars suffix
    println(TestTars().toByteArray())

generated result

// This codes are generated automatically from Ore. Do not modify!
package xxx;

import java.lang.Object;
import java.lang.String;
import java.util.Map;

import moe.ore.tars.TarsInputStream;
import moe.ore.tars.TarsOutputStream;

public final class Test1Tars extends Test1 {
    public void writeTo(TarsOutputStream output) {
        super.writeTo(output);
        if (map != null) {
            output.write(map, 10);
        }
        if (txt != null) {
            output.write(txt, 1);
        }
        output.write(anInt, 3);
        output.write(aChar, 6);
    }

    public void readFrom(TarsInputStream input) {
        super.readFrom(input);
        map = (Map<String, Object>) input.read(map, 10, false);
        txt = (String) input.read(txt, 1, true);
        anInt = (int) input.read(anInt, 3, false);
        aChar = (char) input.read(aChar, 6, true);
    }
}

算了 不放洋屁了 就是自动生成一个包装类到build文件夹 类里面就是实现了两个方法而已 但是因为是继承实体类的 字段不能用private修饰 你不需要做其他操作 只管导包调用就行了

tarscompiler's People

Contributors

o2e 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.