0

I have a column in the SQL table which is of type varbinary. With the use of EF Core, I fetch the data from the table and model it to a property of Byte[] type. Now I need to deserialize the byte[] to List of doubles with the help of protobuf-net.

Earlier the same thing was being done from a js code with the help of protobufjs library using the .proto file. Now with the code migration, this needs to be done with c#. Any help is appreciated.

  • What is your problem? What have you tried so far? Given that you have a `byte []` byte array containing the protocol buffer serialized list of doubles, you can wrap that in a memory stream as shown in [Protobuf-net Serialize/Deserialize to/from byte arrays](https://stackoverflow.com/q/24329961/3744182) and deserialize to a `List` using `var list = Serializer.Deserialize>(stream)` as shown in e.g. [Getting started with protobuf-net](https://stackoverflow.com/q/14535913/3744182). – dbc Oct 04 '21 at 16:59
  • I had tried var list = Serializer.Deserialize>(stream) but I got the count as 0 although the array had around 1000 elements. – codenet2502 Oct 04 '21 at 17:10
  • `Serializer.Deserialize>(stream)` looks OK, so is there any way you could provide a [mcve] showing what you have tried that does not work, e.g. by [editing](https://stackoverflow.com/posts/69439617/edit) your question to include your code and the `byte []` data as a base64 encoded string? If you're not sure how to encode and decode bas64 in c# see [How do I encode and decode a base64 string?](https://stackoverflow.com/q/11743160/3744182). – dbc Oct 04 '21 at 17:14
  • 1
    @codenet2502 I can almost certainly help here (I'm the author of protobuf-net), but could you please post some of the payload - perhaps as hex or base-64 - and the first few expected values, so I can give a reply with some hope of being correct? There are a few ways this could be encoded – Marc Gravell Oct 04 '21 at 18:15
  • Due to some constraints, I can't post any of the payload. Apologies for that. I can post the protobuf decoding code that is being used in JS. Please let me know, if that'll help. – codenet2502 Oct 05 '21 at 11:47
  • @codenet2502 - then can you post a synthetic example? E.g. using your old code, serialize a list with fake data like `[-1., 0., 0.5]` to binary, then attempt to deserialize using protobuf-net. If it fails, [edit] your question to add the fake data. (But if it succeeds, investigate whether the binary data is getting mangled somehow when being fetched by EF Core.) – dbc Oct 05 '21 at 14:53
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 09 '21 at 15:11

0 Answers0