Skip to content

Feature request: manually control type mapping #52

@jacobq

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,
    };
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions