Skip to content

How do I send a google.protobuf.Value object using protobuf-net.Grpc and code-first? #335

Open
@glazkovalex

Description

@glazkovalex

The protobuf format has the type google.protobuf.Value described in Create Protobuf messages for .NET apps.
There is also a Google.Protobuf.WellKnownTypes.Value type in the Google.Protobuf, Version=3.28.0.0 library.

I can send google.protobuf.Value with a message described by such a proto-file:

import "google/protobuf/struct.proto";

message Status {
// ...
    google.protobuf.Value data = 3;
}

As a result, I will get a generated dot with a "data" field of the type Google.Protobuf.WellKnownTypes.Value. I can assign an arbitrary JsonDocument to this "data" in the following way and everything will be transmitted perfectly.

var dto = new Status();
dto.Data = Google.Protobuf.WellKnownTypes.Value.Parser.ParseJson(myJsonDocument.RootElement.ToString())

I used protobuf-net.Grpc and applied code-first by creating such a dto with the field Google.Protobuf.WellKnownTypes.Value

[DataContract]
public class ObjectTypeDto
{
    [DataMember(Order = 1)]
    public Google.Protobuf.WellKnownTypes.Value Data { get; set; }
}

If I pass my myJsonDocument through it as before, I get an exception: System.InvalidOperationException: No serializer defined for type: Google.Protobuf.WellKnownTypes.Value

How do I send a google.protobuf.Value(Google.Protobuf.WellKnownTypes.Value) object using protobuf-net.Grpc and code-first?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions