Skip to content

Commit

Permalink
fix: codecs.codecSNAPPY.Marshal uses configured contentCodec (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoylan authored Nov 26, 2024
1 parent 5d287c2 commit 0ed0c55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-723.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Codecs.codecSNAPPY.Marshal uses configured contentCodec
links:
- https://github.com/palantir/conjure-go-runtime/pull/723
17 changes: 6 additions & 11 deletions conjure-go-contract/codecs/snappy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"io"

"github.com/golang/snappy"
werror "github.com/palantir/witchcraft-go-error"
)

var _ Codec = codecSNAPPY{}
Expand Down Expand Up @@ -68,20 +67,16 @@ func (c codecSNAPPY) Encode(w io.Writer, v interface{}) error {
if err != nil {
return err
}

encoded, err := c.Marshal(data)
if err != nil {
return err
}
encoded := snappy.Encode(nil, data)
_, err = w.Write(encoded)
return err
}

func (c codecSNAPPY) Marshal(v interface{}) ([]byte, error) {
data, ok := v.([]byte)
if !ok {
return nil, werror.Error("failed to compress data from type which is not of type []byte")
data, err := c.contentCodec.Marshal(v)
if err != nil {
return nil, err
}
d := snappy.Encode(nil, data)
return d, nil
encoded := snappy.Encode(nil, data)
return encoded, nil
}
2 changes: 1 addition & 1 deletion conjure-go-contract/codecs/snappy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestSnappyCompression(t *testing.T) {
require.Equal(t, input, actual)
})
t.Run("Marshal/Unmarshal", func(t *testing.T) {
encoded, err := snappyEncoder.Marshal([]byte(input))
encoded, err := snappyEncoder.Marshal(input)
require.NoError(t, err)

// assert encoded message compressed
Expand Down

0 comments on commit 0ed0c55

Please sign in to comment.