Serializing ProtoMessage payload
Serializing ProtoMessage payload
31 Jan 2022, 09:26
Hi!
Is there any way to utilize ProtoMessage directly instead of the type classes in C#?
You can set the payload type with ProtoOAPayloadType but then serializing the appropriate message payload, using a dictionary of key/value pairs for the specific properties for instance, seems a bit tricky without knowing what number the field is in the proto definition.
Does anybody with some technical insight in the OpenApi.NET library know if there is a way already? It would be nice if this was possible, although it's mostly for testing.
Thanks!
Replies
kemenist
31 Jan 2022, 12:48
Yes exactly, those we're methods and classes I've been trying to use, it's just that I can't seem to get the ByteString payload to be correctly formatted.
Do you have any tips to get me on the right path? I'm thinking there would need to be some sort of StreamWriter involved?
Thanks!
@kemenist
amusleh
31 Jan 2022, 12:55
( Updated at: 31 Jan 2022, 12:57 )
RE:
kemenist said:
Yes exactly, those we're methods and classes I've been trying to use, it's just that I can't seem to get the ByteString payload to be correctly formatted.
Do you have any tips to get me on the right path? I'm thinking there would need to be some sort of StreamWriter involved?
Thanks!
Hi,
All Google Protobuf .NET objects implement the IMessage interface, which has a ToByteString method, please check the MessageFactory class code.
OpenAPI.NET OpenClient has several overloads of SendMessage method, please check each and use the one that you want to based on your condition.
@amusleh
amusleh
31 Jan 2022, 12:42
Hi,
If you are using OpenAPI.NET then you can use the SendMessage method overload that gets a ProtoMessage: OpenAPI.Net/OpenClient.cs at c39e7c973089a8e13ba00390a4fb2316c4efa8b8 · spotware/OpenAPI.Net (github.com)
There is also the MessageFactory static helper class that you can use: OpenAPI.Net/MessageFactory.cs at c39e7c973089a8e13ba00390a4fb2316c4efa8b8 · spotware/OpenAPI.Net (github.com)
@amusleh