1

I try to implement this PR https://github.com/apache/pulsar/pull/8372 in dotnet client. As far as I get for now, generating message schema for input class works like this: Some class -> .proto for this class -> google wrapper from this .proto -> get Descriptor from the wrapper and proceed with serializations.

In integration tests there is an example which does exactly that:

 ProtobufNativeSchema<org.apache.pulsar.client.schema.proto.Test.TestMessage> protobufSchema

 = ProtobufNativeSchema.of(org.apache.pulsar.client.schema.proto.Test.TestMessage.class)

Where TestMessage is a .proto definition:

syntax = "proto3";
package proto;

import "ExternalTest.proto";

option java_package = "org.apache.pulsar.client.schema.proto";
option java_outer_classname = "Test";

enum TestEnum {
    SHARED = 0;
    FAILOVER = 1;
}

message SubMessage {
    string foo = 1;
    double bar = 2;
    message NestedMessage {
        string url = 1;
        string title = 2;
        repeated string snippets = 3;
    }
}

message TestMessage {
    string stringField = 1;
    double doubleField = 2;
    int32 intField = 6;
    TestEnum testEnum = 4;
    SubMessage nestedField = 5;
    repeated string repeatedField = 10;
    proto.external.ExternalMessage externalMessage = 11;
}

I cant understand how .proto gets converted into java class. There is a proto compiler https://developers.google.com/protocol-buffers/docs/reference/java-generated which can create java class from .proto; but it needs to be invoked by hand and only then class can be included in codebase and used. It looks like it is going "on the fly" in integration test example, at least I cant find generated class anywhere.

Reference for C# https://developers.google.com/protocol-buffers/docs/reference/csharp-generated does the same thing, but generates C# source files.

So how does it work in java client exactly?

Michael Snytko
  • 327
  • 3
  • 13

1 Answers1

0

As turns out, input class for generating schema should be of type GeneratedMessageV3. So, it's already pre-compiled by protobuf and all types in related parts of codebase are "constrained" to it with java reflection.

Michael Snytko
  • 327
  • 3
  • 13