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

Consider string buffer encoding. #8

Closed
sc0Vu opened this issue Mar 8, 2018 · 1 comment
Closed

Consider string buffer encoding. #8

sc0Vu opened this issue Mar 8, 2018 · 1 comment
Assignees
Projects

Comments

@sc0Vu
Copy link
Member

sc0Vu commented Mar 8, 2018

I think string in PHP is utf8 bytes. Consider the following code:

$buffer = new Buffer('abcàê߀abc', 'ascii');
echo $buffer->length(); // 15

if you dump you'll see:

  array(15) {
    [0]=>
    int(97)
    [1]=>
    int(98)
    [2]=>
    int(99)
    [3]=>
    int(195)
    [4]=>
    int(160)
    [5]=>
    int(195)
    [6]=>
    int(170)
    [7]=>
    int(195)
    [8]=>
    int(159)
    [9]=>
    int(226)
    [10]=>
    int(130)
    [11]=>
    int(172)
    [12]=>
    int(97)
    [13]=>
    int(98)
    [14]=>
    int(99)
  }

It should be 10 and looks like:

  array(10) {
    [0]=>
    int(97)
    [1]=>
    int(98)
    [2]=>
    int(99)
    [3]=>
    int(224)
    [4]=>
    int(234)
    [5]=>
    int(223)
    [6]=>
    int(172)
    [7]=>
    int(97)
    [8]=>
    int(98)
    [9]=>
    int(99)
  }

In nodejs:

  • Ascii:
new Buffer('abcàê߀abc', 'ascii');
<Buffer 61 62 63 e0 ea df ac 61 62 63> // [97, 98, 99, 224, 234, 223, 172, 97, 98, 99]
  • Utf8 (like the array above)
new Buffer('abcàê߀abc', 'utf8');
<Buffer 61 62 63 c3 a0 c3 aa c3 9f e2 82 ac 61 62 63> // [97, 98, 99, 195, 160, 195, 170, 195, 159, 226, 130, 172, 97, 98, 99]

How to fix it?

@sc0Vu sc0Vu self-assigned this Mar 8, 2018
@sc0Vu
Copy link
Member Author

sc0Vu commented Nov 7, 2019

IMHO buffer usage looks bad (.dirty), so I remove the buffer in the new version of rlp.

@sc0Vu sc0Vu closed this as completed Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v0.3
  
Awaiting triage
Development

No branches or pull requests

1 participant