Class ProtoJson
The protobuf JSON mapping over runtime descriptors: InvokeJson's converter.
Google.Protobuf's C# JsonParser/JsonFormatter need generated message
classes, which a descriptor built from gRPC reflection does not have (C# has no
DynamicMessage), so the mapping is implemented here on the wire format and checked
against those reference implementations on compiled test messages
(tests/Virtufin.Api.Tests/ProtoJsonConformanceTests.cs).
Encoding accepts a field by its proto name (code_source) or JSON name
(codeSource) and refuses any other key. Decoding writes proto field names
and default values (JsonFormatter with PreserveProtoFieldNames and
FormatDefaultValues): 64-bit integers as strings, enums by name, bytes as
base64, the well-known types in their JSON forms.
public sealed class ProtoJson
- Inheritance
-
ProtoJson
- Inherited Members
Constructors
ProtoJson(Func<string, MessageDescriptor?>)
The protobuf JSON mapping over runtime descriptors: InvokeJson's converter.
Google.Protobuf's C# JsonParser/JsonFormatter need generated message
classes, which a descriptor built from gRPC reflection does not have (C# has no
DynamicMessage), so the mapping is implemented here on the wire format and checked
against those reference implementations on compiled test messages
(tests/Virtufin.Api.Tests/ProtoJsonConformanceTests.cs).
Encoding accepts a field by its proto name (code_source) or JSON name
(codeSource) and refuses any other key. Decoding writes proto field names
and default values (JsonFormatter with PreserveProtoFieldNames and
FormatDefaultValues): 64-bit integers as strings, enums by name, bytes as
base64, the well-known types in their JSON forms.
public ProtoJson(Func<string, MessageDescriptor?> resolveType)
Parameters
resolveTypeFunc<string, MessageDescriptor>The message descriptor of a full type name, for
google.protobuf.Any.
Fields
MaxDepth
The deepest nesting accepted, as Google.Protobuf's default recursion limit.
public const int MaxDepth = 100
Field Value
Methods
Decode(byte[], MessageDescriptor)
The JSON of the binary message data of descriptor.
public string Decode(byte[] data, MessageDescriptor descriptor)
Parameters
databyte[]descriptorMessageDescriptor
Returns
Encode(MessageDescriptor, JsonElement)
The binary encoding of json as descriptor.
public byte[] Encode(MessageDescriptor descriptor, JsonElement json)
Parameters
descriptorMessageDescriptorjsonJsonElement
Returns
- byte[]
Exceptions
- ProtoJsonException
The JSON is not that message.