Skip to content

fix: honor element custom codecs for uint8 slices - #395

Closed
Solaris-star wants to merge 1 commit into
vmihailenco:v5from
Solaris-star:fix/391-byte-slice-custom-codec
Closed

fix: honor element custom codecs for uint8 slices#395
Solaris-star wants to merge 1 commit into
vmihailenco:v5from
Solaris-star:fix/391-byte-slice-custom-codec

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

Named uint8 element types that implement CustomEncoder/CustomDecoder were still packed as msgpack bin when used in a slice:

type Role uint8
func (r Role) EncodeMsgpack(enc *msgpack.Encoder) error { return enc.EncodeString("BACKEND") }

msgpack.Marshal(Role(1))      // string ✅
msgpack.Marshal([]Role{1, 2}) // bin blob ❌

Fix

In encoder/decoder type dispatch, only take the []byte shortcut when the element type has no custom codec (value or pointer receiver).

Test plan

  • go test .
  • TestByteKindSliceHonorsElementCustomCodec

Fixes #391

Slices whose element kind is uint8 were always encoded/decoded as binary
blobs, even when the element type implemented CustomEncoder/CustomDecoder
(or Marshaler/Unmarshaler). Scalar values of the same type correctly used
the custom codec.

Skip the []byte shortcut when the element type provides a custom codec so
[]Role encodes as an array of custom values and can decode from such an
array.

Fixes #391
@Solaris-star Solaris-star closed this by deleting the head repository Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[]byte-kind shortcut overrides element CustomEncoder/CustomDecoder for named uint8 slices

1 participant