CMertens / protobuf-net

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

How to use precompiled serializer and *WithLengthPrefix()? #345

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Precompiled serializer seems to be incompatible with these calls, especially 
that accept Stream as src/dst.

Maybe I miss something, but I still can not see what I miss :)

Thanks,
Alexey

Original issue reported on code.google.com by alexey.p...@gmail.com on 13 Dec 2012 at 11:52

GoogleCodeExporter commented 9 years ago
Can you give an example? You should be able to use, for example:

        var serializer = new MyCustomSerializer();

        var obj = new Foo { Bar = "abc" };

        var ms = new MemoryStream();
        serializer.SerializeWithLengthPrefix(ms, obj, null, ProtoBuf.PrefixStyle.Base128, 4);
        ms.Position = 0;
        var clone = (Foo)serializer.DeserializeWithLengthPrefix(
            ms, null, typeof(Foo), ProtoBuf.PrefixStyle.Base128, 4);

what happens differently?

Original comment by marc.gravell on 13 Dec 2012 at 12:28

GoogleCodeExporter commented 9 years ago
Sorry, I gave not that much of information.

With a typical serializer I write:
//...
Stream someStream;
//...
var msg = new MyMessage();
msg = 100500;
Protobuf.Serializer.SerializeWithLengthPrefix(someStream, msg, 
ProtoBuf.PrefixStyle.Base128);

And I don't specify any of FieldID, but what should I specify in precompiled 
version (where you have 4)?

Thanks and sorry for confusion,
Alexey

Original comment by alexey.p...@gmail.com on 13 Dec 2012 at 12:32

GoogleCodeExporter commented 9 years ago
To be compatible with that usage, 0

Original comment by marc.gravell on 13 Dec 2012 at 12:34

GoogleCodeExporter commented 9 years ago
Oh, tag is the same as fieldNumber, didn't figure that out, sorry :)

Original comment by alexey.p...@gmail.com on 13 Dec 2012 at 12:42

GoogleCodeExporter commented 9 years ago
Also, wanted to ask a quick question - there was RpcClient once, and as far as 
I can see, it has been removed. It's forever?

Original comment by alexey.p...@gmail.com on 13 Dec 2012 at 12:44

GoogleCodeExporter commented 9 years ago
v2 involved pretty-much a rewrite of the entire core; simply, that code was not 
on the critical path for getting something usable and useful, and I know it 
needs a bit of attention. I can try to get to it, but I've got a lot of other 
things (on various projects) that need doing too. Also: with tools like 
ServiceStack supporting protobuf-net, there are plenty of options available.

But: at the current time, that code has not been re-implemented for v2. I don't 
specifically want to kill it - I just haven't had time to open that can of 
worms.

Original comment by marc.gravell on 13 Dec 2012 at 12:56

GoogleCodeExporter commented 9 years ago
It's still something odd with precompiled version. What am I doing wrong? :(
error CS0143: The type 'Unity3D.Runtime.Protos.PrecompilerSerializer' has no 
constructors defined
on my version of 'var serializer = new MyCustomSerializer();', and .NET 
Reflector indeed shows no ctors there

Original comment by alexey.p...@gmail.com on 13 Dec 2012 at 1:55