sijie commented on a change in pull request #3876: Add the multi version schema support URL: https://github.com/apache/pulsar/pull/3876#discussion_r275129909
########## File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java ########## @@ -101,38 +95,43 @@ public void accept(Descriptors.FieldDescriptor fieldDescriptor) { } @Override - public byte[] encode(T message) { - return message.toByteArray(); - } + protected SchemaReader<T> loadReader(byte[] schemaVersion) { + throw new RuntimeException("ProtobufSchema don't support schema versioning"); } - @Override - public T decode(byte[] bytes) { - try { - return this.tParser.parseFrom(bytes); - } catch (Exception e) { - throw new RuntimeException(new SchemaSerializationException(e)); - } + public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of(Class<T> pojo) { + return of(pojo, new HashMap<>()); } - @Override - public SchemaInfo getSchemaInfo() { - return schemaInfo; + public static <T> ProtobufSchema ofGenericClass(Class<T> pojo, Map<String, String> properties) { + SchemaDefinition<T> schemaDefinition = SchemaDefinition.<T>builder().withPojo(pojo).withProperties(properties).build(); + return ProtobufSchema.of(schemaDefinition); } - public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of(Class<T> pojo) { - return of(pojo, Collections.emptyMap()); - } + public static <T> ProtobufSchema of(SchemaDefinition<T> schemaDefinition) { + Class<T> pojo = schemaDefinition.getPojo(); - public static ProtobufSchema ofGenericClass(Class pojo, Map<String, String> properties) { if (!com.google.protobuf.GeneratedMessageV3.class.isAssignableFrom(pojo)) { throw new IllegalArgumentException(com.google.protobuf.GeneratedMessageV3.class.getName() + " is not assignable from " + pojo.getName()); } - return new ProtobufSchema<>(properties, pojo); + + try{ + SchemaInfo schemaInfo = SchemaInfo.builder() + .schema(createProtobufAvroSchema(schemaDefinition.getPojo()).toString().getBytes(UTF_8)) + .type(SchemaType.PROTOBUF) + .name("") + .properties(schemaDefinition.getProperties()) + .build(); + return new ProtobufSchema(schemaInfo, Review comment: line 125-129 don't have the right indent. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services