Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Added for loop to Encode function in order to support big-endian mach… #47

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,17 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
const uint16_t* buf,
size_t buflen) {
Local<String> val;

uint16_t dst[buflen];
if (IsBigEndian()) {
// Node's "ucs2" encoding expects LE character data inside a
// Buffer, so we need to reorder on BE platforms. See
// http://nodejs.org/api/buffer.html regarding Node's "ucs2"
// encoding specification
for (size_t i = 0; i < buflen; i++) {
dst[i] = (buf[i] << 8) | (buf[i] >> 8);
}
buf = dst;
}
if (buflen < EXTERN_APEX) {
val = String::NewFromTwoByte(isolate,
buf,
Expand Down