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

Function SetMetaData

engine/dlib/src/dlib/buffer.cpp:631–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

629 }
630
631 Result SetMetaData(HBuffer hbuffer, dmhash_t name_hash, const void* data, uint32_t count, ValueType type)
632 {
633 Buffer* buffer = g_BufferContext->Get(hbuffer);
634 if (!buffer) {
635 return RESULT_BUFFER_INVALID;
636 }
637 if (count == 0) {
638 return RESULT_METADATA_INVALID;
639 }
640
641 Buffer::MetaData* item = FindMetaDataItem(buffer, name_hash);
642 uint32_t values_block_size = GetSizeForValueType(type)*count; // do this once
643 if (item) {
644 // make sure the type and value count is right
645 if (item->m_ValueCount != count || item->m_ValueType != type) {
646 return RESULT_METADATA_INVALID;
647 }
648 memcpy(item->m_Data, data, values_block_size);
649 return RESULT_OK;
650 } else {
651 dmArray<Buffer::MetaData*>& metadata_items = buffer->m_MetaDataArray;
652 if (metadata_items.Full()) {
653 metadata_items.OffsetCapacity(2);
654 }
655 item = (Buffer::MetaData*) malloc(sizeof(Buffer::MetaData));
656 item->m_Name = name_hash;
657 item->m_ValueCount = count;
658 item->m_ValueType = type;
659 item->m_Data = malloc(values_block_size);
660 memcpy(item->m_Data, data, values_block_size);
661 metadata_items.Push(item);
662 }
663
664 return RESULT_OK;
665 }
666
667}

Callers 4

CloneFunction · 0.85
TEST_FFunction · 0.85
verifyMetadataByTypeFunction · 0.85
SetMetadataFunction · 0.85

Calls 7

FindMetaDataItemFunction · 0.85
GetSizeForValueTypeFunction · 0.85
mallocFunction · 0.85
GetMethod · 0.45
FullMethod · 0.45
OffsetCapacityMethod · 0.45
PushMethod · 0.45

Tested by 2

TEST_FFunction · 0.68
verifyMetadataByTypeFunction · 0.68