sijie commented on a change in pull request #3904: [go schema] support go schema for pulsar-client-go URL: https://github.com/apache/pulsar/pull/3904#discussion_r275131218
########## File path: pulsar-client-go/pulsar/schema.go ########## @@ -0,0 +1,494 @@ +// +// 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 pulsar + +import ( + "bytes" + "encoding/json" + "errors" + "reflect" + "unsafe" + + log "github.com/apache/pulsar/pulsar-client-go/logutil" + + "github.com/gogo/protobuf/proto" + "github.com/linkedin/goavro" +) + +type SchemaType int + +const ( + NONE SchemaType = iota //No schema defined + STRING //Simple String encoding with UTF-8 + JSON //JSON object encoding and validation + PROTOBUF //Protobuf message encoding and decoding + AVRO //Serialize and deserialize via Avro + BOOLEAN // + INT8 //A 8-byte integer. + INT16 //A 16-byte integer. + INT32 //A 32-byte integer. + INT64 //A 64-byte integer. + FLOAT //A float number. + DOUBLE //A double number + _ // + _ // + _ // + KEY_VALUE //A Schema that contains Key Schema and Value Schema. + BYTES = -1 //A bytes array. + AUTO = -2 // + AUTO_CONSUME = -3 //Auto Consume Type. + AUTO_PUBLISH = -4 // Auto Publish Type. +) + +// Encapsulates data around the schema definition +type SchemaInfo struct { + Name string + Schema string + Type SchemaType +} + +func NewSchemaInfo(name string, schema string, schemaType SchemaType) *SchemaInfo { + si := &SchemaInfo{ + Name: name, + Schema: schema, + Type: schemaType, + } + return si +} + +type Schema interface { + Serialize(v interface{}) ([]byte, error) Review comment: nit: can we call it `encode` similar as what java does ---------------------------------------------------------------- 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