在node.js应用程序中,我们需要反序列化一个包含多个对象的缓冲区。与
protobuf-net
这是这样做的:
var stream = new MemoryStream(byteData);
List<Schema.Object> objects = ProtoBuf.Serializer.Deserialize<List<Schema.Object>>(stream);
我现在也在努力
protobuf.js
.我没有找到一个创建模型对象数组的示例,只有一个模型对象,如:
const Object = root.lookupType('model.Object');
const message = Object.decode(byteData); //this creates one object but the buffer contains multiple objects
如何创建对象数组,而不是使用protobuf.js创建单个对象?
以下是数据序列化的方式:
try
{
using (var stream = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(stream, objects);
Stream.Position = 0;
// Return the serialized byte array.
return stream.ToArray();
}
}
finally {}
}