From 87e7b25daacefb66ef4f14ce4b8ec303623b40bc Mon Sep 17 00:00:00 2001 From: Baptiste Canton Date: Mon, 14 Apr 2025 19:13:39 +0200 Subject: [PATCH 1/2] Add fpc compression and decompression mutators --- go.mod | 1 + go.sum | 2 ++ pkg/mutators/single/fpc.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 pkg/mutators/single/fpc.go diff --git a/go.mod b/go.mod index 966b0615..9c51325c 100644 --- a/go.mod +++ b/go.mod @@ -131,6 +131,7 @@ require ( github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rs/xid v1.6.0 // indirect + github.com/spenczar/fpc v1.0.0 // indirect github.com/xanzy/go-gitlab v0.115.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect diff --git a/go.sum b/go.sum index 2e8f9680..94ac2bd4 100644 --- a/go.sum +++ b/go.sum @@ -323,6 +323,8 @@ github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/gunit v1.4.2 h1:tyWYZffdPhQPfK5VsMQXfauwnJkqg7Tv5DLuQVYxq3Q= github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= +github.com/spenczar/fpc v1.0.0 h1:H0NtafmaWbJhSghiU5oilPzh/5kdbtQ8nTBt9I4dLMA= +github.com/spenczar/fpc v1.0.0/go.mod h1:14BNj23NWSW7Hf2jk29+fpk9ufQKUGMCefCj9vgjwBU= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/pkg/mutators/single/fpc.go b/pkg/mutators/single/fpc.go new file mode 100644 index 00000000..678e081c --- /dev/null +++ b/pkg/mutators/single/fpc.go @@ -0,0 +1,32 @@ +package mutators + +import ( + "io" + + "github.com/spenczar/fpc" +) + +func init() { + singleRegister("fpc", wfpc, withDescription("compress 64bit floats"), + withCategory("compress"), + ) + singleRegister("unfpc", rfpc, withDescription("decompress 64bit floats"), + withCategory("decompress"), + ) +} + +func wfpc(out io.WriteCloser, in io.ReadCloser, _ any) (int64, error) { + f := fpc.NewWriter(out) + + // the buffer must obviously be a multiple of 8 + n, err := io.CopyBuffer(f, in, make([]byte, 8*1024)) + if err != nil { + return n, err + } + err = f.Close() + return n, err +} + +func rfpc(out io.WriteCloser, in io.ReadCloser, _ any) (int64, error) { + return io.Copy(out, fpc.NewReader(in)) +} From 4a6fdea714d9ff50a40f38ed1934d7db415831ca Mon Sep 17 00:00:00 2001 From: Baptiste Canton Date: Mon, 14 Apr 2025 21:29:41 +0200 Subject: [PATCH 2/2] change category --- pkg/mutators/single/fpc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/mutators/single/fpc.go b/pkg/mutators/single/fpc.go index 678e081c..0a1d7b31 100644 --- a/pkg/mutators/single/fpc.go +++ b/pkg/mutators/single/fpc.go @@ -8,10 +8,10 @@ import ( func init() { singleRegister("fpc", wfpc, withDescription("compress 64bit floats"), - withCategory("compress"), + withCategory("specific compress"), ) singleRegister("unfpc", rfpc, withDescription("decompress 64bit floats"), - withCategory("decompress"), + withCategory("specific decompress"), ) }