mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
[Lua] manipulate byte array as string (#6624)
* [Lua] manipulate byte array as string Sometimes it would be more effective than reading byte by byte * change according to the review * update
This commit is contained in:
@@ -339,6 +339,18 @@ class LuaGenerator : public BaseGenerator {
|
||||
code += EndFunc;
|
||||
}
|
||||
|
||||
// Access a byte/ubyte vector as a string
|
||||
void AccessByteVectorAsString(const StructDef &struct_def,
|
||||
const FieldDef &field, std::string *code_ptr) {
|
||||
std::string &code = *code_ptr;
|
||||
GenReceiver(struct_def, code_ptr);
|
||||
code += MakeCamel(NormalizedName(field));
|
||||
code += "AsString(start, stop)\n";
|
||||
code += std::string(Indent) + "return " + SelfData + ":VectorAsString(" +
|
||||
NumToString(field.value.offset) + ", start, stop)\n";
|
||||
code += EndFunc;
|
||||
}
|
||||
|
||||
// Begin the creator function signature.
|
||||
void BeginBuilderArgs(const StructDef &struct_def, std::string *code_ptr) {
|
||||
std::string &code = *code_ptr;
|
||||
@@ -499,6 +511,10 @@ class LuaGenerator : public BaseGenerator {
|
||||
GetMemberOfVectorOfStruct(struct_def, field, code_ptr);
|
||||
} else {
|
||||
GetMemberOfVectorOfNonStruct(struct_def, field, code_ptr);
|
||||
if (vectortype.base_type == BASE_TYPE_CHAR ||
|
||||
vectortype.base_type == BASE_TYPE_UCHAR) {
|
||||
AccessByteVectorAsString(struct_def, field, code_ptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user