mirror of
https://github.com/google/flatbuffers.git
synced 2025-04-09 00:12:15 +08:00
Kotlin test optional enum (#6201)
* Add test for optional enums in Kotlin * Rename optional_scalars2.fbs into optional_scalars.fbs Also updated all references in the project to point to "optional_scalars.fbs" instead of "optional_scalars2.fbs".
This commit is contained in:
parent
fe8e3c7e5d
commit
1606fb6375
@ -20,7 +20,7 @@ cc_test(
|
||||
"test_builder.cpp",
|
||||
"test_builder.h",
|
||||
"union_vector/union_vector_generated.h",
|
||||
"optional_scalars2_generated.h",
|
||||
"optional_scalars_generated.h",
|
||||
],
|
||||
copts = [
|
||||
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
|
||||
@ -54,7 +54,7 @@ cc_test(
|
||||
":unicode_test.json",
|
||||
":union_vector/union_vector.fbs",
|
||||
":union_vector/union_vector.json",
|
||||
":optional_scalars2.fbs",
|
||||
":optional_scalars.fbs",
|
||||
],
|
||||
includes = [
|
||||
"",
|
||||
|
@ -4,7 +4,7 @@ test_dir=`pwd`
|
||||
|
||||
cd ${swift_dir}/Tests/FlatBuffers.Test.SwiftTests
|
||||
${test_dir}/../flatc --swift --gen-mutable --grpc --gen-object-api -I ${test_dir}/include_test ${test_dir}/monster_test.fbs ${test_dir}/union_vector/union_vector.fbs
|
||||
${test_dir}/../flatc --swift ${test_dir}/optional_scalars2.fbs
|
||||
${test_dir}/../flatc --swift ${test_dir}/optional_scalars.fbs
|
||||
cd ${swift_dir}
|
||||
swift build --build-tests
|
||||
swift test
|
||||
|
@ -510,6 +510,9 @@ class KotlinTest {
|
||||
assert(scalarStuff.justBool == false)
|
||||
assert(scalarStuff.maybeBool == null)
|
||||
assert(scalarStuff.defaultBool == true)
|
||||
assert(scalarStuff.justEnum == OptionalByte.None)
|
||||
assert(scalarStuff.maybeEnum == null)
|
||||
assert(scalarStuff.defaultEnum == OptionalByte.One)
|
||||
|
||||
fbb.clear()
|
||||
|
||||
@ -547,6 +550,9 @@ class KotlinTest {
|
||||
ScalarStuff.addJustBool(fbb, true)
|
||||
ScalarStuff.addMaybeBool(fbb, true)
|
||||
ScalarStuff.addDefaultBool(fbb, true)
|
||||
ScalarStuff.addJustEnum(fbb, OptionalByte.Two)
|
||||
ScalarStuff.addMaybeEnum(fbb, OptionalByte.Two)
|
||||
ScalarStuff.addDefaultEnum(fbb, OptionalByte.Two)
|
||||
|
||||
pos = ScalarStuff.endScalarStuff(fbb)
|
||||
|
||||
@ -587,6 +593,9 @@ class KotlinTest {
|
||||
assert(scalarStuff.justBool == true)
|
||||
assert(scalarStuff.maybeBool == true)
|
||||
assert(scalarStuff.defaultBool == true)
|
||||
assert(scalarStuff.justEnum == OptionalByte.Two)
|
||||
assert(scalarStuff.maybeEnum == OptionalByte.Two)
|
||||
assert(scalarStuff.defaultEnum == OptionalByte.Two)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,29 +17,32 @@ inline const flatbuffers::TypeTable *ScalarStuffTypeTable();
|
||||
enum class OptionalByte : int8_t {
|
||||
None = 0,
|
||||
One = 1,
|
||||
Two = 2,
|
||||
MIN = None,
|
||||
MAX = One
|
||||
MAX = Two
|
||||
};
|
||||
|
||||
inline const OptionalByte (&EnumValuesOptionalByte())[2] {
|
||||
inline const OptionalByte (&EnumValuesOptionalByte())[3] {
|
||||
static const OptionalByte values[] = {
|
||||
OptionalByte::None,
|
||||
OptionalByte::One
|
||||
OptionalByte::One,
|
||||
OptionalByte::Two
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesOptionalByte() {
|
||||
static const char * const names[3] = {
|
||||
static const char * const names[4] = {
|
||||
"None",
|
||||
"One",
|
||||
"Two",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameOptionalByte(OptionalByte e) {
|
||||
if (flatbuffers::IsOutRange(e, OptionalByte::None, OptionalByte::One)) return "";
|
||||
if (flatbuffers::IsOutRange(e, OptionalByte::None, OptionalByte::Two)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesOptionalByte()[index];
|
||||
}
|
||||
@ -80,6 +83,7 @@ struct ScalarStuffT : public flatbuffers::NativeTable {
|
||||
flatbuffers::Optional<bool> maybe_bool = flatbuffers::nullopt;
|
||||
bool default_bool = true;
|
||||
optional_scalars::OptionalByte just_enum = optional_scalars::OptionalByte::None;
|
||||
flatbuffers::Optional<optional_scalars::OptionalByte> maybe_enum = flatbuffers::nullopt;
|
||||
optional_scalars::OptionalByte default_enum = optional_scalars::OptionalByte::One;
|
||||
};
|
||||
|
||||
@ -125,7 +129,8 @@ struct ScalarStuff FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
VT_MAYBE_BOOL = 66,
|
||||
VT_DEFAULT_BOOL = 68,
|
||||
VT_JUST_ENUM = 70,
|
||||
VT_DEFAULT_ENUM = 72
|
||||
VT_MAYBE_ENUM = 72,
|
||||
VT_DEFAULT_ENUM = 74
|
||||
};
|
||||
int8_t just_i8() const {
|
||||
return GetField<int8_t>(VT_JUST_I8, 0);
|
||||
@ -331,6 +336,12 @@ struct ScalarStuff FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_just_enum(optional_scalars::OptionalByte _just_enum) {
|
||||
return SetField<int8_t>(VT_JUST_ENUM, static_cast<int8_t>(_just_enum), 0);
|
||||
}
|
||||
flatbuffers::Optional<optional_scalars::OptionalByte> maybe_enum() const {
|
||||
return GetOptional<int8_t, optional_scalars::OptionalByte>(VT_MAYBE_ENUM);
|
||||
}
|
||||
bool mutate_maybe_enum(optional_scalars::OptionalByte _maybe_enum) {
|
||||
return SetField<int8_t>(VT_MAYBE_ENUM, static_cast<int8_t>(_maybe_enum));
|
||||
}
|
||||
optional_scalars::OptionalByte default_enum() const {
|
||||
return static_cast<optional_scalars::OptionalByte>(GetField<int8_t>(VT_DEFAULT_ENUM, 1));
|
||||
}
|
||||
@ -373,6 +384,7 @@ struct ScalarStuff FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
VerifyField<uint8_t>(verifier, VT_MAYBE_BOOL) &&
|
||||
VerifyField<uint8_t>(verifier, VT_DEFAULT_BOOL) &&
|
||||
VerifyField<int8_t>(verifier, VT_JUST_ENUM) &&
|
||||
VerifyField<int8_t>(verifier, VT_MAYBE_ENUM) &&
|
||||
VerifyField<int8_t>(verifier, VT_DEFAULT_ENUM) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
@ -487,6 +499,9 @@ struct ScalarStuffBuilder {
|
||||
void add_just_enum(optional_scalars::OptionalByte just_enum) {
|
||||
fbb_.AddElement<int8_t>(ScalarStuff::VT_JUST_ENUM, static_cast<int8_t>(just_enum), 0);
|
||||
}
|
||||
void add_maybe_enum(optional_scalars::OptionalByte maybe_enum) {
|
||||
fbb_.AddElement<int8_t>(ScalarStuff::VT_MAYBE_ENUM, static_cast<int8_t>(maybe_enum));
|
||||
}
|
||||
void add_default_enum(optional_scalars::OptionalByte default_enum) {
|
||||
fbb_.AddElement<int8_t>(ScalarStuff::VT_DEFAULT_ENUM, static_cast<int8_t>(default_enum), 1);
|
||||
}
|
||||
@ -504,39 +519,40 @@ struct ScalarStuffBuilder {
|
||||
inline flatbuffers::Offset<ScalarStuff> CreateScalarStuff(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int8_t just_i8 = 0,
|
||||
flatbuffers::Optional<int8_t>maybe_i8 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<int8_t> maybe_i8 = flatbuffers::nullopt,
|
||||
int8_t default_i8 = 42,
|
||||
uint8_t just_u8 = 0,
|
||||
flatbuffers::Optional<uint8_t>maybe_u8 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<uint8_t> maybe_u8 = flatbuffers::nullopt,
|
||||
uint8_t default_u8 = 42,
|
||||
int16_t just_i16 = 0,
|
||||
flatbuffers::Optional<int16_t>maybe_i16 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<int16_t> maybe_i16 = flatbuffers::nullopt,
|
||||
int16_t default_i16 = 42,
|
||||
uint16_t just_u16 = 0,
|
||||
flatbuffers::Optional<uint16_t>maybe_u16 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<uint16_t> maybe_u16 = flatbuffers::nullopt,
|
||||
uint16_t default_u16 = 42,
|
||||
int32_t just_i32 = 0,
|
||||
flatbuffers::Optional<int32_t>maybe_i32 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<int32_t> maybe_i32 = flatbuffers::nullopt,
|
||||
int32_t default_i32 = 42,
|
||||
uint32_t just_u32 = 0,
|
||||
flatbuffers::Optional<uint32_t>maybe_u32 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<uint32_t> maybe_u32 = flatbuffers::nullopt,
|
||||
uint32_t default_u32 = 42,
|
||||
int64_t just_i64 = 0,
|
||||
flatbuffers::Optional<int64_t>maybe_i64 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<int64_t> maybe_i64 = flatbuffers::nullopt,
|
||||
int64_t default_i64 = 42LL,
|
||||
uint64_t just_u64 = 0,
|
||||
flatbuffers::Optional<uint64_t>maybe_u64 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<uint64_t> maybe_u64 = flatbuffers::nullopt,
|
||||
uint64_t default_u64 = 42ULL,
|
||||
float just_f32 = 0.0f,
|
||||
flatbuffers::Optional<float>maybe_f32 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<float> maybe_f32 = flatbuffers::nullopt,
|
||||
float default_f32 = 42.0f,
|
||||
double just_f64 = 0.0,
|
||||
flatbuffers::Optional<double>maybe_f64 = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<double> maybe_f64 = flatbuffers::nullopt,
|
||||
double default_f64 = 42.0,
|
||||
bool just_bool = false,
|
||||
flatbuffers::Optional<bool>maybe_bool = flatbuffers::nullopt,
|
||||
flatbuffers::Optional<bool> maybe_bool = flatbuffers::nullopt,
|
||||
bool default_bool = true,
|
||||
optional_scalars::OptionalByte just_enum = optional_scalars::OptionalByte::None,
|
||||
flatbuffers::Optional<optional_scalars::OptionalByte> maybe_enum = flatbuffers::nullopt,
|
||||
optional_scalars::OptionalByte default_enum = optional_scalars::OptionalByte::One) {
|
||||
ScalarStuffBuilder builder_(_fbb);
|
||||
builder_.add_default_f64(default_f64);
|
||||
@ -564,6 +580,7 @@ inline flatbuffers::Offset<ScalarStuff> CreateScalarStuff(
|
||||
if(maybe_i16) { builder_.add_maybe_i16(*maybe_i16); }
|
||||
builder_.add_just_i16(just_i16);
|
||||
builder_.add_default_enum(default_enum);
|
||||
if(maybe_enum) { builder_.add_maybe_enum(*maybe_enum); }
|
||||
builder_.add_just_enum(just_enum);
|
||||
builder_.add_default_bool(default_bool);
|
||||
if(maybe_bool) { builder_.add_maybe_bool(*maybe_bool); }
|
||||
@ -627,6 +644,7 @@ inline void ScalarStuff::UnPackTo(ScalarStuffT *_o, const flatbuffers::resolver_
|
||||
{ auto _e = maybe_bool(); _o->maybe_bool = _e; }
|
||||
{ auto _e = default_bool(); _o->default_bool = _e; }
|
||||
{ auto _e = just_enum(); _o->just_enum = _e; }
|
||||
{ auto _e = maybe_enum(); _o->maybe_enum = _e; }
|
||||
{ auto _e = default_enum(); _o->default_enum = _e; }
|
||||
}
|
||||
|
||||
@ -672,6 +690,7 @@ inline flatbuffers::Offset<ScalarStuff> CreateScalarStuff(flatbuffers::FlatBuffe
|
||||
auto _maybe_bool = _o->maybe_bool;
|
||||
auto _default_bool = _o->default_bool;
|
||||
auto _just_enum = _o->just_enum;
|
||||
auto _maybe_enum = _o->maybe_enum;
|
||||
auto _default_enum = _o->default_enum;
|
||||
return optional_scalars::CreateScalarStuff(
|
||||
_fbb,
|
||||
@ -709,11 +728,13 @@ inline flatbuffers::Offset<ScalarStuff> CreateScalarStuff(flatbuffers::FlatBuffe
|
||||
_maybe_bool,
|
||||
_default_bool,
|
||||
_just_enum,
|
||||
_maybe_enum,
|
||||
_default_enum);
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *OptionalByteTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
@ -722,10 +743,11 @@ inline const flatbuffers::TypeTable *OptionalByteTypeTable() {
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"None",
|
||||
"One"
|
||||
"One",
|
||||
"Two"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_ENUM, 2, type_codes, type_refs, nullptr, nullptr, names
|
||||
flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
@ -766,6 +788,7 @@ inline const flatbuffers::TypeTable *ScalarStuffTypeTable() {
|
||||
{ flatbuffers::ET_BOOL, 0, -1 },
|
||||
{ flatbuffers::ET_BOOL, 0, -1 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
@ -806,10 +829,11 @@ inline const flatbuffers::TypeTable *ScalarStuffTypeTable() {
|
||||
"maybe_bool",
|
||||
"default_bool",
|
||||
"just_enum",
|
||||
"maybe_enum",
|
||||
"default_enum"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 35, type_codes, type_refs, nullptr, nullptr, names
|
||||
flatbuffers::ST_TABLE, 36, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
@ -55,9 +55,8 @@ set TEST_NOINCL_FLAGS=%TEST_BASE_FLAGS% --no-includes --no-fb-import
|
||||
..\%buildtype%\flatc.exe --cpp %TEST_BASE_FLAGS% --cpp-ptr-type flatbuffers::unique_ptr native_type_test.fbs || goto FAIL
|
||||
|
||||
@rem Generate the optional scalar code for tests.
|
||||
..\%buildtype%\flatc.exe --rust --lobster optional_scalars2.fbs || goto FAIL
|
||||
..\%buildtype%\flatc.exe --kotlin optional_scalars.fbs || goto FAIL
|
||||
..\%buildtype%\flatc.exe %TEST_NOINCL_FLAGS% %TEST_CPP_FLAGS% --cpp optional_scalars2.fbs || goto FAIL
|
||||
..\%buildtype%\flatc.exe --kotlin --rust --lobster optional_scalars.fbs || goto FAIL
|
||||
..\%buildtype%\flatc.exe %TEST_NOINCL_FLAGS% %TEST_CPP_FLAGS% --cpp optional_scalars.fbs || goto FAIL
|
||||
|
||||
@rem Generate the schema evolution tests
|
||||
..\%buildtype%\flatc.exe --cpp --scoped-enums %TEST_CPP_FLAGS% -o evolution_test ./evolution_test/evolution_v1.fbs ./evolution_test/evolution_v2.fbs || goto FAIL
|
||||
@ -74,7 +73,7 @@ set TEST_CPP17_FLAGS=--cpp --cpp-std c++17 -o ./cpp17/generated_cpp17 %TEST_NOIN
|
||||
if NOT "%MONSTER_EXTRA%"=="skip" (
|
||||
@rem Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher.
|
||||
..\%buildtype%\flatc.exe %TEST_CPP17_FLAGS% -I include_test monster_test.fbs || goto FAIL
|
||||
..\%buildtype%\flatc.exe %TEST_CPP17_FLAGS% optional_scalars2.fbs || goto FAIL
|
||||
..\%buildtype%\flatc.exe %TEST_CPP17_FLAGS% optional_scalars.fbs || goto FAIL
|
||||
@rem..\%buildtype%\flatc.exe %TEST_CPP17_FLAGS% arrays_test.fbs || goto FAIL
|
||||
@rem..\%buildtype%\flatc.exe %TEST_CPP17_FLAGS% native_type_test.fbs || goto FAIL
|
||||
@rem..\%buildtype%\flatc.exe %TEST_CPP17_FLAGS% monster_extra.fbs || goto FAIL
|
||||
|
@ -53,9 +53,8 @@ $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_JS_TS_FLAGS -o namespace
|
||||
../flatc --dart monster_extra.fbs
|
||||
|
||||
# Generate optional scalar code for tests.
|
||||
../flatc --kotlin optional_scalars.fbs # These ones have not added optional enum support.
|
||||
../flatc --rust --lobster optional_scalars2.fbs
|
||||
../flatc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS --cpp optional_scalars2.fbs
|
||||
../flatc --kotlin --rust --lobster optional_scalars.fbs
|
||||
../flatc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS --cpp optional_scalars.fbs
|
||||
|
||||
# Generate the schema evolution tests
|
||||
../flatc --cpp --scoped-enums $TEST_CPP_FLAGS -o evolution_test ./evolution_test/evolution_v*.fbs
|
||||
@ -64,7 +63,7 @@ working_dir=`pwd`
|
||||
cd FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests
|
||||
$working_dir/../flatc --swift --grpc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -I ../../../include_test ../../../monster_test.fbs
|
||||
$working_dir/../flatc --swift $TEST_BASE_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS ../../../union_vector/union_vector.fbs
|
||||
$working_dir/../flatc --swift ../../../optional_scalars2.fbs
|
||||
$working_dir/../flatc --swift ../../../optional_scalars.fbs
|
||||
cd $working_dir
|
||||
|
||||
cd FlatBuffers.GRPC.Swift/Sources/Model
|
||||
@ -86,7 +85,7 @@ fi
|
||||
# Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher.
|
||||
TEST_CPP17_FLAGS="--cpp --cpp-std c++17 -o ./cpp17/generated_cpp17 $TEST_NOINCL_FLAGS"
|
||||
../flatc $TEST_CPP17_FLAGS -I include_test monster_test.fbs
|
||||
../flatc $TEST_CPP17_FLAGS optional_scalars2.fbs
|
||||
../flatc $TEST_CPP17_FLAGS optional_scalars.fbs
|
||||
|
||||
cd ../samples
|
||||
../flatc --cpp --lobster $TEST_BASE_FLAGS $TEST_CPP_FLAGS monster.fbs
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import from "../lobster/"
|
||||
import monster_test_generated
|
||||
import optional_scalars2_generated
|
||||
import optional_scalars_generated
|
||||
|
||||
def check_read_buffer(buf):
|
||||
// CheckReadBuffer checks that the given buffer is evaluated correctly as the example Monster.
|
||||
|
@ -3,6 +3,7 @@ namespace optional_scalars;
|
||||
enum OptionalByte: byte {
|
||||
None = 0,
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
// This table tests optional scalars in tables. It should be integrated with
|
||||
@ -48,8 +49,7 @@ table ScalarStuff {
|
||||
default_bool: bool = true;
|
||||
|
||||
just_enum: OptionalByte;
|
||||
// Rust code generator failed with optional<enum>
|
||||
//maybe_enum: OptionalByte = null;
|
||||
maybe_enum: OptionalByte = null;
|
||||
default_enum: OptionalByte = One;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,8 @@ class OptionalByte private constructor() {
|
||||
companion object {
|
||||
const val None: Byte = 0
|
||||
const val One: Byte = 1
|
||||
val names : Array<String> = arrayOf("None", "One")
|
||||
const val Two: Byte = 2
|
||||
val names : Array<String> = arrayOf("None", "One", "Two")
|
||||
fun name(e: Int) : String = names[e]
|
||||
}
|
||||
}
|
||||
|
@ -187,9 +187,14 @@ class ScalarStuff : Table() {
|
||||
val o = __offset(70)
|
||||
return if(o != 0) bb.get(o + bb_pos) else 0
|
||||
}
|
||||
val defaultEnum : Byte
|
||||
val maybeEnum : Byte?
|
||||
get() {
|
||||
val o = __offset(72)
|
||||
return if(o != 0) bb.get(o + bb_pos) else null
|
||||
}
|
||||
val defaultEnum : Byte
|
||||
get() {
|
||||
val o = __offset(74)
|
||||
return if(o != 0) bb.get(o + bb_pos) else 1
|
||||
}
|
||||
companion object {
|
||||
@ -200,8 +205,8 @@ class ScalarStuff : Table() {
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun ScalarStuffBufferHasIdentifier(_bb: ByteBuffer) : Boolean = __has_identifier(_bb, "NULL")
|
||||
fun createScalarStuff(builder: FlatBufferBuilder, justI8: Byte, maybeI8: Byte?, defaultI8: Byte, justU8: UByte, maybeU8: UByte?, defaultU8: UByte, justI16: Short, maybeI16: Short?, defaultI16: Short, justU16: UShort, maybeU16: UShort?, defaultU16: UShort, justI32: Int, maybeI32: Int?, defaultI32: Int, justU32: UInt, maybeU32: UInt?, defaultU32: UInt, justI64: Long, maybeI64: Long?, defaultI64: Long, justU64: ULong, maybeU64: ULong?, defaultU64: ULong, justF32: Float, maybeF32: Float?, defaultF32: Float, justF64: Double, maybeF64: Double?, defaultF64: Double, justBool: Boolean, maybeBool: Boolean?, defaultBool: Boolean, justEnum: Byte, defaultEnum: Byte) : Int {
|
||||
builder.startTable(35)
|
||||
fun createScalarStuff(builder: FlatBufferBuilder, justI8: Byte, maybeI8: Byte?, defaultI8: Byte, justU8: UByte, maybeU8: UByte?, defaultU8: UByte, justI16: Short, maybeI16: Short?, defaultI16: Short, justU16: UShort, maybeU16: UShort?, defaultU16: UShort, justI32: Int, maybeI32: Int?, defaultI32: Int, justU32: UInt, maybeU32: UInt?, defaultU32: UInt, justI64: Long, maybeI64: Long?, defaultI64: Long, justU64: ULong, maybeU64: ULong?, defaultU64: ULong, justF32: Float, maybeF32: Float?, defaultF32: Float, justF64: Double, maybeF64: Double?, defaultF64: Double, justBool: Boolean, maybeBool: Boolean?, defaultBool: Boolean, justEnum: Byte, maybeEnum: Byte?, defaultEnum: Byte) : Int {
|
||||
builder.startTable(36)
|
||||
addDefaultF64(builder, defaultF64)
|
||||
maybeF64?.run { addMaybeF64(builder, maybeF64) }
|
||||
addJustF64(builder, justF64)
|
||||
@ -227,6 +232,7 @@ class ScalarStuff : Table() {
|
||||
maybeI16?.run { addMaybeI16(builder, maybeI16) }
|
||||
addJustI16(builder, justI16)
|
||||
addDefaultEnum(builder, defaultEnum)
|
||||
maybeEnum?.run { addMaybeEnum(builder, maybeEnum) }
|
||||
addJustEnum(builder, justEnum)
|
||||
addDefaultBool(builder, defaultBool)
|
||||
maybeBool?.run { addMaybeBool(builder, maybeBool) }
|
||||
@ -239,7 +245,7 @@ class ScalarStuff : Table() {
|
||||
addJustI8(builder, justI8)
|
||||
return endScalarStuff(builder)
|
||||
}
|
||||
fun startScalarStuff(builder: FlatBufferBuilder) = builder.startTable(35)
|
||||
fun startScalarStuff(builder: FlatBufferBuilder) = builder.startTable(36)
|
||||
fun addJustI8(builder: FlatBufferBuilder, justI8: Byte) = builder.addByte(0, justI8, 0)
|
||||
fun addMaybeI8(builder: FlatBufferBuilder, maybeI8: Byte) = builder.addByte(1, maybeI8, 0)
|
||||
fun addDefaultI8(builder: FlatBufferBuilder, defaultI8: Byte) = builder.addByte(2, defaultI8, 42)
|
||||
@ -274,7 +280,8 @@ class ScalarStuff : Table() {
|
||||
fun addMaybeBool(builder: FlatBufferBuilder, maybeBool: Boolean) = builder.addBoolean(31, maybeBool, false)
|
||||
fun addDefaultBool(builder: FlatBufferBuilder, defaultBool: Boolean) = builder.addBoolean(32, defaultBool, true)
|
||||
fun addJustEnum(builder: FlatBufferBuilder, justEnum: Byte) = builder.addByte(33, justEnum, 0)
|
||||
fun addDefaultEnum(builder: FlatBufferBuilder, defaultEnum: Byte) = builder.addByte(34, defaultEnum, 1)
|
||||
fun addMaybeEnum(builder: FlatBufferBuilder, maybeEnum: Byte) = builder.addByte(34, maybeEnum, 0)
|
||||
fun addDefaultEnum(builder: FlatBufferBuilder, defaultEnum: Byte) = builder.addByte(35, defaultEnum, 1)
|
||||
fun endScalarStuff(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
|
@ -1,59 +0,0 @@
|
||||
namespace optional_scalars;
|
||||
|
||||
enum OptionalByte: byte {
|
||||
None = 0,
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
// This table tests optional scalars in tables. It should be integrated with
|
||||
// the main monster test once most languages support optional scalars.
|
||||
table ScalarStuff {
|
||||
just_i8: int8;
|
||||
maybe_i8: int8 = null;
|
||||
default_i8: int8 = 42;
|
||||
just_u8: uint8;
|
||||
maybe_u8: uint8 = null;
|
||||
default_u8: uint8 = 42;
|
||||
|
||||
just_i16: int16;
|
||||
maybe_i16: int16 = null;
|
||||
default_i16: int16 = 42;
|
||||
just_u16: uint16;
|
||||
maybe_u16: uint16 = null;
|
||||
default_u16: uint16 = 42;
|
||||
|
||||
just_i32: int32;
|
||||
maybe_i32: int32 = null;
|
||||
default_i32: int32 = 42;
|
||||
just_u32: uint32;
|
||||
maybe_u32: uint32 = null;
|
||||
default_u32: uint32 = 42;
|
||||
|
||||
just_i64: int64;
|
||||
maybe_i64: int64 = null;
|
||||
default_i64: int64 = 42;
|
||||
just_u64: uint64;
|
||||
maybe_u64: uint64 = null;
|
||||
default_u64: uint64 = 42;
|
||||
|
||||
just_f32: float32;
|
||||
maybe_f32: float32 = null;
|
||||
default_f32: float32 = 42;
|
||||
just_f64: float64;
|
||||
maybe_f64: float64 = null;
|
||||
default_f64: float64 = 42;
|
||||
|
||||
just_bool: bool;
|
||||
maybe_bool: bool = null;
|
||||
default_bool: bool = true;
|
||||
|
||||
just_enum: OptionalByte;
|
||||
maybe_enum: OptionalByte = null;
|
||||
default_enum: OptionalByte = One;
|
||||
}
|
||||
|
||||
root_type ScalarStuff;
|
||||
|
||||
file_identifier "NULL";
|
||||
file_extension "mon";
|
@ -1,8 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_OPTIONALSCALARS2_OPTIONAL_SCALARS_H_
|
||||
#define FLATBUFFERS_GENERATED_OPTIONALSCALARS2_OPTIONAL_SCALARS_H_
|
||||
#ifndef FLATBUFFERS_GENERATED_OPTIONALSCALARS_OPTIONAL_SCALARS_H_
|
||||
#define FLATBUFFERS_GENERATED_OPTIONALSCALARS_OPTIONAL_SCALARS_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
@ -979,4 +979,4 @@ inline flatbuffers::unique_ptr<optional_scalars::ScalarStuffT> UnPackSizePrefixe
|
||||
|
||||
} // namespace optional_scalars
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_OPTIONALSCALARS2_OPTIONAL_SCALARS_H_
|
||||
#endif // FLATBUFFERS_GENERATED_OPTIONALSCALARS_OPTIONAL_SCALARS_H_
|
@ -40,7 +40,7 @@ mod monster_test_generated;
|
||||
pub use monster_test_generated::my_game;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "../../optional_scalars2_generated.rs"]
|
||||
#[path = "../../optional_scalars_generated.rs"]
|
||||
mod optional_scalars_generated;
|
||||
|
||||
#[rustfmt::skip] // TODO: Use standard rust formatting and remove dead code.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "../../optional_scalars2_generated.rs"]
|
||||
#[path = "../../optional_scalars_generated.rs"]
|
||||
mod optional_scalars_generated;
|
||||
use crate::optional_scalars_generated::optional_scalars::*;
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "namespace_test/namespace_test2_generated.h"
|
||||
#include "union_vector/union_vector_generated.h"
|
||||
#include "monster_extra_generated.h"
|
||||
#include "optional_scalars2_generated.h"
|
||||
#include "optional_scalars_generated.h"
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1700
|
||||
# include "arrays_test_generated.h"
|
||||
# include "evolution_test/evolution_v1_generated.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user