On Fri, Jul 5, 2013 at 12:08 AM, Stephan Beal <[email protected]> wrote:
> On Fri, Jul 5, 2013 at 12:03 AM, Arseniy Pavlenko <[email protected]> wrote:
>>
>> Any updates/workarounds for 8 bit binary strings?
>
>
> JS doesn't support them, so v8 doesn't either. You cannot legally use
> Strings for arbitrarily-encoded data. You _can_ wrap your own Buffer types
> which point to such memory, but it is illegal to convert their contents to a
> JS string.

There's a trick though:

  Handle<String> BinaryString(const uint8_t* data, size_t size) {
    uint16_t* out = new uint16_t[size];
    for (size_t n = 0; n < size; ++n) out[n] = data[n];
    Local<String> s = String::NewFromTwoByte(Isolate::GetCurrent(), out);
    delete[] out;
    return s;
  }

There's room for optimization of course, but the basic concept is the
same: convert the input to 16 bits and create a two-byte string from
that.

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" 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/groups/opt_out.


Reply via email to