From 963ec0ed7ddd5fc8861b55ec82155b83f83a9fc7 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Tue, 15 Feb 2022 18:04:23 +0800 Subject: [PATCH 1/2] Make SdkToProto and ProtoToSDK public Signed-off-by: Kevin Su --- binding/format/protobuf/v2/protobuf.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binding/format/protobuf/v2/protobuf.go b/binding/format/protobuf/v2/protobuf.go index c70249e45..84bbef483 100644 --- a/binding/format/protobuf/v2/protobuf.go +++ b/binding/format/protobuf/v2/protobuf.go @@ -76,7 +76,7 @@ func (protobufFmt) Unmarshal(b []byte, e *event.Event) error { } // convert an SDK event to a protobuf variant of the event that can be marshaled. -func sdkToProto(e *event.Event) (*pb.CloudEvent, error) { +func SdkToProto(e *event.Event) (*pb.CloudEvent, error) { container := &pb.CloudEvent{ Id: e.ID(), Source: e.Source(), @@ -191,7 +191,7 @@ func valueFrom(attr *pb.CloudEventAttributeValue) (interface{}, error) { } // Convert from a protobuf variant into the generic, SDK event. -func protoToSDK(container *pb.CloudEvent) (*event.Event, error) { +func ProtoToSDK(container *pb.CloudEvent) (*event.Event, error) { e := event.New() e.SetID(container.Id) e.SetSource(container.Source) From 99a930dfd95ccda96a8fb7b731b9e299f847d4ed Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Wed, 16 Feb 2022 01:23:37 +0800 Subject: [PATCH 2/2] Fixed tests Signed-off-by: Kevin Su --- binding/format/protobuf/v2/protobuf.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/binding/format/protobuf/v2/protobuf.go b/binding/format/protobuf/v2/protobuf.go index 84bbef483..01b93d47b 100644 --- a/binding/format/protobuf/v2/protobuf.go +++ b/binding/format/protobuf/v2/protobuf.go @@ -56,7 +56,7 @@ func (protobufFmt) MediaType() string { } func (protobufFmt) Marshal(e *event.Event) ([]byte, error) { - pbe, err := sdkToProto(e) + pbe, err := ToProto(e) if err != nil { return nil, err } @@ -67,7 +67,7 @@ func (protobufFmt) Unmarshal(b []byte, e *event.Event) error { if err := proto.Unmarshal(b, pbe); err != nil { return err } - e2, err := protoToSDK(pbe) + e2, err := FromProto(pbe) if err != nil { return err } @@ -76,7 +76,7 @@ func (protobufFmt) Unmarshal(b []byte, e *event.Event) error { } // convert an SDK event to a protobuf variant of the event that can be marshaled. -func SdkToProto(e *event.Event) (*pb.CloudEvent, error) { +func ToProto(e *event.Event) (*pb.CloudEvent, error) { container := &pb.CloudEvent{ Id: e.ID(), Source: e.Source(), @@ -191,7 +191,7 @@ func valueFrom(attr *pb.CloudEventAttributeValue) (interface{}, error) { } // Convert from a protobuf variant into the generic, SDK event. -func ProtoToSDK(container *pb.CloudEvent) (*event.Event, error) { +func FromProto(container *pb.CloudEvent) (*event.Event, error) { e := event.New() e.SetID(container.Id) e.SetSource(container.Source)