[英]How to tell protostuff to pack property to fixed32 and not int32
I'm trying to serialize the following Java object to protobuf using protostuff: 我正在尝试使用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;
}
}
With the following code: 使用以下代码:
Schema<HeaderTest> headerTestSchema = RuntimeSchema.getSchema(HeaderTest.class);
byte[] headerTestBuff = ProtostuffIOUtil.toByteArray(headerTestInstance, headerTestSchema, LinkedBuffer.allocate());
I would like to get fixed size buffer but protostuff serialize the version integer as varint type ( the amount of bytes use to represent the integer changes according to the integer size ) 我想获得固定大小的缓冲区,但protostuff将版本整数序列化为varint类型(用于表示整数的字节数根据整数大小而变化)
How can I tell protostuff to serialize specific property as fixed32 with fix amount of bytes 我如何告诉protostuff将特定属性序列化为fixed32并具有固定的字节数
Thanks 谢谢
RuntimeSchema
does not allow you to select fixed32
as a type for integer field. RuntimeSchema
不允许您选择fixed32
作为整数字段的类型。 It can use only int32
/ int64
. 它只能使用int32
/ int64
。
The only thing that you can do - you can estimate maximum size of the buffer. 你唯一能做的就是 - 你可以估计缓冲区的最大大小。 Each int32
takes at most 5 bytes. 每个int32
最多占用5个字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.