A: 

Hohum, yup looks like a bug (now logged); repeatable example below. I'll see if I can fix it on the train (shortly). Sorry 'bout that:

using System;
using System.IO;
using ProtoBuf;
[ProtoContract]
public class Strange // test entity
{
    [ProtoMember(1)]
    public string Foo { get; set; } // test prop
    [ProtoMember(2)]
    public int Bar { get; set; } // test prop

    static void Main() {
        var original = new Strange { Foo = "abc", Bar = 123 };
        // serialize and deserialize with base-128
        using (MemoryStream ms = new MemoryStream()) {
            Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Base128,1);
            ms.Position = 0;
            object obj;
            Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms,
                PrefixStyle.Base128, i => typeof(Strange),out obj);
            var clone = (Strange)obj;
            Console.WriteLine("Foo via Base128: " + clone.Foo); // works fine
            Console.WriteLine("Bar via Base128: " + clone.Bar);
        }
        // serialize and deserialize with fixed-32
        using (MemoryStream ms = new MemoryStream())
        {
            Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Fixed32,1);
            ms.Position = 0;
            object obj;
            // BOOM here; oh how embarrassing
            Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms,
                PrefixStyle.Fixed32, i => typeof(Strange), out obj);
            var clone = (Strange)obj;
            Console.WriteLine("Foo via Fixed32: " + clone.Foo);
            Console.WriteLine("Bar via Fixed32: " + clone.Bar);
        }
    }
}
Marc Gravell
Okay. I'll wait for a feedback. Good luck ;-)I can go with the Base128, but as I told you in another question, my co-worker need to implement it in C++ and as you said, it would be easier for him if we use Fixed32.
Rafael Romão
I took a look at the source code and noticed the tag parameter is not supported for the Fixed32 prefix style. I use this parameter to identify the message, so Fixed32 is not a good option for me anyway.
Rafael Romão
Indeed; I looked at this earlier and reached the same conclusion; I was coming back to post an update but work hours intervened. There is no reason that we *can't* include the tag info with Fixed32 - indeed, looking at the code cold it seems odd to omit it - but at the moment it would be a lot simpler to work with base-128 ;-p It isn't very tricky to translate, especially to a C++ diehard. If you really want a prefix version of Fixed32 it isn't really *tricky* - but it is a change; and not *that* expensive (8 bytes per entity).
Marc Gravell

related questions