Closed GoogleCodeExporter closed 8 years ago
Was the data serialized with a length prefix? That code is fairly well tested,
so I'm a
little surprised... what volume of data are we talking? (i.e. what is the
length?) - as
the prefix can *in theory* be 5 bytes long (unlikely though). Have you got any
complete
example I might be able to use to reproduce this?
Original comment by marc.gravell
on 16 Oct 2009 at 9:13
Thanks for replying to my poorly formatted report. Here is a class that shows
where I
have the problem. It is a short message. I did not include my proto message,
but that
should not be a factor.
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using System.Windows.Forms;
using biz.cgta.proto.oms;
namespace ProtoTest
{
public class ProtoTest
{
/*==============================================================================
=================*/
public ProtoTest()
{
int len32;
int len128;
bool test;
//CreateParams a proto message.
OmsMessage omsMessage = new OmsMessage();
omsMessage.message_type = OmsMessage.MessageType.MSG_TYPE_CONFIRMATION;
omsMessage.application_id = "application_id";
omsMessage.symbol = "symbol";
omsMessage.initial_qty = "initial_qty";
omsMessage.limit_price = "limit_price";
omsMessage.last_fill_qty = "last_fill_qty";
omsMessage.last_fill_price = "last_fill_price";
omsMessage.trader_id = "trader_hid";
MemoryStream textStream = new MemoryStream();
ProtoBuf.Serializer.SerializeWithLengthPrefix<OmsMessage>(textStream,
omsMessage, ProtoBuf.PrefixStyle.Fixed32);
textStream.Position = 0;
test = ProtoBuf.Serializer.TryReadLengthPrefix(textStream.GetBuffer(), 0,
5, ProtoBuf.PrefixStyle.Fixed32, out len32);
textStream = new MemoryStream();
ProtoBuf.Serializer.SerializeWithLengthPrefix<OmsMessage>(textStream,
omsMessage, ProtoBuf.PrefixStyle.Base128);
textStream.Position = 0;
test = ProtoBuf.Serializer.TryReadLengthPrefix(textStream.GetBuffer(), 0,
5, ProtoBuf.PrefixStyle.Base128, out len128);
Console.WriteLine("Fixed32 len: " + len32 + " Base128 len: " + len128);
}
}
}
Output:
Fixed32 len: 103 Base128 len: -1039857561
Original comment by abraham....@gmail.com
on 19 Oct 2009 at 3:43
You were right; there was a bug in TryReadLengthPrefix (fixed r275) [a
**really**
stupid bug; sorry] - but note that to use it in this way you must also
explicitly
specify zero for the "tag" parameter:
ProtoBuf.Serializer.SerializeWithLengthPrefix<OmsMessage>(textStream, omsMessage,
ProtoBuf.PrefixStyle.Base128,0);
Otherwise, and **only** in base128-mode (the existing documentation did mention
this), it includes a tag-prefix to make the stream a fully valid proto message
on the
wire. (It sounds like you don't need this).
To make this usage simpler, I've also added a TryReadLengthPrefix that accepts
a
Stream; see Examples/Issues/Issue80.cs for usage (but it should be pretty
obvious).
I'm on the train, so I don't know if the new zip will upload at the minute;
I'll try,
but I may have to do this later.
Original comment by marc.gravell
on 21 Oct 2009 at 6:00
Cool! That did the trick. Thanks for the fast response!
Original comment by abraham....@gmail.com
on 21 Oct 2009 at 1:24
Original comment by marc.gravell
on 21 Oct 2009 at 2:02
Original issue reported on code.google.com by
abraham....@gmail.com
on 16 Oct 2009 at 3:45