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

Function DoLoadDefaultField

engine/ddf/src/ddf/ddf_load.cpp:75–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73 static void DoLoadDefaultMessage(LoadContext* load_context, const Descriptor* desc, Message* message);
74
75 static void DoLoadDefaultField(LoadContext* load_context, const FieldDescriptor* f, Message* message)
76 {
77 if (f->m_Label == LABEL_REPEATED)
78 {
79 // Nothing to read default
80 }
81 else if (f->m_Label == LABEL_REQUIRED)
82 {
83 // Try to load default but the field is required. Invalid definition
84 dmLogWarning("Invalid message type. Required field (%s) in an optional message.", f->m_Name);
85 }
86 else if (f->m_Label == LABEL_OPTIONAL)
87 {
88 if (f->m_Type == TYPE_STRING && f->m_DefaultValue)
89 {
90 message->SetString(load_context, f, f->m_DefaultValue, strlen(f->m_DefaultValue));
91 }
92 else if (f->m_Type == TYPE_BYTES && f->m_DefaultValue)
93 {
94 dmLogWarning("Default values for 'bytes' is not supported");
95 }
96 else if (f->m_Type == TYPE_MESSAGE)
97 {
98 Message sub_message = message->SubMessage(f);
99 DoLoadDefaultMessage(load_context, f->m_MessageDescriptor, &sub_message);
100 }
101 else if (f->m_DefaultValue)
102 {
103 // Assume scalar type
104 message->SetScalar(f, f->m_DefaultValue, ScalarTypeSize(f->m_Type));
105 }
106 }
107 }
108
109 static bool HasDescriptorRecursive(const Descriptor* desc, const FieldDescriptor* f)
110 {

Callers 2

DoLoadDefaultMessageFunction · 0.85
DoLoadMessageFunction · 0.85

Calls 5

DoLoadDefaultMessageFunction · 0.85
ScalarTypeSizeFunction · 0.85
SetStringMethod · 0.80
SubMessageMethod · 0.80
SetScalarMethod · 0.80

Tested by

no test coverage detected