22
33package events
44
5+ import (
6+ "encoding/json"
7+ )
8+
59type KafkaEvent struct {
610 EventSource string `json:"eventSource"`
711 EventSourceARN string `json:"eventSourceArn"`
@@ -10,12 +14,37 @@ type KafkaEvent struct {
1014}
1115
1216type KafkaRecord struct {
13- Topic string `json:"topic"`
14- Partition int64 `json:"partition"`
15- Offset int64 `json:"offset"`
16- Timestamp MilliSecondsEpochTime `json:"timestamp"`
17- TimestampType string `json:"timestampType"`
18- Key string `json:"key,omitempty"`
19- Value string `json:"value,omitempty"`
20- Headers []map [string ][]byte `json:"headers"`
17+ Topic string `json:"topic"`
18+ Partition int64 `json:"partition"`
19+ Offset int64 `json:"offset"`
20+ Timestamp MilliSecondsEpochTime `json:"timestamp"`
21+ TimestampType string `json:"timestampType"`
22+ Key string `json:"key,omitempty"`
23+ Value string `json:"value,omitempty"`
24+ Headers []map [string ]JSONNumberBytes `json:"headers"`
25+ }
26+
27+ // JSONNumberBytes represents array of bytes in Headers field.
28+ type JSONNumberBytes []byte
29+
30+ // MarshalJSON converts byte array into array of signed integers.
31+ func (b JSONNumberBytes ) MarshalJSON () ([]byte , error ) {
32+ signedNumbers := make ([]int8 , len (b ))
33+ for i , value := range b {
34+ signedNumbers [i ] = int8 (value )
35+ }
36+ return json .Marshal (signedNumbers )
37+ }
38+
39+ // UnmarshalJSON converts a given json with potential negative values into byte array.
40+ func (b * JSONNumberBytes ) UnmarshalJSON (data []byte ) error {
41+ var signedNumbers []int8
42+ if err := json .Unmarshal (data , & signedNumbers ); err != nil {
43+ return err
44+ }
45+ * b = make (JSONNumberBytes , len (signedNumbers ))
46+ for i , value := range signedNumbers {
47+ (* b )[i ] = byte (value )
48+ }
49+ return nil
2150}
0 commit comments