Skip to content

Feature request: manually control type mapping #52

Description

@jacobq

I would like to use this library in a node.js application that communicates with a msgpack API. Unfortunately, I need to be able to send messages that use specific data types for specific fields (e.g. Array<fixint>, bin8, ...) rather than have the library automatically choose/guess as described in
https://github.com/msgpack/msgpack-node#type-mapping.

How hard would it be to incorporate this? For example, I'd like to be able to do this:

// Binary data
const buff = getBufferFromSomewhere();
msgpack.pack(buff, { family: 'bin' }); // ==> chooses `bin8`, `bin16` or `bin32` depending on buffer size

// Force particular numeric type
msgpack.pack(123, { type: 'fixint' });

// Specify custom type mapping when packing arrays
const a = [{ data: Math.PI, type: 'float64' }, { data: 3.14, type: 'float32' }];
msgpack.pack(a, {
  interpret(item) {
    return {
      data: item.data,
      type: item.type,
      // alternatively:
      family: item.family,
    };
  }
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions