From b5b5b5eb980b40ff226766d14c13072546fb5134 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Thu, 19 Feb 2026 10:35:00 -0500 Subject: [PATCH 1/2] run go fix --- compress.go | 20 ++++++++++---------- decode.go | 6 +++--- inflate.go | 14 +++++++------- output.go | 8 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/compress.go b/compress.go index aa6f8c0..cab300d 100644 --- a/compress.go +++ b/compress.go @@ -115,8 +115,8 @@ type BinaryMapKey string // The map is of type `map[interface{}]int`, which the `interface{}` can // be an int64, a plain old string, or a binary []byte buffer wrapped in a // BinaryMapKey. -func (c *compressor) collectFrequencies() (ret map[interface{}]int, err error) { - ret = make(map[interface{}]int) +func (c *compressor) collectFrequencies() (ret map[any]int, err error) { + ret = make(map[any]int) hooks := msgpackDecoderHooks{ mapKeyHook: func(d decodeStack) (decodeStack, error) { d.hooks = msgpackDecoderHooks{ @@ -136,7 +136,7 @@ func (c *compressor) collectFrequencies() (ret map[interface{}]int, err error) { } return nil }, - fallthroughHook: func(i interface{}, _ string) error { + fallthroughHook: func(i any, _ string) error { return fmt.Errorf("bad map key (type %T)", i) }, } @@ -167,12 +167,12 @@ func (c *compressor) collectFrequencies() (ret map[interface{}]int, err error) { // or a BinaryMapKey (which is a wrapper around a binary buffer). The `Freq` field // is a count for how many times the `Key` shows up in the encoded msgpack object. type Frequency struct { - Key interface{} + Key any Freq int } // sortFrequencies converts a map of (keys -> counts) into an ordered vector of frequencies. -func (c *compressor) sortFrequencies(freqs map[interface{}]int) []Frequency { +func (c *compressor) sortFrequencies(freqs map[any]int) []Frequency { ret := make([]Frequency, len(freqs)) var i int for k, v := range freqs { @@ -187,8 +187,8 @@ func (c *compressor) sortFrequencies(freqs map[interface{}]int) []Frequency { // where the RHS values are ordered 0 to N. The idea is that the most frequent // keys get ths smallest values, which take of the least space when msgpack encoded. // This function returns the "keyMap" referred to later. -func (c *compressor) frequenciesToMap(freqs []Frequency) map[interface{}]uint { - ret := make(map[interface{}]uint, len(freqs)) +func (c *compressor) frequenciesToMap(freqs []Frequency) map[any]uint { + ret := make(map[any]uint, len(freqs)) for i, freq := range freqs { ret[freq.Key] = uint(i) //nolint:gosec // G115: range index is always non-negative } @@ -197,7 +197,7 @@ func (c *compressor) frequenciesToMap(freqs []Frequency) map[interface{}]uint { // output the data, the compressed keymap, and the version byte, which is the whole // encodeded compressed output. -func (c *compressor) output(freqsSorted []Frequency, keys map[interface{}]uint) (output []byte, err error) { +func (c *compressor) output(freqsSorted []Frequency, keys map[any]uint) (output []byte, err error) { version := Version(1) data, err := c.outputData(keys) if err != nil { @@ -213,7 +213,7 @@ func (c *compressor) output(freqsSorted []Frequency, keys map[interface{}]uint) // outputData, replacing all map Keys with their corresponding uints in the // keyMap. If we come across white-listed values, replace them with an // "external marker", followed by their position in the keyMap. -func (c *compressor) outputData(keys map[interface{}]uint) (output []byte, err error) { +func (c *compressor) outputData(keys map[any]uint) (output []byte, err error) { var data outputter hooks := data.decoderHooks() @@ -240,7 +240,7 @@ func (c *compressor) outputData(keys map[interface{}]uint) (output []byte, err e } return data.outputRawUint(val) }, - fallthroughHook: func(i interface{}, _ string) error { + fallthroughHook: func(i any, _ string) error { return fmt.Errorf("bad map key (type %T)", i) }, } diff --git a/decode.go b/decode.go index 7f30d5a..cb6c5c3 100644 --- a/decode.go +++ b/decode.go @@ -118,7 +118,7 @@ type msgpackDecoderHooks struct { float64Hook func(b []byte) error boolHook func(b bool) error extHook func(b []byte) error - fallthroughHook func(i interface{}, s string) error + fallthroughHook func(i any, s string) error } func readByte(r io.Reader) (byte, error) { @@ -360,7 +360,7 @@ func (m *msgpackDecoder) decodeArray(s decodeStack, n msgpackInt) (err error) { if numItems > bigArray { return ErrContainerTooBig } - for i := 0; i < numItems; i++ { + for range numItems { err = m.decodeArrayElement(s) if err != nil { return err @@ -420,7 +420,7 @@ func (m *msgpackDecoder) decodeMap(s decodeStack, n msgpackInt) (err error) { if numItems > bigArray { return ErrContainerTooBig } - for i := 0; i < numItems; i++ { + for range numItems { err = m.decodeMapPair(s) if err != nil { return err diff --git a/inflate.go b/inflate.go index bf0d88e..4d81e9c 100644 --- a/inflate.go +++ b/inflate.go @@ -83,7 +83,7 @@ func (c *inflator) openOuter() (version int, compressedData []byte, compressedKe idx++ return nil }, - fallthroughHook: func(_ interface{}, typ string) error { + fallthroughHook: func(_ any, typ string) error { return fmt.Errorf("unexpected value of type %q at top level", typ) }, } @@ -94,7 +94,7 @@ func (c *inflator) openOuter() (version int, compressedData []byte, compressedKe return version, compressedData, compressedKeymap, nil } -func (c *inflator) inflateKeymap(compressedKeymap []byte) (keymap map[uint]interface{}, err error) { +func (c *inflator) inflateKeymap(compressedKeymap []byte) (keymap map[uint]any, err error) { rawKeymap, err := flateInflate(compressedKeymap) if err != nil { return nil, err @@ -116,7 +116,7 @@ func (c *inflator) inflateKeymap(compressedKeymap []byte) (keymap map[uint]inter return nil } - putValue := func(i interface{}) error { + putValue := func(i any) error { if !isValue { return errors.New("got a call to putValue when we expected a key") } @@ -125,7 +125,7 @@ func (c *inflator) inflateKeymap(compressedKeymap []byte) (keymap map[uint]inter return nil } - fallthroughHook := func(_ interface{}, typ string) error { + fallthroughHook := func(_ any, typ string) error { return fmt.Errorf("unexpected value of type %q in keymap", typ) } @@ -138,7 +138,7 @@ func (c *inflator) inflateKeymap(compressedKeymap []byte) (keymap map[uint]inter if err != nil { return d, err } - keymap = make(map[uint]interface{}, i) + keymap = make(map[uint]any, i) return d, nil }, mapKeyHook: func(d decodeStack) (decodeStack, error) { @@ -216,7 +216,7 @@ func decodeBufToUint32(b []byte) (uint32, error) { } } -func (c *inflator) inflateData(keymap map[uint]interface{}, compressedData []byte) (ret []byte, err error) { +func (c *inflator) inflateData(keymap map[uint]any, compressedData []byte) (ret []byte, err error) { var data outputter hooks := data.decoderHooks() hooks.mapKeyHook = func(d decodeStack) (decodeStack, error) { @@ -232,7 +232,7 @@ func (c *inflator) inflateData(keymap map[uint]interface{}, compressedData []byt } return data.outputStringOrUintOrBinary(key) }, - fallthroughHook: func(_ interface{}, typ string) error { + fallthroughHook: func(_ any, typ string) error { return fmt.Errorf("Expected only int map keys; got a %q", typ) }, } diff --git a/output.go b/output.go index 93fe69b..78de296 100644 --- a/output.go +++ b/output.go @@ -34,11 +34,11 @@ func (o *outputter) outputByte(b byte) error { return err } -func (o *outputter) outputBinaryInt(i interface{}) error { +func (o *outputter) outputBinaryInt(i any) error { return binary.Write(&o.buf, binary.BigEndian, i) } -func (o *outputter) outputPrefixAndBinaryInt(b byte, i interface{}) error { +func (o *outputter) outputPrefixAndBinaryInt(b byte, i any) error { err := o.outputByte(b) if err != nil { return err @@ -208,7 +208,7 @@ func (o *outputter) decoderHooks() msgpackDecoderHooks { } } -func (o *outputter) outputStringOrUintOrBinary(i interface{}) error { +func (o *outputter) outputStringOrUintOrBinary(i any) error { switch t := i.(type) { case BinaryMapKey: return o.outputBinary(msgpackIntFromUint(uint(len(t))), []byte(t)) @@ -230,7 +230,7 @@ func (o *outputter) outputStringOrUintOrBinary(i interface{}) error { // we we substitute in a binary or string for something in our dictionary, // we output it as a big endian integer, prefixed by the "external" byte. func (o *outputter) outputExtUint(u uint) error { - var i interface{} + var i any var b byte switch { case u <= 0xff: From b3bb172811a3cc5a9bd718baad33cb5abaa2eab8 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Thu, 19 Feb 2026 10:43:10 -0500 Subject: [PATCH 2/2] kick ci