leejw51 / protobuf-net

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

Problem with array of lists #192

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
ramisyuanbo@gmail.com
==============

What steps will reproduce the problem?
1. Make an array of lists like this: List<SomeType>[].
Make the length of the array 2. Fill it with 2 list.
2. Serialize this array
3. Deserialize it

What is the expected output? What do you see instead?
I expect to get an array of 2 lists. 
Instead I get an array of 1 list, containing the content from both the lists.

What version of the product are you using? On what operating system?
latest. 

Please provide any additional information below.

Original issue reported on code.google.com by ramisyua...@gmail.com on 23 Jun 2011 at 5:26

GoogleCodeExporter commented 9 years ago
Actually, I would expect that scenario to throw an exception; directly nested 
lists (including jagged arrays, etc) cannot be represented directly in a 
protobuf stream  - it is usually necessary to add an intermediate layer, i.e. 
an array of an object that *contains* a list.

This error certainly happens for such constructs *inside* a type model - a list 
at the root of the graph is slightly different; I'll see if I can make it throw 
the correct message.

Original comment by marc.gravell on 23 Jun 2011 at 11:34

GoogleCodeExporter commented 9 years ago
This scenario is now correctly detected and an exception thrown

Original comment by marc.gravell on 25 Jun 2011 at 9:50

GoogleCodeExporter commented 9 years ago
Hello Marc,
Thanks  for all the effort!
Still i wonder what's the idea behind the design that "directly nested lists 
could not be represented directly in a protobuf stream"?
Would you pls share the idea with us? 
Thanks a lot!
The improvement in serialization/dese efficiency is amazing over the .Net 
version!

Original comment by ramisyua...@gmail.com on 27 Jun 2011 at 12:52

GoogleCodeExporter commented 9 years ago
This is a side-effect of the protobuf stream format, as defined by google, and 
how "repeated" data is packed without any additional markers. However, thinking 
about it now I *can* see a way I could make this work... but the important 
thing is that it works the same for the two scenarios ;p

I'll re-open this, and see if I can get that hacked in at some point.

Original comment by marc.gravell on 27 Jun 2011 at 8:54

GoogleCodeExporter commented 9 years ago
Thanks again for all the effort!

Original comment by ramisyua...@gmail.com on 28 Jun 2011 at 5:18

GoogleCodeExporter commented 9 years ago
Hi Marc,
I've just encountered it as well on my own, when trying to store something like 
a List<List<X>>...

At first I didn't understand the true meaning of the limitation, so I tried to 
define a class like ListOfX and try to serialize a List<ListOfX> but protobuf 
detects this too...

Is there something simple that can be done with this?
You mentioned that you are re-opening the bug since you now think this can be 
solved within google's own spec... so here' me hoping... :)

Original comment by d...@houmus.org on 2 Oct 2011 at 4:48

GoogleCodeExporter commented 9 years ago
Is this issue fixed or if not can anyone give a workaround? I have a jagged 
array in my class. I cannot change it to an array of array(according to the 
workaround provided by Marc in in this thread. 
http://stackoverflow.com/questions/11134370/proto-buf-net-and-serialization) 
because this is an existing application and it's complex that we don't know the 
impact of changing the data structure. I also don't understand what is the 
workaround explained in this thread. 
http://stackoverflow.com/questions/4090173/using-protobuf-net-how-to-deserialize
-a-multi-dimensional-array

Original comment by vbsat...@gmail.com on 26 Apr 2013 at 3:10

GoogleCodeExporter commented 9 years ago
I wouldn't say "fixed" is the right word, as if anything it is a feature 
request. I have something in mind - getting the time is the trick :) I should 
have some this weekend/week.

Original comment by marc.gravell on 26 Apr 2013 at 3:15

GoogleCodeExporter commented 9 years ago
Thank you so much for quick response. appreciate it.

Original comment by vbsat...@gmail.com on 26 Apr 2013 at 3:19