in jones-ndb/impl/src/ndb/NdbTypeEncoders.cpp [1054:1097]
Local<String> getTextFromBuffer(const NdbDictionary::Column *col,
Handle<Object> bufferObj) {
const EncoderCharset * csinfo = getEncoderCharsetForColumn(col);
uint32_t len = node::Buffer::Length(bufferObj);
char * str = node::Buffer::Data(bufferObj);
Local<String> string;
// We won't call stringIsAscii() on a whole big TEXT buffer...
if(csinfo->isAscii) {
stats.read_strings_externalized++;
ExternalizedAsciiString *ext = new ExternalizedAsciiString(str, len);
ext->ref.Reset(isolate, bufferObj);
string = String::NewExternal(isolate, ext);
} else if (csinfo->isUtf16le) {
stats.read_strings_externalized++;
uint16_t * buf = (uint16_t *) str;
ExternalizedUnicodeString * ext = new ExternalizedUnicodeString(buf, len/2);
ext->ref.Reset(isolate, bufferObj);
string = String::NewExternal(isolate, ext);
} else {
stats.read_strings_created++;
if (csinfo->isUtf8) {
DEBUG_PRINT("New from UTF8 [%d] %s", len, str);
string = String::NewFromUtf8(isolate, str, String::kNormalString, len);
} else { // Recode
stats.read_strings_recoded++;
CharsetMap csmap;
int32_t lengths[2];
lengths[0] = len;
lengths[1] = getUtf8BufferSizeForColumn(len, csinfo);
DEBUG_PRINT("Recode [%d / %d]", lengths[0], lengths[1]);
char * recode_buffer = new char[lengths[1]];
csmap.recode(lengths,
col->getCharsetNumber(),
csmap.getUTF8CharsetNumber(),
str, recode_buffer);
DEBUG_PRINT("New from Recode [%d] %s", lengths[1], recode_buffer);
string = String::NewFromUtf8(isolate, recode_buffer, String::kNormalString, lengths[1]);
delete[] recode_buffer;
}
}
return string;
}