CMertens / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

DeserializeWithLengthPrefix when using with Fixed32 or Fixed32BigEndian doesn't work as expected. #255

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When setting the field number of each serialization and using Base128 the 
reading of a message can be skipped, but this doesn't work with the Fixed32 or 
Fixed32BigEndian prefix style.

The last console.write will return "Second String" in this case:

var typeModel = TypeModel.Create();
var first = "First";
var second = "Second String";
var s = new MemoryStream();
typeModel.SerializeWithLengthPrefix(s, first, first.GetType(), 
PrefixStyle.Base128, 1);
typeModel.SerializeWithLengthPrefix(s, second, second.GetType(), 
PrefixStyle.Base128, 2);
s.Seek(0, SeekOrigin.Begin);
var newSecond = (string)typeModel.DeserializeWithLengthPrefix(s, null, 
typeof(string), PrefixStyle.Base128, 2);
Console.WriteLine(newSecond);

But if I change PrefixStyle to Fixed32 or Fixed32BigEndian the console output 
is "Second". Of course in a complex example the deserialization throws an 
exception.

typeModel.SerializeWithLengthPrefix(s, first, first.GetType(), 
PrefixStyle.Fixed32, 1);
typeModel.SerializeWithLengthPrefix(s, second, second.GetType(), 
PrefixStyle.Fixed32, 2);
s.Seek(0, SeekOrigin.Begin);
var newSecond = (string)typeModel.DeserializeWithLengthPrefix(s, null, 
typeof(string), PrefixStyle.Fixed32, 2);
Console.WriteLine(newSecond);

Original issue reported on code.google.com by lukas.bu...@gmail.com on 30 Nov 2011 at 12:45

GoogleCodeExporter commented 9 years ago
Edit: In the second case the output is "First"

Original comment by lukas.bu...@gmail.com on 30 Nov 2011 at 12:47