Skip to content

Commit

Permalink
Make shared attribute working in Golang
Browse files Browse the repository at this point in the history
  • Loading branch information
altexy authored and Aleksandr Altshuler committed Jan 6, 2025
1 parent 8694806 commit 33ac2f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/source/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,6 @@ Current understood attributes:
it won't be accessible anymore by newer code. Note that if you deprecate a
field that was previous required, old code may fail to validate new data (when
using the optional verifier).

### `required`

- `required` (on a non-scalar table field): this field must always be set. By
default, fields do not need to be present in the binary. This is desirable, as
it helps with forwards/backwards compatibility, and flexibility of data
Expand All @@ -452,6 +449,9 @@ Current understood attributes:
- `force_align: size` (on a vector): force the alignment of this vector to be
something different than what the element size would normally dictate. Note:
Now only work for generated C++ code.
- `shared` (on a field): For string fields, this enables the usage of string
pooling (i.e. `CreateSharedString`) as default serialization behavior. Note:
Now only work for generated C++ and Golang code.
- `bit_flags` (on an unsigned enum): the values of this field indicate bits,
meaning that any unsigned value N specified in the schema will end up
representing 1<<N, or if you don't specify values at all, you'll get the
Expand Down
9 changes: 7 additions & 2 deletions src/idl_gen_go.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,13 @@ class GoGenerator : public BaseGenerator {
if (IsString(field.value.type)) {
code += "\t" + offset + " := flatbuffers.UOffsetT(0)\n";
code += "\tif t." + field_field + " != \"\" {\n";
code += "\t\t" + offset + " = builder.CreateString(t." + field_field +
")\n";
if (field.shared) {
code += "\t\t" + offset + " = builder.CreateSharedString(t." + field_field +
")\n";
} else {
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 &&
Expand Down

0 comments on commit 33ac2f9

Please sign in to comment.