protostuff/protostuff

How to serialize java class generated by protoc.exe using protostuff?

Closed this issue · 2 comments

zzhlhc commented
  • How to serialize java class generated by protoc.exe using protostuff?

  • For example, in the code below, User is a class generated by protoc.exe, and use the original serialization method to gen bytes rs1

User.Demo.Builder builder = User.Demo.newBuilder();
builder.setId("1").setAge(20).setName("mike").build();   
User.Demo userDemo = builder.build();   
byte[] rs1 = userDemo.toByteArray();

, but if use protoStuff:

byte[] rs2 = ProtostuffIOUtil.toByteArray(demo
   , RuntimeSchema.getSchema(User.Demo.Class)
   , buffer)
  • the correct result cannot be obtained (rs2 is longer than rs1 and Chinese is not displayed normally when deserialized), is there any way for protostuff to allow me to serialize User.demo and get result equals to rs1?

or should i give up and just let these two serialization methods exist in the project?

dyu commented

It will need extra codegen via java_v2protoc_schema
See https://protostuff.github.io/documentation/compiler-options/

zzhlhc commented

Thanks!