import io.protostuff.Tag;
public class User {
@Tag(1)
private String name;
@Tag(2)
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
}
import io.protostuff.LinkedBuffer;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
public class Main {
public static void main(String[] args) {
User user = new User("Tom", 20);
Schema<User> schema = RuntimeSchema.getSchema(User.class);
byte[] data = ProtostuffIOUtil.toByteArray(user, schema, LinkedBuffer.allocate());
User newUser = schema.newMessage();
ProtostuffIOUtil.mergeFrom(data, newUser, schema);
}
}