@@ -12,9 +12,9 @@ import (
1212 stdtime "time"
1313
1414 // third-party libraries
15- cepb "cloudevents.io/genproto/v1"
1615 "github.com/cloudevents/sdk-go/v2/event"
1716 "github.com/cloudevents/sdk-go/v2/types"
17+ cepb "github.com/linkall-labs/vanus/proto/pkg/cloudevents"
1818 "google.golang.org/protobuf/types/known/anypb"
1919 "google.golang.org/protobuf/types/known/timestamppb"
2020)
@@ -35,14 +35,14 @@ var (
3535 zeroTime = stdtime.Time {}
3636)
3737
38- // convert an SDK event to a protobuf variant of the event that can be marshaled.
38+ // ToProto convert an SDK event to a protobuf variant of the event that can be marshaled.
3939func ToProto (e * event.Event ) (* cepb.CloudEvent , error ) {
4040 container := & cepb.CloudEvent {
4141 Id : e .ID (),
4242 Source : e .Source (),
4343 SpecVersion : e .SpecVersion (),
4444 Type : e .Type (),
45- Attributes : make (map [string ]* cepb.CloudEventAttributeValue ),
45+ Attributes : make (map [string ]* cepb.CloudEvent_CloudEventAttributeValue ),
4646 }
4747 if e .DataContentType () != "" {
4848 container .Attributes [datacontenttype ], _ = attributeFor (e .DataContentType ())
@@ -78,39 +78,39 @@ func ToProto(e *event.Event) (*cepb.CloudEvent, error) {
7878 return container , nil
7979}
8080
81- func attributeFor (v interface {}) (* cepb.CloudEventAttributeValue , error ) {
81+ func attributeFor (v interface {}) (* cepb.CloudEvent_CloudEventAttributeValue , error ) {
8282 vv , err := types .Validate (v )
8383 if err != nil {
8484 return nil , err
8585 }
86- attr := & cepb.CloudEventAttributeValue {}
86+ attr := & cepb.CloudEvent_CloudEventAttributeValue {}
8787 switch vt := vv .(type ) {
8888 case bool :
89- attr .Attr = & cepb.CloudEventAttributeValue_CeBoolean {
89+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeBoolean {
9090 CeBoolean : vt ,
9191 }
9292 case int32 :
93- attr .Attr = & cepb.CloudEventAttributeValue_CeInteger {
93+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeInteger {
9494 CeInteger : vt ,
9595 }
9696 case string :
97- attr .Attr = & cepb.CloudEventAttributeValue_CeString {
97+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeString {
9898 CeString : vt ,
9999 }
100100 case []byte :
101- attr .Attr = & cepb.CloudEventAttributeValue_CeBytes {
101+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeBytes {
102102 CeBytes : vt ,
103103 }
104104 case types.URI :
105- attr .Attr = & cepb.CloudEventAttributeValue_CeUri {
105+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeUri {
106106 CeUri : vt .String (),
107107 }
108108 case types.URIRef :
109- attr .Attr = & cepb.CloudEventAttributeValue_CeUriRef {
109+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeUriRef {
110110 CeUriRef : vt .String (),
111111 }
112112 case types.Timestamp :
113- attr .Attr = & cepb.CloudEventAttributeValue_CeTimestamp {
113+ attr .Attr = & cepb.CloudEvent_CloudEventAttributeValue_CeTimestamp {
114114 CeTimestamp : timestamppb .New (vt .Time ),
115115 }
116116 default :
@@ -119,38 +119,38 @@ func attributeFor(v interface{}) (*cepb.CloudEventAttributeValue, error) {
119119 return attr , nil
120120}
121121
122- func valueFrom (attr * cepb.CloudEventAttributeValue ) (interface {}, error ) {
122+ func valueFrom (attr * cepb.CloudEvent_CloudEventAttributeValue ) (interface {}, error ) {
123123 var v interface {}
124124 switch vt := attr .Attr .(type ) {
125- case * cepb.CloudEventAttributeValue_CeBoolean :
125+ case * cepb.CloudEvent_CloudEventAttributeValue_CeBoolean :
126126 v = vt .CeBoolean
127- case * cepb.CloudEventAttributeValue_CeInteger :
127+ case * cepb.CloudEvent_CloudEventAttributeValue_CeInteger :
128128 v = vt .CeInteger
129- case * cepb.CloudEventAttributeValue_CeString :
129+ case * cepb.CloudEvent_CloudEventAttributeValue_CeString :
130130 v = vt .CeString
131- case * cepb.CloudEventAttributeValue_CeBytes :
131+ case * cepb.CloudEvent_CloudEventAttributeValue_CeBytes :
132132 v = vt .CeBytes
133- case * cepb.CloudEventAttributeValue_CeUri :
133+ case * cepb.CloudEvent_CloudEventAttributeValue_CeUri :
134134 uri , err := url .Parse (vt .CeUri )
135135 if err != nil {
136136 return nil , fmt .Errorf ("failed to parse URI value %s: %s" , vt .CeUri , err .Error ())
137137 }
138138 v = uri
139- case * cepb.CloudEventAttributeValue_CeUriRef :
139+ case * cepb.CloudEvent_CloudEventAttributeValue_CeUriRef :
140140 uri , err := url .Parse (vt .CeUriRef )
141141 if err != nil {
142142 return nil , fmt .Errorf ("failed to parse URIRef value %s: %s" , vt .CeUriRef , err .Error ())
143143 }
144144 v = types.URIRef {URL : * uri }
145- case * cepb.CloudEventAttributeValue_CeTimestamp :
145+ case * cepb.CloudEvent_CloudEventAttributeValue_CeTimestamp :
146146 v = vt .CeTimestamp .AsTime ()
147147 default :
148148 return nil , fmt .Errorf ("unsupported attribute type: %T" , vt )
149149 }
150150 return types .Validate (v )
151151}
152152
153- // Convert from a protobuf variant into the generic, SDK event.
153+ // FromProto Convert from a protobuf variant into the generic, SDK event.
154154func FromProto (container * cepb.CloudEvent ) (* event.Event , error ) {
155155 e := event .New ()
156156 e .SetID (container .Id )
@@ -179,7 +179,7 @@ func FromProto(container *cepb.CloudEvent) (*event.Event, error) {
179179 if container .Attributes != nil {
180180 attr := container .Attributes [datacontenttype ]
181181 if attr != nil {
182- if stattr , ok := attr .Attr .(* cepb.CloudEventAttributeValue_CeString ); ok {
182+ if stattr , ok := attr .Attr .(* cepb.CloudEvent_CloudEventAttributeValue_CeString ); ok {
183183 contentType = stattr .CeString
184184 }
185185 }
0 commit comments