From 37fdad53aae341ae53b7b3b3848ac1397baa5d9c Mon Sep 17 00:00:00 2001 From: Brad Moylan Date: Tue, 26 Nov 2024 10:33:44 -0800 Subject: [PATCH 1/2] fix: codecs.codecSNAPPY.Marshal uses configured contentCodec --- conjure-go-contract/codecs/snappy.go | 17 ++++++----------- conjure-go-contract/codecs/snappy_test.go | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/conjure-go-contract/codecs/snappy.go b/conjure-go-contract/codecs/snappy.go index c7ceb14f..81c6fab0 100644 --- a/conjure-go-contract/codecs/snappy.go +++ b/conjure-go-contract/codecs/snappy.go @@ -18,7 +18,6 @@ import ( "io" "github.com/golang/snappy" - werror "github.com/palantir/witchcraft-go-error" ) var _ Codec = codecSNAPPY{} @@ -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 } diff --git a/conjure-go-contract/codecs/snappy_test.go b/conjure-go-contract/codecs/snappy_test.go index 0d54ac92..0eb44f37 100644 --- a/conjure-go-contract/codecs/snappy_test.go +++ b/conjure-go-contract/codecs/snappy_test.go @@ -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 From 20760796c71627f8d4358be74e7c0f1132f88c12 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Tue, 26 Nov 2024 18:34:05 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-723.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-723.v2.yml diff --git a/changelog/@unreleased/pr-723.v2.yml b/changelog/@unreleased/pr-723.v2.yml new file mode 100644 index 00000000..84427b49 --- /dev/null +++ b/changelog/@unreleased/pr-723.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Codecs.codecSNAPPY.Marshal uses configured contentCodec + links: + - https://github.com/palantir/conjure-go-runtime/pull/723