我正在尝试使用 protostuff 将以下 Java 对象序列化为 protobuf:
public class HeaderTest
{
private int version;
private UUID messageId;
public HeaderTest() {} // required by jackson
public HeaderTest(UUID messageId, int version)
{
this.messageId = messageId;
this.version = version;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public UUID getMessageId() {
return messageId;
}
public void setMessageId(UUID messageId) {
this.messageId = messageId;
}
}
使用以下代码:
Schema<HeaderTest> headerTestSchema = RuntimeSchema.getSchema(HeaderTest.class);
byte[] headerTestBuff = ProtostuffIOUtil.toByteArray(headerTestInstance, headerTestSchema, LinkedBuffer.allocate());
我想获得固定大小的缓冲区,但 protostuff 将版本整数序列化为 varint 类型(用于表示整数的字节数根据整数大小而变化)
如何告诉 protostuff 以固定字节数将特定属性序列化为 fixed32
谢谢