Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
},
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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()
Expand All @@ -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)
},
}
Expand Down
6 changes: 3 additions & 3 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions inflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
Expand All @@ -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
Expand All @@ -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")
}
Expand All @@ -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)
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
},
}
Expand Down
8 changes: 4 additions & 4 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand Down
Loading