Git Product home page Git Product logo

msgpack.js's People

Contributors

aarnott avatar tisztamo avatar ygoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

msgpack.js's Issues

has a bug

let obj = serializeMsgPack([100, 100, "ok", serializeMsgPack([[100, 1000.01]])]
let obj2 = deserializeMsgPack(obj)
console.log(deserializeMsgPack(obj2[3])[0][1]);// print:5.262076770253218e+228

No "default" case in 'append'

The encoder's append function does not have a default handler. This can result in broken or incomplete objects (e.g. when an encoded object contains a function).

Also, would you consider teaching the encoder to call an object's "toJSON" method (if it has one), and encode its result instead of the original object?

Options undocumented

It seems there are options for both serialize() and unserialize(), but I do not know what they do. I have read the following comment but I don't know what it means.

Indicates whether multiple values in data are concatenated to multiple MessagePack arrays.

Perhaps an example would help?

Wrong bin format handling

What is happening: during encoding binary data is handled like a plain object and during decoding it wrongly returns the array which represents the length of the binary data.

What was expected: typed arrays being encoded using the bin format family and this format family being decoded back to typed arrays.

Examples:

serializeMsgPack(new Uint8Array([1, 2, 3]))
// Expected: new Uint8Array([0xC4, 0x03, 0x01, 0x02, 0x03])
// Got: new Uint8Array([0x83, 0xA1, 0x30, 0x01, 0xA1, 0x31, 0x02, 0xA1, 0x32, 0x03])

deserializeMsgPack(new Uint8Array([0xC4, 0x03, 0x01, 0x02, 0x03]))
// Expected: new Uint8Array([1, 2, 3])
// Got: new Uint8Array([3])

deserializeMsgPack method throws exception while using with ASP.NET Core

I am using msgpack.js with Message Pack implementation in C# for ASP.NET Core. But I am getting an error like this.

image

Here is the code.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().AddMvcOptions(option =>
    {
        option.OutputFormatters.Clear();
        option.OutputFormatters.Add(new MessagePackOutputFormatter(StandardResolver.Instance));
        option.InputFormatters.Clear();
        option.InputFormatters.Add(new MessagePackInputFormatter(StandardResolver.Instance));
    }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

And here is the client code.

<script src="jquery-3.3.1.min.js"></script>
<script src="msgpack.js"></script>
<script>
    $(function () {
        $.get("/api/person", function (data) {
            console.log(deserializeMsgPack(data));
        });
    });
</script>

I am using it in a Web API project, and returning default values controller.

Does it work with System.Decimal?

Hello
First of all great work. Im using .Net Core as backend, and im interested knowing if is possible to have decimal values in C# class or is mandatory to use double.
Thanks in advance

Encoding in python and decoding in javascript

Is it possible to decode an encoded message from python in javascript using this library? And if yes, how?

The encoded message I created in python looks as follow: b'\x83\xa2id\x01\xa4test\x17\xa3hey*'
When I retrieve it in my javascript code and try to deserialize it I get an error message about invalid type, undefined. The encoded message I created in the python script seems to be a Blob{} type when it arrives in the javascript code. I have tried to convert the Blob type to a string by using a fileReader, but with small success.

Any ideas regarding this?

Cheers

Handle NaN and Infinity, set them to Null, like JSON does

    function append(data) {
      data == null || data === NaN || data === Infinity ? appendByte(0xc0) :
      (
        data.constructor === String ? appendString :
        data.constructor === Number ? appendNumber :
        data.constructor === Boolean ? appendBoolean :
        Array.isArray(data) ? appendArray :
        data instanceof Date ? appendDate :
        appendObject
      )(data)
    }

Skip serializing properties with `undefined` values

Similar to JSON.stringify behavior, properties whose value is undefined should not be serialized as null in msgpack. Undefined means: undefined, which is decidedly different from a defined value of null.

Observe the following node interactive:

> msgpack.deserialize(msgpack.serialize({a:'a',b:undefined}))
{ a: 'a', b: null }
> JSON.stringify({a:'a',b:undefined})
'{"a":"a"}'

It's convenient to use undefined as a value to suppress its encoding, but this library ignores that technique.

If you can't change the default behavior, what if we added an option under which undefined properties would be skipped?

I am willing to send a PR.

Proposal: converting Integer with DataView

First of all, thank you for your work.

Currently only float is being converted using DataView, why not use DataView to convert Integer uniformly?
If we all use DataView, the code will be shorter and easier to read, also less prone to errors.

Recently I needed to use the little-endian version of msgpack.
I modified a python library and all I had to do to modify the endianness was to change the symbol ">" to "<".
To modify the javascript library, I only had to change the DataView functions parameter from false to true, but since you don't use DataView, it's a bit confusing: https://github.com/dukelec/msgpackel

Modification for the python library:

Screenshot_2021-10-18_18-03-22

Modification for the javascript library:

Screenshot_2021-10-18_18-02-19

Screenshot_2021-10-18_18-01-55

Screenshot_2021-10-18_18-01-15

The example of javascript client and server

Can you provide an example of msgpack.js + MessagePack-CSharp? I tried to use msgpack.js to send data to the server via WebSocket. Deserialize bytes using MessagePack-CSharp, but not working. Thank you.

Callback for ext

At first, thanks for your library. It is small without Node.js dependencies, what is the unicorn today.
I have suggestion for the small enhancement: Please add a callback for ext format decoding to the deserialize function

Copy to TypeScript

A compilation exception occurred while trying to copy to a TypeScript file.
The number of parameters of some functions does not correspond.

Detect Web Workers environment

When the library is used in a web worker there is an issue with undefined window so i suggest adding Web Workers detection such as :

// Environment detection
if (typeof module === "object" && module && typeof module.exports === "object") {
	// Node.js
	module.exports = msgpack;
}
else if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
	// Global object
	self[self.msgpackJsName || "msgpack"] = msgpack;
} else {
	// Global object
	window[window.msgpackJsName || "msgpack"] = msgpack;
}

Wrong float deserialization from typed arrays with non-zero byteOffset

When deserializing from an Uint8Array which has a non-zero byteOffset, float values go wrong.

(I am sending an MsgPack object together with some type information over websocket, so only the second part of the websocket frame contains the data to deserialize)

MWE:

const buf = new ArrayBuffer(10);
const arr0 = new Uint8Array(buf);
const arr1 = new Uint8Array(buf, 1);
for (let i = 0; i < arr0.length; i++) {
	arr0[i] = 255;
}
for (let i = 0; i < arr1.length; i++) {
	arr1[i] = 0;
}
arr1[0] = 0xcb;

arr1 should then deserialize to 0, but it does not. (I have found the cause and will issue a pull request soon)

Date deserialisation doesn't cope with pre-epoch dates

If you serialise a date which is pre-epoch, e.g. new Date(-1) is 1969-12-13 23:59:59.999, and then attempt to deserialize it, the deserialsiation fails return the same date.

image

Hex representation:

image

From a quick play around in the debugger this appears to be because the sign bit and 2's compliment is not respected for negative numbers (which are required for pre-epoch times). My guess is that this is due to the bit shifting required to parse the dates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.