gaoran10 commented on code in PR #1006:
URL: https://github.com/apache/pulsar-client-go/pull/1006#discussion_r1168104413
##########
pulsar/schema.go:
##########
@@ -219,6 +226,107 @@ func (ps *ProtoSchema) GetSchemaInfo() *SchemaInfo {
return &ps.SchemaInfo
}
+type ProtoNativeSchema struct {
+ SchemaInfo
+}
+
+func NewProtoNativeSchemaWithMessage(message proto.Message, properties
map[string]string) *ProtoNativeSchema {
+ return NewProtoNativeSchema(GetProtoNativeSchemaInfo(message),
properties)
+}
+
+func NewProtoNativeSchema(protoNativeSchemaDef string, properties
map[string]string) *ProtoNativeSchema {
+ pns := new(ProtoNativeSchema)
+ pns.SchemaInfo.Schema = protoNativeSchemaDef
+ pns.SchemaInfo.Type = ProtoNative
+ pns.SchemaInfo.Properties = properties
+ pns.SchemaInfo.Name = "ProtoNative"
+ return pns
+}
+
+func GetProtoNativeSchemaInfo(message proto.Message) string {
+ fileDesc := message.ProtoReflect().Descriptor().ParentFile()
+ fileProtoMap := make(map[string]*descriptorpb.FileDescriptorProto)
+ GetFileProto(fileDesc, fileProtoMap)
+
+ fileDescList := make([]*descriptorpb.FileDescriptorProto, 0,
len(fileProtoMap))
+ for k := range fileProtoMap {
+ value := descriptorpb.FileDescriptorProto{
+ Name: fileProtoMap[k].Name,
+ Package: fileProtoMap[k].Package,
+ Dependency: fileProtoMap[k].Dependency,
+ PublicDependency: fileProtoMap[k].PublicDependency,
+ MessageType: fileProtoMap[k].MessageType,
+ EnumType: fileProtoMap[k].EnumType,
+ Service: fileProtoMap[k].Service,
+ Extension: fileProtoMap[k].Extension,
+ Options: fileProtoMap[k].Options,
+ SourceCodeInfo: fileProtoMap[k].SourceCodeInfo,
+ Syntax: fileProtoMap[k].Syntax,
+ }
+ fileDescList = append(fileDescList, &value)
+ }
+ fileDescSet := descriptorpb.FileDescriptorSet{
+ File: fileDescList,
+ }
+ bytesData, err := proto.Marshal(&fileDescSet)
+ if err != nil {
+ log.Fatalf("get serialized proto file data error: %v", err)
Review Comment:
I found other schema-initialize functions also handle errors like this.
--
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]