MCPcopy Create free account
hub / github.com/apache/fory / serializeString

Function serializeString

javascript/packages/hps/src/fastcall.cc:91–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91static void serializeString(const v8::FunctionCallbackInfo<v8::Value> &args) {
92 auto isolate = args.GetIsolate();
93 auto context = isolate->GetCurrentContext();
94 v8::Local<v8::Uint8Array> dst = args[0].As<v8::Uint8Array>();
95 v8::Local<v8::String> str = args[1].As<v8::String>();
96 uint32_t offset = args[2].As<v8::Number>()->Uint32Value(context).ToChecked();
97
98 bool is_one_byte = str->IsOneByte();
99 uint8_t *dst_data =
100 reinterpret_cast<uint8_t *>(dst->Buffer()->GetBackingStore()->Data());
101
102 if (is_one_byte && str->IsExternalOneByte()) {
103 offset += writeVarUint32(dst_data, offset,
104 (str->Length() << 2) | Encoding::LATIN1); // length
105 const auto src = str->GetExternalOneByteStringResource()->data();
106 memcpy(dst_data + offset, src, str->Length());
107 offset += str->Length();
108 } else {
109 v8::HandleScope scope(isolate);
110 int flags = String::HINT_MANY_WRITES_EXPECTED |
111 String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8;
112 if (is_one_byte) {
113 offset +=
114 writeVarUint32(dst_data, offset,
115 (str->Length() << 2) | Encoding::LATIN1); // length
116 offset += str->WriteOneByte(isolate, dst_data + offset, 0, str->Length(),
117 flags);
118 } else {
119 offset += writeVarUint32(dst_data, offset,
120 ((str->Length() * 2) << 2) |
121 Encoding::UTF16); // length
122 offset += writeUCS2(isolate, dst_data + offset, str, flags);
123 }
124 }
125
126 args.GetReturnValue().Set(offset);
127}
128
129static uint32_t serializeStringFast(Local<Value> receiver,
130 const v8::FastApiTypedArray<uint8_t> &dst,

Callers 2

stringWithHeaderFastMethod · 0.85
hps.test.tsFile · 0.85

Calls 5

writeVarUint32Function · 0.85
writeUCS2Function · 0.85
BufferMethod · 0.45
dataMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected