Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: manually control type mapping #52

Open
jacobq opened this issue Oct 23, 2019 · 0 comments
Open

Feature request: manually control type mapping #52

jacobq opened this issue Oct 23, 2019 · 0 comments

Comments

@jacobq
Copy link

jacobq commented Oct 23, 2019

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

No branches or pull requests

1 participant