Comments (4)
https://gist.github.com/baryon/6a0f97fc55a39b826d6e3d40166afa59
I noticed that bigint can be interpreted as int64. I have another proposal, what does everyone think? That is to use the hex of bigint, and use a byte array to represent bigint. Of course, we also need to consider negative numbers. I wrote code and test code to perform the conversion between bigint and buffer. Is there anyone who can review and integrate it into this codebase? I'm not quite clear on which format should be used in msgpack to represent it.
from msgpack-javascript.
https://no2chem.github.io/bigint-buffer/
a better lib than my code, it support Big/Little ending
from msgpack-javascript.
Add bigint
private encodeObject(object: unknown, depth: number) {
// try to encode objects with custom codec first of non-primitives
const ext = this.extensionCodec.tryToEncode(object, this.context);
if (ext != null) {
this.encodeExtension(ext);
} else if (Array.isArray(object)) {
this.encodeArray(object, depth);
} else if (ArrayBuffer.isView(object)) {
this.encodeBinary(object);
} else if (typeof object === "object") {
this.encodeMap(object as Record<string, unknown>, depth);
} else if(typeof object === "bigint"){
this.encodeBigInt64(object);
} else {
// symbol, function and other special object come here unless extensionCodec handles them.
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`);
}
}
from msgpack-javascript.
I am using useBigInt64 flag.
const encodedData = msgpack.encode(data, {
sortKeys: true,
useBigInt64: true,
});
from msgpack-javascript.
Related Issues (20)
- [bug] decode throws RangeError on empty Uint8Array HOT 2
- raw_ref type? HOT 2
- How can we convert the msgpack-encoded str back to the origin info HOT 2
- How to solve the problem of large integer accuracy loss
- Encoder Reuse Bug? HOT 2
- Cannot find module
- RangeError: Start offset undefined is outside the bounds of the buffer HOT 3
- Non reversible timestamp encoding HOT 1
- feature request: option to disable TEXT_ENCODING env check HOT 4
- There has a way to decode extension type from another language? HOT 3
- can i override the int64 decoder?
- Invalid integer string convertion from PHP serialized .msgpack HOT 1
- error on https://msgpack.org/
- Decoding of 32 bit floats is not precise HOT 3
- npm `latest` tag on `3.0.0-beta`
- add deno example with `import 'npm:@msgpack/msgpack'` HOT 1
- Encoder / Decoder classes dont work with `new ExtensionCodec()` for handling Set and Map in typescript
- Error in ExtensionCodec.ts?
- Update @msgpack/msgpack to 2.8.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgpack-javascript.