I am trying to use this list structure to save a collection of protobufs in a database as a Byte[]. I created my PBFs, and then created another buffer with an internal List of PBFs as follows. The problem is that during serialization, I get an unexpected sub-type error. My questions are:
1. What is the recommended way to save a collection of PBFs in a database cell?
2. How can I serialize a PBF which has a field which is a collection of other PBFs?
[ProtoContract]
class Buffers
{
[ProtoMember(2)]
public int user_id { get; set; }
...
}
[ProtoContract]
class Albums : Buffers
{
[ProtoMember(4)]
public int album_id { get; set; }
...
}
[ProtoContract]
class BuffersList
{
[ProtoMember(1)]
public List<Buffers> Items { get; set; }
public BuffersList()
{
Items = new List<Buffers>();
}
...
}
Now when I try:
Serializer.NonGeneric.SerializeWithLengthPrefix(<MemoryStream>, <BuffersList>, PrefixStyle.Base128, field);
the above line generates the error message: System.InvalidOperationException: Unexpected sub-type: Albums
Thanks
Manish
On Tuesday, June 22, 2010 4:31:21 PM UTC-4, Marc Gravell wrote:
That was exactly my thought. Something *broadly* like (untested):
[ProtoMember(1)]
public List<Foo> Foos {get;set;}
[ProtoMember(2), DefaultValue(false)]
private bool FoosHasValue {
get { return Foos != null; }
set { Foos = value ? ( Foos ?? new List<Foo>() ) : null; }
}
Note that this may have some impact if you are concatenating messages, and is slightly hacky - Kenton will be tutting, I expect ;p
Marc