Skip to content

feat: pack() type and family hints (#52) - #25690

Merged
godsflaw merged 2 commits into
msgpack:masterfrom
enochgroot:feat/pack-type-hints
Sep 19, 2026
Merged

godsflaw merged 2 commits into
msgpack:masterfrom
enochgroot:feat/pack-type-hints

Conversation

@enochgroot

@enochgroot enochgroot commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds pack(value, { type, family, interpret }) so callers can force
MessagePack wire types (uint8/float32/bin/str, etc.) without changing the
default one-arg / multi-arg packing rules.

Closes #52

Options-object detection: the last argument is options only when it is a
plain object that own-enumerates at least one of type, family,
interpret and nothing else that is not those three keys. Host objects,
Proxies, extra keys, and empty objects stay packed values. pack(1, 2) is
still an array.

Coverage (reviewer round 1)

  • test/pack-hints.test.js: 48 tests, including host-object options
    rejection and null/undefined type/family fall-through.
  • Unreachable hint arms (empty info[1], kTypeNone / kFamilyNone
    defaults, hinted kMaxPackDepth) marked GCOVR_EXCL_*, not deleted.
  • ThrowCannotPackAs is [[noreturn]] so gcovr throw edges match.
  • npm test: 185 pass / 0 fail.
  • npm run coverage:native: 95.2% lines (902/947), 95.4% branches
    (836/876), 100% functions. Gate is 95%.

Test plan

  • npm test
  • npm run coverage:native
  • CI on this PR

- pack(value, { type, family, interpret }) forces MessagePack wire types
- two-arg last-object detection; pack(1, 2) still packs an array
- Host objects, null type, and related pack-options cases
- [[noreturn]] on ThrowCannotPackAs so gcovr throw edges match
- GCOVR_EXCL only on unreachable hint defaults and empty info[1]
- Native coverage 95.2% lines / 95.4% branches
@enochgroot enochgroot changed the title feat: add pack type and family hints feat: pack() type and family hints (#52) Sep 19, 2026
@godsflaw
godsflaw merged commit f578245 into msgpack:master Sep 19, 2026
10 checks passed
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.

Feature request: manually control type mapping

2 participants