-
Notifications
You must be signed in to change notification settings - Fork 13
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
parity with cbor-x #69
Comments
Yeah, OK I'm not against this, it'd be a breaking change but I think this is a reasonable ask - but to be clear, supporting tags out of the box is out of scope for cborg, it's not intended to be fully-featured out of the box. I think you understand this from your current work though. |
We're using this library and prefer that Uint8Arrays continue to, by default, use major 2 and not tag 64. Most isomorphic JS is written using Uint8Arrays to express and manipulate arrays of bytes and it would be awkward to have to do something special here. I'd think that not requiring tags at all is the more common use case (i.e., "I just want to work with bytes and CBOR in JS, just like I do in other languages"). Additionally, ArrayBuffers in JS are not directly manipulated, I'd expect most of the time they are not Given implementation experience, it seems that it was perhaps a mistake for the CBOR spec to make a distinction between Uint8Array and byte strings, and if that is or starts to become the community consensus, implementations shouldn't further entrench the (potential) mistake. Perhaps what is needed here are some simple examples showing how to cause Uint8Arrays to be encoded using tag 64 for those that really need it. If something more than that is needed, perhaps a non-breaking feature (similar to the EDIT: I saw just now that this issue is going on 2 years old -- perhaps it should actually just be closed at this point. |
This is all pretty interesting and with the recent exposure of I'd also be open to entertaining additional code in here to support some or all of this. We have a taglib.js where the tag encoders and decoders could exist. Maybe an export that enables this wholesale for people that want it, while retaining the default behaviour as entirely untagged. To be clear, the default mode of cborg is always going to be without tags--encode and decode. You have to opt in to that, and currently the only way to deal with byte arrays is to squash them all down to a single type. I've chosen |
I'm trying out both
cbor-x
andcborg
...Here is the deal:
cbor-x
supports both typed arrays and arrayBuffercborg
don't support typed arrays and produces regular byte array instead (same as arrayBuffer)cbor-x
then it will produce similar response as when i'm usingcborg
(example at bottom)So here is an example where i use
cbor-x
and encoding Uint8Array's (it will produce a uint8 arrays)Where as when i using
cborg
it would produce another result:To achieve the same result using `cbor-x` then i can use regular ArrayBuffers
Now the actual issue/feature request:
I'm not exactly asking you to support TypedArrays or any other tags.
I'm asking you to rather stop using
Uint8Arrays
in your codebase and your code example and switch to usingArrayBuffer
instead ofUint8Arrays
.Why?
(credit to @Nemo157 for its online diagnostic tool
(also want to ping @kriszyp to ask if he has any saying to this)
(ps: i don't like how every package name their own function encode/decode it's conflicting with other hex/base64/TextDecoder etc - just name name according to what kind of thing they do: like `encodeToHex(input)`)
The text was updated successfully, but these errors were encountered: