Perform nil check on string fields when packing (#7719)
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
parent
4e396d47bc
commit
96d438df47
|
@ -1054,8 +1054,11 @@ class GoGenerator : public BaseGenerator {
|
|||
const std::string offset = field_var + "Offset";
|
||||
|
||||
if (IsString(field.value.type)) {
|
||||
code +=
|
||||
"\t" + offset + " := builder.CreateString(t." + field_field + ")\n";
|
||||
code += "\t" + offset + " := flatbuffers.UOffsetT(0)\n";
|
||||
code += "\tif t." + field_field + " != \"\" {\n";
|
||||
code += "\t\t" + offset + " = builder.CreateString(t." + field_field +
|
||||
")\n";
|
||||
code += "\t}\n";
|
||||
} else if (IsVector(field.value.type) &&
|
||||
field.value.type.element == BASE_TYPE_UCHAR &&
|
||||
field.value.type.enum_def == nullptr) {
|
||||
|
|
|
@ -74,7 +74,10 @@ type MonsterT struct {
|
|||
|
||||
func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
nameOffset := builder.CreateString(t.Name)
|
||||
nameOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Name != "" {
|
||||
nameOffset = builder.CreateString(t.Name)
|
||||
}
|
||||
inventoryOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Inventory != nil {
|
||||
inventoryOffset = builder.CreateByteString(t.Inventory)
|
||||
|
|
|
@ -14,7 +14,10 @@ type StatT struct {
|
|||
|
||||
func (t *StatT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
idOffset := builder.CreateString(t.Id)
|
||||
idOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Id != "" {
|
||||
idOffset = builder.CreateString(t.Id)
|
||||
}
|
||||
StatStart(builder)
|
||||
StatAddId(builder, idOffset)
|
||||
StatAddVal(builder, t.Val)
|
||||
|
|
Loading…
Reference in New Issue