i have two services (one in node, one in java) sharing objects, which are 
compressed and, therefore, binary. 

nodejs does a str.toString('binary') on the compressed buffer.  this 
changes the buffer as in the following example.

enc   [ -108 1 72 116 104 105 115 32 105 115 32 116 104 101 32 115 116 114 
105 110 103 32 70 19 0 70 18 0 -2 37 0 114 37 0 ]

enc.toString('binary')   [ -62 -108 1 72 116 104 105 115 32 105 115 32 116 
104 101 32 115 116 114 105 110 103 32 70 19 0 70 18 0 -61 -66 37 0 114 37 0 
]

unfortunately, it appears that negative bytes become two negative bytes in 
'binary' encoding, and i cannot find a java charset that can translate the 
latter into the former. 

i was told that 'binary' is simply 'latin1' encoding, but since these are 
binary buffers, it does not do as expected.  for example, if i take the 
second array from above in Java, and do 

new String(bytes, "latin1").getBytes("latin1"), 

it gives me back the same array.  [ -62 -108 1 72 116 104 105 115 32 105 
115 32 116 104 101 32 115 116 114 105 110 103 32 70 19 0 70 18 0 -61 -66 37 
0 114 37 0 ]

FWIW, i tracked the node buffer behavior down to v8 StringBytes::Write 
implementation.  
https://github.com/joyent/node/blob/23dfa71dd53617c3492f34787417ca60f03ea2ec/src/string_bytes.cc#L314

but unfortunately, that's where my C++ knowledge ends, and i am confused by 
the following line.  i imagine if i knew what exactly that did, i could 
just reimplement it in java.  str->WriteOneByte(reinterpret_cast<uint8_t*>(
buf), 0, buflen, flags);

thanks in advance!  hopefully, someone else has seen and/or done this 
already.  :/

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to