public class Person { private String name; private int age; } Person person = new Person(); person.setAge(25); Schema<Person> schema = RuntimeSchema.getSchema(Person.class); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ProtostuffIOUtil.writeTo(byteArrayOutputStream, person, schema); byte[] byteArray = byteArrayOutputStream.toByteArray(); Person newPerson = schema.newMessage(); ProtostuffIOUtil.mergeFrom(byteArray, newPerson, schema); LinkedBuffer buffer = LinkedBuffer.allocate(512); BufferSerializer<Person> serializer = new BufferSerializer<>(schema, buffer); ProtostuffIOUtil.writeTo(output, person, serializer);


上一篇:
下一篇:
切换中文