-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Behavior in Nativescript #169
Comments
Every time I have to touch anything related to NativeScript, nothing ever works the way it did a month or two ago. After trying for over an hour, I couldn't get anything to build this time. :( Can you show me the output of If we can't figure this out remotely, I'll probably need some help to create an environment that compiles. |
Of course
|
I want to mention that I am only using the decode function. It fails when decoding a cbor which I can parse problemless using other tools. |
It looks like enocde() is return a string, which i quite odd. I wonder what |
CONSOLE LOG: hex |
ok, so encode is working correctly, but that's a really odd default toString routine for your buffer class. Does Can you try |
Oh, I see. That is the default toString for the external Wait... are you sure |
Yes I am sure this is my code: import process from 'process'
global.process = process
import prereqs from 'cbor-rn-prereqs'
import cbor from 'cbor'
let object = {
x: 'val_x',
y: 'val_y'
}
let encoded = cbor.encode(object)
let decoded = cbor.decode(encoded)
console.log('hex', encoded.toString('hex'))
console.log('encoded[0]', encoded[0])
console.log('the object', object)
console.log('the encoded object', encoded)
console.log('the decoded object', decoded)
console.log('JSON string', JSON.stringify(decoded)) |
the diagnose log: CONSOLE LOG: diagnose {"¢axeval_xayeval_y": "¢axeval_xayeval_y", "¢axeval_xayeval_y": "¢axeval_xayeval_y"} |
At this point, I probably need to play with it myself in a debugger. Could you create a small github repo that has your code in a working environment for me, please? |
Of course: debug-repo |
OK, I've found the problem and will think about a work-around. in NS, |
To see the problem without 3rd party bits: const td = new TextDecoder('utf8', {fatal: true, ignoreBOM: true})
const buf = new Uint8Array([97, 98, 99, 100]);
const s = new Uint8Array(buf.buffer, buf.byteOffset + 1, 1);
const dec = td.decode(s)
console.log('utf8', buf, s, dec)
// utf8 97,98,99,100 98 abcd (expected "b" instead of "abcd") |
Here is the error: https://github.com/NativeScript/NativeScript/blob/17c85107ba84953630b0471c1f6f3d68f6d59f76/packages/core/text/text-common.ts#L70 That function as it currently exists would need a lot of work to merely be wrong. |
OK, here is an imperfect workaround. import TextDecoder from "@cto.af/textdecoder/polyfill";
global.TextDecoder = TextDecoder;
import {fixes} from "cbor-rn-prereqs";
import * as cbor from "cbor";
import * as utils from "cbor/lib/utils.js"
const td = new TextDecoder('utf8', {fatal: true, ignoreBOM: true})
utils.utf8 = buf => td.decode(buf) Unfortunately, the top level TextDecoder instance in I would also recommend filing a bug against NativeScript to have them fix their quite broken implementation. It doesn't decode non-ASCII UTF-8, and doesn't deal with slices. |
@hildjj Thanks for your Info. Before I opened this issue, I tried setting the variable as follow |
util.TextDecoder only exists in node 10, I think. Setting I'll see what I can do to fix this in |
Did we get this solved adequately? |
I think we came to an adequate solution. File more bugs if you continue to have problems with NativeScript being broken. |
I want to use this library in nativescript/angular. I got it bundled and working as follow:
The same behavior when using
cbor-web
I would appreciate any help.
The text was updated successfully, but these errors were encountered: