From 0ed0c5568d490ea64a945cf6fd0b36ee44e5f578 Mon Sep 17 00:00:00 2001 From: Brad Moylan Date: Tue, 26 Nov 2024 10:37:58 -0800 Subject: [PATCH] fix: codecs.codecSNAPPY.Marshal uses configured contentCodec (#723) --- changelog/@unreleased/pr-723.v2.yml | 5 +++++ conjure-go-contract/codecs/snappy.go | 17 ++++++----------- conjure-go-contract/codecs/snappy_test.go | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) 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 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