-
Notifications
You must be signed in to change notification settings - Fork 27
message is not copied in result of hydrateRepeated
#35
Comments
Yup, looks like a bug & looks like your proposed fix should work. Sloppy of me to not have unit tested this. Feel free to add a test, update the code & send a pull request. Will otherwise try to get to this in a couple of days... On a note, I'm not entirely happy with this particular routine. I had tried to eliminate construction of the throw-away ref object here by refactoring the entire library to use pass-by-reference (byref) - see this branch: https://github.com/ctaggart/froto/tree/pass-by-reference-and-record-serializer. Would be great to get that working, but I don't think it is possible to eliminate the runtime-error because .NET simply does not support byref and generic parameters |
I've fixed the above & added a unit test, but there is now an O(n^2) performance issue. While writing the unit tests, I noticed that repeated fields were not being kept in order (packed-repeated works, though). As a quick fix, hydrateRepeated does an append to the end of the list for every new element added. Not sure how to fix this long term without adding additional abstract methods to MessageBase, but that's probably going to be the solution. |
Fix issue #35 - message is not copied in result of `hydrateRepeated`
@tathanhdinh - please update your client code to rename |
I have a problem in using the function
hydrateRepeated
to deserializerepeated
fields where fields are message themselves. Concretely, I have aChunk
message with a repeated field ofInstruction
message (theprotobuf
file can be referenced here, to deserialize the messages, I have used this code. I observe that eachInstruction
is correctly deserialized, but the output list of instructions contains onlynull
objects.(that means each message is correctly deserialized, but the deserialized result is not copied into the output list!?).
Looking into the source code of
hydrateRepeated
, I observe thatelement
is an immutable value (though the argument passed tohydrater
is mutable)so that might be the reason why the deserialized value is not copied into the list. A trivial example is the following code:
The value of
i
is always3
. For the functionhydrateRepeated
, IMHO, the following fix might workThe text was updated successfully, but these errors were encountered: