mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-20 13:45:06 +00:00
Add support of Optional<T> scalars to C++ code generator (#6092)
This commit is contained in:
@@ -3,6 +3,10 @@ import flatbuffers
|
||||
|
||||
namespace optional_scalars
|
||||
|
||||
enum OptionalByte:
|
||||
OptionalByte_None = 0
|
||||
OptionalByte_One = 1
|
||||
|
||||
class ScalarStuff
|
||||
|
||||
class ScalarStuff : flatbuffers_handle
|
||||
@@ -72,13 +76,17 @@ class ScalarStuff : flatbuffers_handle
|
||||
return buf_.flatbuffers_field_int8(pos_, 66, 0), buf_.flatbuffers_field_present(pos_, 66)
|
||||
def default_bool():
|
||||
return buf_.flatbuffers_field_int8(pos_, 68, 1)
|
||||
def just_enum():
|
||||
return OptionalByte(buf_.flatbuffers_field_int8(pos_, 70, 0))
|
||||
def default_enum():
|
||||
return OptionalByte(buf_.flatbuffers_field_int8(pos_, 72, 1))
|
||||
|
||||
def GetRootAsScalarStuff(buf:string): return ScalarStuff { buf, buf.flatbuffers_indirect(0) }
|
||||
|
||||
struct ScalarStuffBuilder:
|
||||
b_:flatbuffers_builder
|
||||
def start():
|
||||
b_.StartObject(33)
|
||||
b_.StartObject(35)
|
||||
return this
|
||||
def add_just_i8(just_i8:int):
|
||||
b_.PrependInt8Slot(0, just_i8, 0)
|
||||
@@ -179,6 +187,12 @@ struct ScalarStuffBuilder:
|
||||
def add_default_bool(default_bool:int):
|
||||
b_.PrependBoolSlot(32, default_bool, 1)
|
||||
return this
|
||||
def add_just_enum(just_enum:OptionalByte):
|
||||
b_.PrependInt8Slot(33, just_enum, 0)
|
||||
return this
|
||||
def add_default_enum(default_enum:OptionalByte):
|
||||
b_.PrependInt8Slot(34, default_enum, 1)
|
||||
return this
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user