How to use _unknownFields in RPC Client?

12 views
Skip to first unread message

erik stroeken

unread,
Dec 14, 2019, 8:01:48 AM12/14/19
to Protocol Buffers

I've an RPC server with this interface:

syntax = "proto3";import "google/protobuf/descriptor.proto";
import "google/protobuf/empty.proto";
option csharp_namespace = "RpcVersioningClient.Services";
service MachineService {
    rpc GetCounters (google.protobuf.Empty) returns (CountersMessage);
}

message CountersMessage {
    int32 module_counter = 1;
}

Suppose I have a client with a newer version and it's not possible to update the server. The client has a new field in CountersMessage:

syntax = "proto3";import "google/protobuf/descriptor.proto";
import "google/protobuf/empty.proto";
option csharp_namespace = "RpcVersioningClient.Services";

service MachineService {
    rpc GetCounters (google.protobuf.Empty) returns (CountersMessage);
}

message CountersMessage {
    int32 module_counter = 1;
    int32 new_module_counter = 2;
}

The field defaults to '0' and since proto3 doesn't allow to specify default values, I can't use the value to find out if the server supports the field. By analyzing the generated message class, I found out, that there is a private field _unknownFields that sounds like the information that I needed. After all new_module_counter is an known field for the server. Since the generated message class is partial, I can make a second partial class with public getter 'UnknownFields'.

public partial class CountersMessage
{
     public UnknownFieldSet UnknownFields => return _unknownFields;
}

Unfortunately, the field is null after receiving the contents of the older server. Does anybody know what is the intention of this field?

Reply all
Reply to author
Forward
0 new messages