Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Stop decoding json from pubsub #554

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions pkg/pubsub/adapter/converters/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package converters

import (
"context"
"encoding/json"
"time"

cloudevents "github.com/cloudevents/sdk-go"
Expand Down Expand Up @@ -60,16 +59,7 @@ func convertPubSub(ctx context.Context, msg *cepubsub.Message, sendMode ModeType
ID: event.ID(),
Attributes: msg.Attributes,
PublishTime: event.Time(),
}

var raw json.RawMessage
if err := event.DataAs(&raw); err != nil {
logger.Desugar().Debug("Failed to get data as raw json, using as is.", zap.Error(err))
// Use data as a byte slice.
msg.Data = event.Data
} else {
// Use data as a raw message.
msg.Data = raw
Data: event.Data,
}

if err := event.SetData(&PushMessage{
Expand Down
4 changes: 2 additions & 2 deletions pkg/pubsub/adapter/converters/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestConvertCloudPubSub(t *testing.T) {
return pubSubPushCloudEvent(map[string]string{
"attribute1": "value1",
"Invalid-Attrib#$^": "value2",
}, "\"test data\"")
}, "\"InRlc3QgZGF0YSI=\"")
},
}, {
name: "Push mode with no attributes",
Expand All @@ -126,7 +126,7 @@ func TestConvertCloudPubSub(t *testing.T) {
},
sendMode: Push,
wantEventFn: func() *cloudevents.Event {
return pubSubPushCloudEvent(nil, "\"test data\"")
return pubSubPushCloudEvent(nil, "\"InRlc3QgZGF0YSI=\"")
},
}}

Expand Down