congbobo184 commented on a change in pull request #13094:
URL: https://github.com/apache/pulsar/pull/13094#discussion_r764944799



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericProtobufReader.java
##########
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema.generic;
+
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import com.google.protobuf.InvalidProtocolBufferException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.SchemaSerializationException;
+import org.apache.pulsar.client.api.schema.Field;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.api.schema.SchemaReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Generic protobuf reader.
+ *
+ * @see GenericProtobufNativeReader
+ */
+@Slf4j
+public class GenericProtobufReader implements SchemaReader<GenericRecord> {
+    private final Descriptors.Descriptor descriptor;
+    private final byte[] schemaVersion;
+    private final List<Field> fields;
+
+    /**
+     * Create a new Generic protobuf reader by protobuf descriptor.
+     *
+     * @param descriptor protobuf descriptor
+     * @see Descriptors##descriptor
+     */
+    public GenericProtobufReader(Descriptors.Descriptor descriptor) {
+        this(descriptor, null);
+    }
+
+    /**
+     * Create a new Generic protobuf reader by protobuf descriptor and schema 
version.
+     *
+     * @param descriptor protobuf descriptor
+     * @see Descriptors##descriptor
+     */
+    public GenericProtobufReader(Descriptors.Descriptor descriptor, byte[] 
schemaVersion) {
+        try {
+            this.schemaVersion = schemaVersion;
+            this.descriptor = descriptor;
+            this.fields = descriptor.getFields()
+                    .stream()
+                    .map(f -> new Field(f.getName(), f.getIndex()))
+                    .collect(Collectors.toList());
+        } catch (Exception e) {
+            log.error("GenericProtobufReader init error", e);

Review comment:
       why cache Exception? 

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericProtobufRecord.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema.generic;
+
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.pulsar.client.api.schema.Field;
+
+import java.util.List;
+
+/**
+ * Generic protobuf record base on #{GenericProtobufNativeRecord}
+ *
+ * @see GenericProtobufNativeRecord
+ */
+public class GenericProtobufRecord extends GenericProtobufNativeRecord {

Review comment:
       may we should extends GenericProtobufRecordBase and 
GenericProtobufNativeRecord also should extends GenericProtobufRecordBase, 
GenericProtobufRecord should not extends GenericProtobufNativeRecord

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/MultiVersionGenericProtobufReader.java
##########
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema.generic;
+
+import com.google.protobuf.Descriptors;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.avro.Schema;
+import org.apache.avro.protobuf.ProtobufData;
+import org.apache.pulsar.client.api.SchemaSerializationException;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.api.schema.SchemaReader;
+import org.apache.pulsar.client.impl.schema.SchemaUtils;
+import org.apache.pulsar.client.impl.schema.reader.AbstractMultiVersionReader;
+import org.apache.pulsar.common.protocol.schema.BytesSchemaVersion;
+import org.apache.pulsar.common.schema.SchemaInfo;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
+
+@Slf4j
+public class MultiVersionGenericProtobufReader extends 
AbstractMultiVersionReader<GenericRecord>

Review comment:
       the same as MultiVersionGenericProtobufReader

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/ProtobufRecordBuilderImpl.java
##########
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema.generic;
+
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.pulsar.client.api.schema.Field;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.api.schema.GenericRecordBuilder;
+
+public class ProtobufRecordBuilderImpl implements GenericRecordBuilder {

Review comment:
       the same as ProtobufNativeRecordBuilderImpl




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to