GithubHelp home page GithubHelp logo

Comments (5)

xiemalin avatar xiemalin commented on July 20, 2024

能否在客户端 用 writeTo方法测试一下,还有你使用的版本是?
OutputStream out = resp.getOutputStream();
codec.writeTo(obj, CodedOutputStream.newInstance(out));

from jprotobuf.

Rekoe avatar Rekoe commented on July 20, 2024

1.7.9

from jprotobuf.

Rekoe avatar Rekoe commented on July 20, 2024
public class UserJProtoBufProtoClass {

    @Protobuf(fieldType = FieldType.INT64, order = 1, required = false)
    public Long id;
    @Protobuf(fieldType = FieldType.STRING, order = 2, required = false)
    public String name;
    @Protobuf(fieldType = FieldType.OBJECT, order = 4)
    public PhoneNumberJProtoBufProtoClass phone;

    public static class PhoneNumberJProtoBufProtoClass {
        @Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
        public String number;
    }
}
    public static void main(String[] args) throws IOException {
        UserJProtoBufProtoClass udbp = new UserJProtoBufProtoClass();
        udbp.id = System.currentTimeMillis();
        udbp.name = "lisi";
        Codec<UserJProtoBufProtoClass> codec = ProtobufProxy.create(UserJProtoBufProtoClass.class);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        //byte[] bytes = codec.encode(udbp);
        //out.write(bytes);

        codec.writeTo(udbp, CodedOutputStream.newInstance(out));

        UserJProtoBufProtoClass tem =codec.decode(out.toByteArray());
        System.out.println(Json.toJson(tem.id));

    }

确实有问题

from jprotobuf.

xiemalin avatar xiemalin commented on July 20, 2024

经测试,代码没有问题,应该你的使用API有问题
google的 protocol buffer 代码 CodedOutputStream.newInstance(out) 是不会自动回写到 out对象中的,所以你需对CodedOutputStream进行一下手工 flush. 代码如下:

        OutputStream os = new ByteArrayOutputStream();
        CodedOutputStream newInstance = CodedOutputStream.newInstance(os);
        codec.writeTo(newPojo, newInstance);
        newInstance.flush();
        System.out.println(os.toString());

from jprotobuf.

Rekoe avatar Rekoe commented on July 20, 2024

嗯 感谢

from jprotobuf.

Related Issues (20)

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.