Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf-net version 2.X to 3.X migration

I am doing an update of my protobuf-net library reference, specifically from 2.4.4 to 3.0.101. Previously, we used null in lists as they contain meaningful information to the business (e.g., new[] { "one", "two", null, null, "five" }). However, they are not supported in 3.x yet as far as I understand (https://protobuf-net.github.io/protobuf-net/releasenotes#).

Is there a suggested migration strategy for collections with nulls?

I can mitigate the change going forward with additional fields (e.g., transposing the collection to a dictionary & back again on serializing/deserializing), however backwards compatibility seems broken for data serialied with 2.x libraries. Are there any migration guides?

like image 836
mike Avatar asked May 05 '21 03:05

mike


1 Answers

Given that 3.x doesn't yet support null retention, your options are somewhat limited:

  1. Submit a PR to add the missing feature. A quick glance through the protobuf source code makes me think that it would be fairly trivial to implement. In line 161 of the linked source file there seems to be a throw for nulls, which is where I'd start. I could be very wrong about how complicated this would be, though.
  2. See if you can use both libraries concurrently. You would need to know (or detect) whether data to serialize is in v2 or v3 format (I have not checked but would be surprised if there wasn't a way to detect this by looking at the first few bytes). You may need to compile a custom version to give it a different namespace, in order for the two to co-exist.
  3. Migrate data to v3. You can do this as a one-off operation (smaller amounts of data that you control) or on-demand (large amounts of data or externally received data). You'll need to re-design the types used in lists with nulls, so that you no longer have nulls (e.g. by having a custom value that logically represents null).
  4. Stay with v2. It's stable and works exceptionally well, so unless you have a specific need to upgrade it may not be worth the effort.
like image 126
Morten Mertner Avatar answered Sep 28 '22 11:09

Morten Mertner