Extensions in proto3

Viewed 4698

Given the following proto definitions:

syntax = "proto3";

import "google/protobuf/descriptor.proto";

option java_package = "com.example.dto";

option java_multiple_files = true;

extend google.protobuf.FieldOptions {
    Projector projector = 50002;
}

message Projector {
    string name = 1;
    string class = 2;
    bool default = 3;
}

message SearchRequest {
    string query = 1 [(projector) = {name: "queryProjector", class: "foobar"}];
    int32 page_number = 2;
    int32 result_per_page = 3;
}

How can I access the field extension?

As far as I understand extension still work in proto3, but are generally replaced by the Any type?

I came as this far:

final Descriptors.Descriptor descriptor = SearchRequest.getDescriptor();

final Descriptors.FieldDescriptor query = descriptor.findFieldByName("query");

Is this the right way? Whats the next step?

1 Answers
Related