MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / GetAnyValueS

Function GetAnyValueS

native/thirdpart/flatbuffers/reflection.cpp:71–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71std::string GetAnyValueS(reflection::BaseType type, const uint8_t *data,
72 const reflection::Schema *schema, int type_index) {
73 switch (type) {
74 case reflection::Float:
75 case reflection::Double: return NumToString(GetAnyValueF(type, data));
76 case reflection::String: {
77 auto s =
78 reinterpret_cast<const String *>(ReadScalar<uoffset_t>(data) + data);
79 return s ? s->c_str() : "";
80 }
81 case reflection::Obj:
82 if (schema) {
83 // Convert the table to a string. This is mostly for debugging purposes,
84 // and does NOT promise to be JSON compliant.
85 // Also prefixes the type.
86 auto &objectdef = *schema->objects()->Get(type_index);
87 auto s = objectdef.name()->str();
88 if (objectdef.is_struct()) {
89 s += "(struct)"; // TODO: implement this as well.
90 } else {
91 auto table_field = reinterpret_cast<const Table *>(
92 ReadScalar<uoffset_t>(data) + data);
93 s += " { ";
94 auto fielddefs = objectdef.fields();
95 for (auto it = fielddefs->begin(); it != fielddefs->end(); ++it) {
96 auto &fielddef = **it;
97 if (!table_field->CheckField(fielddef.offset())) continue;
98 auto val = GetAnyFieldS(*table_field, fielddef, schema);
99 if (fielddef.type()->base_type() == reflection::String) {
100 std::string esc;
101 flatbuffers::EscapeString(val.c_str(), val.length(), &esc, true,
102 false);
103 val = esc;
104 }
105 s += fielddef.name()->str();
106 s += ": ";
107 s += val;
108 s += ", ";
109 }
110 s += "}";
111 }
112 return s;
113 } else {
114 return "(table)";
115 }
116 case reflection::Vector:
117 return "[(elements)]"; // TODO: implement this as well.
118 case reflection::Union: return "(union)"; // TODO: implement this as well.
119 default: return NumToString(GetAnyValueI(type, data));
120 }
121}
122
123void SetAnyValueI(reflection::BaseType type, uint8_t *data, int64_t val) {
124// clang-format off

Callers 2

GetAnyFieldSFunction · 0.85
GetAnyVectorElemSFunction · 0.85

Calls 13

NumToStringFunction · 0.85
GetAnyValueFFunction · 0.85
GetAnyFieldSFunction · 0.85
EscapeStringFunction · 0.85
GetAnyValueIFunction · 0.85
nameMethod · 0.80
CheckFieldMethod · 0.80
lengthMethod · 0.80
c_strMethod · 0.45
GetMethod · 0.45
strMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected