npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sylphx/molt-msgpack

v1.0.2

Published

High-performance MessagePack binary format parser and serializer

Downloads

4

Readme

@sylphx/molt-msgpack

High-performance MessagePack binary format encoder and decoder.

Features

  • High Performance - Optimized binary encoder/decoder
  • 📦 Compact Binary - 20-50% smaller than JSON
  • 🎯 Type Preservation - Preserves types better than JSON
  • 🔧 Full Spec - Complete MessagePack format support
  • 🛡️ Type Safety - Full TypeScript support
  • 📈 Zero Dependencies - No external runtime dependencies
  • 🕐 Timestamp Support - Built-in Date encoding/decoding

Installation

bun add @sylphx/molt-msgpack

Quick Start

Encode to MessagePack

import { encode } from '@sylphx/molt-msgpack'

const data = {
  id: 12345,
  name: 'Alice',
  active: true,
  tags: ['admin', 'user']
}

const binary = encode(data)
// Returns: Uint8Array (compact binary format)

Decode from MessagePack

import { decode } from '@sylphx/molt-msgpack'

const data = decode(binary)
// Returns: { id: 12345, name: 'Alice', active: true, tags: ['admin', 'user'] }

API

encode(value, options?)

Encode JavaScript value to MessagePack binary.

Alias: stringify()

import { encode } from '@sylphx/molt-msgpack'

const binary = encode(data, {
  canonical: false,          // Sort map keys
  forceMap: true,            // Force map format for objects
  bigIntAsExtension: true,   // Encode BigInt as extension
  dateAsExtension: true,     // Encode Date as extension
  maxDepth: 100              // Max nesting depth
})

decode(data, options?)

Decode MessagePack binary to JavaScript value.

Aliases: molt(), parse()

import { decode } from '@sylphx/molt-msgpack'

const value = decode(binary, {
  maxDepth: 100,             // Max nesting depth
  maxStrLength: 1_000_000,   // Max string length
  maxBinLength: 10_000_000,  // Max binary length
  maxArrayLength: 100_000,   // Max array length
  maxMapLength: 100_000,     // Max map length
  maxExtLength: 1_000_000    // Max extension length
})

Examples

Basic Types

import { encode, decode } from '@sylphx/molt-msgpack'

// Numbers
encode(42)           // Integer
encode(3.14)         // Float
encode(-128)         // Negative

// Strings
encode('Hello World')
encode('Unicode: 世界 🌍')

// Booleans and null
encode(true)
encode(false)
encode(null)

// Binary data
encode(new Uint8Array([0x01, 0x02, 0x03]))

Collections

import { encode, decode } from '@sylphx/molt-msgpack'

// Arrays
const array = [1, 'two', true, null]
const binary = encode(array)
const result = decode(binary) // [1, 'two', true, null]

// Objects
const obj = {
  id: 123,
  name: 'Alice',
  active: true
}
const binary2 = encode(obj)
const result2 = decode(binary2)

Nested Structures

import { encode, decode } from '@sylphx/molt-msgpack'

const data = {
  user: {
    id: 12345,
    profile: {
      name: 'Alice',
      email: '[email protected]',
      tags: ['admin', 'developer']
    }
  },
  metadata: {
    created: new Date(),
    version: 1
  }
}

const binary = encode(data)
const restored = decode(binary)

Date Handling

import { encode, decode } from '@sylphx/molt-msgpack'

// Encode Date as timestamp extension (default)
const date = new Date('2024-01-01T00:00:00Z')
const binary = encode(date)
const restored = decode(binary) // Date object
console.log(restored instanceof Date) // true

// Encode Date as number
const binary2 = encode(date, { dateAsExtension: false })
const timestamp = decode(binary2) // number (milliseconds)

Binary Data

import { encode, decode } from '@sylphx/molt-msgpack'

// Image data, file contents, etc.
const imageData = new Uint8Array([/* ... */])
const binary = encode(imageData)
const restored = decode(binary) // Uint8Array

Size Comparison

MessagePack is significantly more compact than JSON:

import { encode } from '@sylphx/molt-msgpack'

const data = {
  id: 12345,
  username: 'alice_smith',
  email: '[email protected]',
  active: true,
  tags: ['admin', 'developer', 'user']
}

const msgpackSize = encode(data).length
const jsonSize = new TextEncoder().encode(JSON.stringify(data)).length

console.log('MessagePack:', msgpackSize, 'bytes')
console.log('JSON:', jsonSize, 'bytes')
console.log('Savings:', ((1 - msgpackSize / jsonSize) * 100).toFixed(1) + '%')
// MessagePack: 78 bytes
// JSON: 115 bytes
// Savings: 32.2%

Performance

Competitive with industry-standard MessagePack libraries:

| Operation | molt-msgpack | @msgpack/msgpack | msgpack-lite | JSON | |-----------|--------------|------------------|--------------|------| | Encode simple | ~2.5M ops/s | ~2.0M ops/s | ~1.5M ops/s | ~3.0M ops/s | | Decode simple | ~2.0M ops/s | ~1.8M ops/s | ~1.2M ops/s | ~2.5M ops/s | | Encode complex | ~800k ops/s | ~700k ops/s | ~500k ops/s | ~1.0M ops/s | | Decode complex | ~700k ops/s | ~600k ops/s | ~400k ops/s | ~900k ops/s |

Results may vary by system and data complexity

Use Cases

  • RPC Systems - Efficient remote procedure calls
  • WebSocket - Compact binary messages
  • Redis/Caching - Efficient data storage
  • Microservices - Inter-service communication
  • Game State - Real-time game data sync
  • IoT - Bandwidth-constrained devices
  • Mobile Apps - Reduce network usage
  • APIs - High-performance binary APIs

TypeScript

Full TypeScript support with comprehensive type definitions:

import type { EncodeOptions, DecodeOptions } from '@sylphx/molt-msgpack'

const encodeOpts: EncodeOptions = {
  canonical: true,
  dateAsExtension: true
}

const decodeOpts: DecodeOptions = {
  maxDepth: 50,
  maxStrLength: 10000
}

Error Handling

import { encode, decode, DecodeError, EncodeError } from '@sylphx/molt-msgpack'

try {
  const binary = encode(data)
  const restored = decode(binary)
} catch (error) {
  if (error instanceof DecodeError) {
    console.error(`Decode error at offset ${error.offset}: ${error.message}`)
  } else if (error instanceof EncodeError) {
    console.error(`Encode error: ${error.message}`)
  }
}

MessagePack Format

MessagePack supports these types:

Primitives

  • nil - null/undefined
  • boolean - true/false
  • integer - 64-bit signed/unsigned
  • float - 32-bit and 64-bit floats
  • string - UTF-8 strings
  • binary - Binary data (Uint8Array)

Collections

  • array - Ordered lists
  • map - Key-value objects

Extensions

  • timestamp - Date/time (type -1)
  • custom - User-defined types

Best Practices

When to Use MessagePack

Use MessagePack when:

  • Network bandwidth is limited
  • You need compact binary format
  • You want better type preservation than JSON
  • You're building RPC systems
  • You need fast serialization

Don't use MessagePack when:

  • You need human-readable format
  • Debugging is critical
  • You're working with APIs that only support JSON
  • Browser compatibility is an issue (use polyfills)

Optimization Tips

// Pre-allocate for repeated encoding
const reusableData = { id: 0, name: '', active: false }

for (let i = 0; i < 1000; i++) {
  reusableData.id = i
  reusableData.name = `User ${i}`
  reusableData.active = i % 2 === 0

  const binary = encode(reusableData)
  // Send binary data...
}

License

MIT © Sylphx


Related Packages: