MCPcopy Create free account
hub / github.com/defold/defold / AddString

Method AddString

engine/ddf/src/ddf/ddf_message.cpp:340–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338 }
339
340 void Message::AddString(LoadContext* load_context, const FieldDescriptor* field, const char* buffer, int buffer_len)
341 {
342 assert((Label) field->m_Label == LABEL_REPEATED);
343 assert(field->m_MessageDescriptor == 0);
344
345 // Always alloc
346 char* str_buf = load_context->AllocString(buffer_len + 1);
347
348 if (!m_DryRun)
349 {
350 RepeatedField* repeated_field = (RepeatedField*) GetBuffer(field->m_Offset);
351 uintptr_t array = (uintptr_t)repeated_field->m_Array;
352 if (load_context->GetOptions() & OPTION_OFFSET_POINTERS )
353 {
354 if (repeated_field->m_ArrayCount == 0) {
355 repeated_field->m_Array = (uintptr_t) load_context->GetOffset((void*)repeated_field->m_Array);
356 }
357 array = (uintptr_t)load_context->GetPointer(repeated_field->m_Array);
358 }
359
360 memcpy(str_buf, buffer, buffer_len);
361 str_buf[buffer_len] = '\0';
362
363 uintptr_t dest = array + repeated_field->m_ArrayCount * sizeof(const char*);
364 if (load_context->GetOptions() & OPTION_OFFSET_POINTERS)
365 {
366 const char* offset = (const char*)(uintptr_t) load_context->GetOffset(str_buf);
367 memcpy((void*) dest, &offset, sizeof(const char*));
368 }
369 else
370 {
371 memcpy((void*) dest, &str_buf, sizeof(const char*));
372 }
373 repeated_field->m_ArrayCount++;
374 }
375 }
376
377 void Message::SetBytes(LoadContext* load_context, const FieldDescriptor* field, const char* buffer, int buffer_len)
378 {

Callers

nothing calls this directly

Calls 6

AllocStringMethod · 0.80
GetOptionsMethod · 0.80
GetOffsetMethod · 0.80
GetPointerMethod · 0.80
assertFunction · 0.50
GetBufferFunction · 0.50

Tested by

no test coverage detected