1 package serializer 2 3 import ( 4 "github.com/gogo/protobuf/jsonpb" 5 "google.golang.org/protobuf/runtime/protoiface" 6 ) 7 8 // ProtobufToJSON converts protocol buffer message to JSON string 9 func ProtobufToJSON(message protoiface.MessageV1) (string, error) { 10 marshaler := jsonpb.Marshaler{ 11 EnumsAsInts: false, 12 EmitDefaults: true, 13 Indent: " ", 14 OrigName: true, 15 } 16 17 return marshaler.MarshalToString(message) 18 } 19