Question about converting message types

16 views
Skip to first unread message

Tal Maimon

unread,
Nov 23, 2021, 6:28:22 PM11/23/21
to Protocol Buffers
Hey!
New to Protobuf here, I was wondering if there are any means to enforce two messages structures having similar members.
Let's say that for example I'd like to have two packing options:
1. As compact and dynamic as possible for network and storage operations
2. Sparse for efficient rule matching

So basically I'd like to have a `to` and `from` functions generated between these messages and also enforcement if any of them changes as to not break compatibility.

I've created a simple protobuf code (is it even considered code?) for my case which you can find here https://pastebin.com/BhGgTKkE

The end goal is that in my example I'd like to have a `CompactEntry.toSparseEntry()` function

I understand that this might be a hard to implement feature as it requires different message to know each other. Also , I know that protobuf doesn't support inheritance. I was just wondering if anyone else tackled a similar issue and if there's a best practice around it.

Thanks a lot!


Reply all
Reply to author
Forward
0 new messages