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

UTF read/write issues #13

Closed
elfwine opened this issue Oct 14, 2016 · 7 comments
Closed

UTF read/write issues #13

elfwine opened this issue Oct 14, 2016 · 7 comments

Comments

@elfwine
Copy link

elfwine commented Oct 14, 2016

I'm trying to use this amf javascript for an Air project that needed to migrate to HTML using Electron.
I'm having trouble with deserializing vectors type. I tried to debug with browser inspector, and when the type is 13, it throws an error exception.
Also, retrieving strings with Japanese characters returned garbish. I tried to escape the output string but still not getting the proper characters.
I have no direct access with the Server, thus I do not know how the flex service implemented.
By the way, using Charles proxy, I can see the response string properly (not garbaged).

Any help is much appreciated.
Thanks.

@emilkm
Copy link
Owner

emilkm commented Oct 14, 2016

Hi,

I have just started using the library in a project and will put more time into it. Vector is not supported, and I can look into the UTF decoding.

Can you send me a Charles session with the request/response in question.

@elfwine
Copy link
Author

elfwine commented Oct 14, 2016

Thank you for your quick response.

Is there any way to support the Vector?
By the way, I solved the UTF decoding.
Here's my code for readUTF function.

`
var utflen = length ? length : this.readUnsignedShort();
var end = this.pos + utflen,
chars = [],
charCount = 0,
maxCharCount = 65535,
charArrayCount = 1,
result = [],
i = 0,
charArrays, byteCount, charCode;
charArrays = [chars];
while (this.pos < end) {
    charCode = this.read();
    if (charCode > 127) {
        if (charCode > 239) {
            byteCount = 4;
            charCode = (charCode & 0x07);
        } else if (charCode > 223) {
            byteCount = 3;
            charCode = (charCode & 0x0F);
        } else {
            byteCount = 2;
            charCode = (charCode & 0x1F);
        }
        while (--byteCount) {
            charCode = ((charCode << 6) | (this.read() & 0x3F));
        }
    }

    chars.push(charCode);
    if (++charCount === maxCharCount) {
        charArrays.push(chars = []);
        charCount = 0;
        charArrayCount++;
    }
}

for (; i < charArrayCount; i++) {
    result.push(String.fromCharCode.apply(String, charArrays[i]));
}

return result.join('');

`

How can I send you the Charles session?
Thanks again.

@emilkm
Copy link
Owner

emilkm commented Oct 14, 2016

Send it to gmail (same username).

Sure, this is the senchatouch-amf solution.

I added Vector support to efxphp, so will see if I can come up with something.

@emilkm
Copy link
Owner

emilkm commented Oct 17, 2016

I have fixed the UTF read/write functionality and added some tests. Will work on more tests in the future.

Will look into reading Vectors.

@emilkm emilkm changed the title Anyway to deserialize a response Vector type UTF read/write issues Oct 17, 2016
@emilkm
Copy link
Owner

emilkm commented Oct 17, 2016

Opening a new ticket for Vector reading enhancement.

@elfwine
Copy link
Author

elfwine commented Oct 18, 2016

Thank you for your response. I forked your source and added the vector read support (so far it works with the data I received from the server). I also fix the ArrayCollection problem.
I will try your latest source and will incorperate the vector read support.

Again, thanks. ;)

@emilkm
Copy link
Owner

emilkm commented Oct 18, 2016

Cool, glad you are making it work for you.

I had an uncommitted fix for traits, which resulted in problems with second typed object in arrays (or ArrayCollection if you server is BLAZEDS and you have it). You got that one right. I have fixed the UTF write as well :)

I have done the read, support (not 100% sure what to do with uint at the moment). Also doing write. Should be done today or tomorrow. Will post more comments in #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants