.net - ProtoBuf-Net to do raw read -
i want have simple piece of code iterate through random stream of protocol buffers, , print out contents without having explicit understanding of structural contents. equivalent xmlreader.read() inside while loop
using (protobuf.protoreader protoreader = new protobuf.protoreader(stream1, null, new protobuf.serializationcontext { })) { protoreader.readfieldheader(); while (protoreader.wiretype != protobuf.wiretype.none) { switch (protoreader.wiretype) { case protobuf.wiretype.fixed64: console.writeline(protoreader.readint64()); break; case protobuf.wiretype.fixed32: console.writeline(protoreader.readint32()); break; case protobuf.wiretype.startgroup: console.writeline(protoreader.readint32()); break; default: console.writeline(protoreader.wiretype); break; } } }
however don't know how advance protocol buffer next element. in test, keeps returning "startgroup" , never advancing. how can advance next element in stream?
the readfieldheader()
should inside loop:
while(protoreader.readfieldheader() > 0) { //... }
note: if don't know how process given field, there .skipfield()
method correctly read data - example:
default: console.writeline(protoreader.wiretype); protoreader.skipfield(); break;
you must read or skip data once per field-header.
in case of groups , sub-items, need use startsubitem
etc:
var tok = protoreader.startsubitem(protoreader); // inner while-loop, etc protoreader.endsubitem(tok);
alternatively: use skipfield()
.
Comments
Post a Comment