diff options
19 files changed, 111 insertions, 164 deletions
diff --git a/src/idl_gen_csharp.cpp b/src/idl_gen_csharp.cpp index fe90979f..05fe04ad 100644 --- a/src/idl_gen_csharp.cpp +++ b/src/idl_gen_csharp.cpp @@ -190,7 +190,7 @@ class CSharpGenerator : public BaseGenerator { std::unordered_set<std::string> keywords_; std::string EscapeKeyword(const std::string &name) const { - return keywords_.find(name) == keywords_.end() ? name : name + "_"; + return keywords_.find(name) == keywords_.end() ? name : "@" + name; } std::string Name(const FieldDef &field) const { diff --git a/tests/FlatBuffers.Test/FlatBuffers.Core.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Core.Test.csproj index 02b16d55..d22adf7b 100644 --- a/tests/FlatBuffers.Test/FlatBuffers.Core.Test.csproj +++ b/tests/FlatBuffers.Test/FlatBuffers.Core.Test.csproj @@ -137,17 +137,17 @@ <Compile Include="..\optional_scalars\ScalarStuff.cs"> <Link>optional_scalars\ScalarStuff.cs</Link> </Compile> - <Compile Include="..\keyword_test\ABC.cs"> - <Link>keyword_test\ABC.cs</Link> + <Compile Include="..\KeywordTest\ABC.cs"> + <Link>KeywordTest\ABC.cs</Link> </Compile> - <Compile Include="..\keyword_test\public.cs"> - <Link>keyword_test\public.cs</Link> + <Compile Include="..\KeywordTest\public.cs"> + <Link>KeywordTest\public.cs</Link> </Compile> - <Compile Include="..\keyword_test\KeywordsInTable.cs"> - <Link>keyword_test\KeywordsInTable.cs</Link> + <Compile Include="..\KeywordTest\KeywordsInTable.cs"> + <Link>KeywordTest\KeywordsInTable.cs</Link> </Compile> - <Compile Include="..\keyword_test\KeywordsInUnion.cs"> - <Link>keyword_test\KeywordsInUnion.cs</Link> + <Compile Include="..\KeywordTest\KeywordsInUnion.cs"> + <Link>KeywordTest\KeywordsInUnion.cs</Link> </Compile> </ItemGroup> diff --git a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj index 3fc23d90..c5e3ea0f 100644 --- a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj +++ b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj @@ -168,17 +168,17 @@ <Compile Include="..\optional_scalars\ScalarStuff.cs"> <Link>optional_scalars\ScalarStuff.cs</Link> </Compile> - <Compile Include="..\keyword_test\ABC.cs"> - <Link>keyword_test\ABC.cs</Link> + <Compile Include="..\KeywordTest\ABC.cs"> + <Link>KeywordTest\ABC.cs</Link> </Compile> - <Compile Include="..\keyword_test\public.cs"> - <Link>keyword_test\public.cs</Link> + <Compile Include="..\KeywordTest\public.cs"> + <Link>KeywordTest\public.cs</Link> </Compile> - <Compile Include="..\keyword_test\KeywordsInTable.cs"> - <Link>keyword_test\KeywordsInTable.cs</Link> + <Compile Include="..\KeywordTest\KeywordsInTable.cs"> + <Link>KeywordTest\KeywordsInTable.cs</Link> </Compile> - <Compile Include="..\keyword_test\KeywordsInUnion.cs"> - <Link>keyword_test\KeywordsInUnion.cs</Link> + <Compile Include="..\KeywordTest\KeywordsInUnion.cs"> + <Link>KeywordTest\KeywordsInUnion.cs</Link> </Compile> <Compile Include="Assert.cs" /> <Compile Include="ByteBufferTests.cs" /> diff --git a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs index f8c50c6c..83cb35c2 100644 --- a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs +++ b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs @@ -19,6 +19,7 @@ using System.Text; using System.Threading; using MyGame.Example; using optional_scalars; +using KeywordTest; namespace FlatBuffers.Test { @@ -1117,5 +1118,26 @@ namespace FlatBuffers.Test Assert.AreEqual(OptionalByte.Two, scalarStuff.MaybeEnum); Assert.AreEqual(OptionalByte.Two, scalarStuff.DefaultEnum); } + + + [FlatBuffersTestMethod] + public void TestKeywordEscaping() { + Assert.AreEqual((int)KeywordTest.@public.NONE, 0); + + Assert.AreEqual((int)KeywordTest.ABC.@void, 0); + Assert.AreEqual((int)KeywordTest.ABC.where, 1); + Assert.AreEqual((int)KeywordTest.ABC.@stackalloc, 2); + + var fbb = new FlatBufferBuilder(1); + var offset = KeywordsInTable.CreateKeywordsInTable( + fbb, KeywordTest.ABC.@stackalloc, KeywordTest.@public.NONE); + fbb.Finish(offset.Value); + + KeywordsInTable keywordsInTable = + KeywordsInTable.GetRootAsKeywordsInTable(fbb.DataBuffer); + + Assert.AreEqual(keywordsInTable.Is, KeywordTest.ABC.@stackalloc); + Assert.AreEqual(keywordsInTable.Private, KeywordTest.@public.NONE); + } } } diff --git a/tests/FlatBuffers.Test/NetTest.sh b/tests/FlatBuffers.Test/NetTest.sh index f8adf293..0c907675 100755 --- a/tests/FlatBuffers.Test/NetTest.sh +++ b/tests/FlatBuffers.Test/NetTest.sh @@ -19,12 +19,12 @@ $DOTNET sln add $PROJ_FILE $DOTNET restore -r linux-x64 $PROJ_FILE # Testing C# on Linux using Mono. -msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:minimal $PROJ_FILE +msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:quiet $PROJ_FILE mono $TEMP_BIN/FlatBuffers.Test.exe rm -fr $TEMP_BIN # Repeat with unsafe versions -msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:minimal $PROJ_FILE +msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:quiet $PROJ_FILE mono $TEMP_BIN/FlatBuffers.Test.exe rm -fr $TEMP_BIN @@ -36,17 +36,17 @@ $DOTNET sln add $CORE_PROJ_FILE $DOTNET restore -r linux-x64 $CORE_PROJ_FILE # Testing C# on Linux using .Net Core. -msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:minimal $CORE_PROJ_FILE +msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:quiet $CORE_PROJ_FILE $TEMP_BIN/FlatBuffers.Core.Test.exe rm -fr $TEMP_BIN # Repeat with unsafe versions -msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:minimal $CORE_PROJ_FILE +msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:quiet $CORE_PROJ_FILE $TEMP_BIN/FlatBuffers.Core.Test.exe rm -fr $TEMP_BIN # Repeat with SpanT versions -msbuild -property:Configuration=Release,EnableSpanT=true,OutputPath=$TEMP_BIN -verbosity:minimal $CORE_PROJ_FILE +msbuild -property:Configuration=Release,EnableSpanT=true,OutputPath=$TEMP_BIN -verbosity:quiet $CORE_PROJ_FILE $TEMP_BIN/FlatBuffers.Core.Test.exe rm -fr $TEMP_BIN diff --git a/tests/keyword_test/ABC.cs b/tests/KeywordTest/ABC.cs index 8fc58fb6..3d7ceff7 100644 --- a/tests/keyword_test/ABC.cs +++ b/tests/KeywordTest/ABC.cs @@ -2,11 +2,16 @@ // automatically generated by the FlatBuffers compiler, do not modify // </auto-generated> +namespace KeywordTest +{ + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] public enum ABC : int { - void_ = 0, + @void = 0, where = 1, - stackalloc_ = 2, + @stackalloc = 2, }; + +} diff --git a/tests/keyword_test/KeywordsInTable.cs b/tests/KeywordTest/KeywordsInTable.cs index 88019bab..495671bd 100644 --- a/tests/keyword_test/KeywordsInTable.cs +++ b/tests/KeywordTest/KeywordsInTable.cs @@ -2,6 +2,9 @@ // automatically generated by the FlatBuffers compiler, do not modify // </auto-generated> +namespace KeywordTest +{ + using global::System; using global::System.Collections.Generic; using global::FlatBuffers; @@ -16,31 +19,31 @@ public struct KeywordsInTable : IFlatbufferObject public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); } public KeywordsInTable __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - public ABC Is { get { int o = __p.__offset(4); return o != 0 ? (ABC)__p.bb.GetInt(o + __p.bb_pos) : ABC.void_; } } - public bool MutateIs(ABC is_) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, (int)is_); return true; } else { return false; } } - public public_ Private { get { int o = __p.__offset(6); return o != 0 ? (public_)__p.bb.GetInt(o + __p.bb_pos) : public_.NONE; } } - public bool MutatePrivate(public_ private_) { int o = __p.__offset(6); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, (int)private_); return true; } else { return false; } } + public KeywordTest.ABC Is { get { int o = __p.__offset(4); return o != 0 ? (KeywordTest.ABC)__p.bb.GetInt(o + __p.bb_pos) : KeywordTest.ABC.@void; } } + public bool MutateIs(KeywordTest.ABC @is) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, (int)@is); return true; } else { return false; } } + public KeywordTest.@public Private { get { int o = __p.__offset(6); return o != 0 ? (KeywordTest.@public)__p.bb.GetInt(o + __p.bb_pos) : KeywordTest.@public.NONE; } } + public bool MutatePrivate(KeywordTest.@public @private) { int o = __p.__offset(6); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, (int)@private); return true; } else { return false; } } public int Type { get { int o = __p.__offset(8); return o != 0 ? __p.bb.GetInt(o + __p.bb_pos) : (int)0; } } public bool MutateType(int type) { int o = __p.__offset(8); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, type); return true; } else { return false; } } - public static Offset<KeywordsInTable> CreateKeywordsInTable(FlatBufferBuilder builder, - ABC is_ = ABC.void_, - public_ private_ = public_.NONE, + public static Offset<KeywordTest.KeywordsInTable> CreateKeywordsInTable(FlatBufferBuilder builder, + KeywordTest.ABC @is = KeywordTest.ABC.@void, + KeywordTest.@public @private = KeywordTest.@public.NONE, int type = 0) { builder.StartTable(3); KeywordsInTable.AddType(builder, type); - KeywordsInTable.AddPrivate(builder, private_); - KeywordsInTable.AddIs(builder, is_); + KeywordsInTable.AddPrivate(builder, @private); + KeywordsInTable.AddIs(builder, @is); return KeywordsInTable.EndKeywordsInTable(builder); } public static void StartKeywordsInTable(FlatBufferBuilder builder) { builder.StartTable(3); } - public static void AddIs(FlatBufferBuilder builder, ABC is_) { builder.AddInt(0, (int)is_, 0); } - public static void AddPrivate(FlatBufferBuilder builder, public_ private_) { builder.AddInt(1, (int)private_, 0); } + public static void AddIs(FlatBufferBuilder builder, KeywordTest.ABC @is) { builder.AddInt(0, (int)@is, 0); } + public static void AddPrivate(FlatBufferBuilder builder, KeywordTest.@public @private) { builder.AddInt(1, (int)@private, 0); } public static void AddType(FlatBufferBuilder builder, int type) { builder.AddInt(2, type, 0); } - public static Offset<KeywordsInTable> EndKeywordsInTable(FlatBufferBuilder builder) { + public static Offset<KeywordTest.KeywordsInTable> EndKeywordsInTable(FlatBufferBuilder builder) { int o = builder.EndTable(); - return new Offset<KeywordsInTable>(o); + return new Offset<KeywordTest.KeywordsInTable>(o); } public KeywordsInTableT UnPack() { var _o = new KeywordsInTableT(); @@ -52,8 +55,8 @@ public struct KeywordsInTable : IFlatbufferObject _o.Private = this.Private; _o.Type = this.Type; } - public static Offset<KeywordsInTable> Pack(FlatBufferBuilder builder, KeywordsInTableT _o) { - if (_o == null) return default(Offset<KeywordsInTable>); + public static Offset<KeywordTest.KeywordsInTable> Pack(FlatBufferBuilder builder, KeywordsInTableT _o) { + if (_o == null) return default(Offset<KeywordTest.KeywordsInTable>); return CreateKeywordsInTable( builder, _o.Is, @@ -65,16 +68,18 @@ public struct KeywordsInTable : IFlatbufferObject public class KeywordsInTableT { [Newtonsoft.Json.JsonProperty("is")] - public ABC Is { get; set; } + public KeywordTest.ABC Is { get; set; } [Newtonsoft.Json.JsonProperty("private")] - public public_ Private { get; set; } + public KeywordTest.@public Private { get; set; } [Newtonsoft.Json.JsonProperty("type")] public int Type { get; set; } public KeywordsInTableT() { - this.Is = ABC.void_; - this.Private = public_.NONE; + this.Is = KeywordTest.ABC.@void; + this.Private = KeywordTest.@public.NONE; this.Type = 0; } } + +} diff --git a/tests/keyword_test/KeywordsInUnion.cs b/tests/KeywordTest/KeywordsInUnion.cs index 24b126ee..68c050e6 100644 --- a/tests/keyword_test/KeywordsInUnion.cs +++ b/tests/KeywordTest/KeywordsInUnion.cs @@ -2,12 +2,15 @@ // automatically generated by the FlatBuffers compiler, do not modify // </auto-generated> +namespace KeywordTest +{ + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] public enum KeywordsInUnion : byte { NONE = 0, - static_ = 1, - internal_ = 2, + @static = 1, + @internal = 2, }; public class KeywordsInUnionUnion { @@ -20,16 +23,16 @@ public class KeywordsInUnionUnion { } public T As<T>() where T : class { return this.Value as T; } - public KeywordsInTableT Asstatic() { return this.As<KeywordsInTableT>(); } - public static KeywordsInUnionUnion Fromstatic(KeywordsInTableT _static) { return new KeywordsInUnionUnion{ Type = KeywordsInUnion.static_, Value = _static }; } - public KeywordsInTableT Asinternal() { return this.As<KeywordsInTableT>(); } - public static KeywordsInUnionUnion Frominternal(KeywordsInTableT _internal) { return new KeywordsInUnionUnion{ Type = KeywordsInUnion.internal_, Value = _internal }; } + public KeywordTest.KeywordsInTableT Asstatic() { return this.As<KeywordTest.KeywordsInTableT>(); } + public static KeywordsInUnionUnion Fromstatic(KeywordTest.KeywordsInTableT _static) { return new KeywordsInUnionUnion{ Type = KeywordsInUnion.@static, Value = _static }; } + public KeywordTest.KeywordsInTableT Asinternal() { return this.As<KeywordTest.KeywordsInTableT>(); } + public static KeywordsInUnionUnion Frominternal(KeywordTest.KeywordsInTableT _internal) { return new KeywordsInUnionUnion{ Type = KeywordsInUnion.@internal, Value = _internal }; } public static int Pack(FlatBuffers.FlatBufferBuilder builder, KeywordsInUnionUnion _o) { switch (_o.Type) { default: return 0; - case KeywordsInUnion.static_: return KeywordsInTable.Pack(builder, _o.Asstatic()).Value; - case KeywordsInUnion.internal_: return KeywordsInTable.Pack(builder, _o.Asinternal()).Value; + case KeywordsInUnion.@static: return KeywordTest.KeywordsInTable.Pack(builder, _o.Asstatic()).Value; + case KeywordsInUnion.@internal: return KeywordTest.KeywordsInTable.Pack(builder, _o.Asinternal()).Value; } } } @@ -69,10 +72,12 @@ public class KeywordsInUnionUnion_JsonConverter : Newtonsoft.Json.JsonConverter if (_o == null) return null; switch (_o.Type) { default: break; - case KeywordsInUnion.static_: _o.Value = serializer.Deserialize<KeywordsInTableT>(reader); break; - case KeywordsInUnion.internal_: _o.Value = serializer.Deserialize<KeywordsInTableT>(reader); break; + case KeywordsInUnion.@static: _o.Value = serializer.Deserialize<KeywordTest.KeywordsInTableT>(reader); break; + case KeywordsInUnion.@internal: _o.Value = serializer.Deserialize<KeywordTest.KeywordsInTableT>(reader); break; } return _o; } } + +} diff --git a/tests/keyword_test/public.cs b/tests/KeywordTest/public.cs index c2f5a022..4d7684cf 100644 --- a/tests/keyword_test/public.cs +++ b/tests/KeywordTest/public.cs @@ -2,9 +2,14 @@ // automatically generated by the FlatBuffers compiler, do not modify // </auto-generated> +namespace KeywordTest +{ + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -public enum public_ : int +public enum @public : int { NONE = 0, }; + +} diff --git a/tests/generate_code.bat b/tests/generate_code.bat index 73fb1d71..bee552bb 100644 --- a/tests/generate_code.bat +++ b/tests/generate_code.bat @@ -72,7 +72,7 @@ set TEST_NOINCL_FLAGS=%TEST_BASE_FLAGS% --no-includes ..\%buildtype%\flatc.exe --cpp --scoped-enums %TEST_CPP_FLAGS% -o evolution_test ./evolution_test/evolution_v1.fbs ./evolution_test/evolution_v2.fbs || goto FAIL @rem Generate the keywords tests -..\%buildtype%\flatc.exe --csharp --scoped-enums %TEST_BASE_FLAGS% %TEST_CS_FLAGS% -o keyword_test keyword_test.fbs || goto FAIL +..\%buildtype%\flatc.exe --csharp --scoped-enums %TEST_BASE_FLAGS% %TEST_CS_FLAGS% keyword_test.fbs || goto FAIL if NOT "%MONSTER_EXTRA%"=="skip" ( @echo Generate MosterExtra diff --git a/tests/generate_code.sh b/tests/generate_code.sh index 009b67a3..b7a442b7 100755 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -74,7 +74,7 @@ $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_TS_FLAGS -o namespace_te ../flatc --cpp --scoped-enums $TEST_CPP_FLAGS -o evolution_test ./evolution_test/evolution_v*.fbs # Generate the keywords tests -../flatc --csharp $TEST_BASE_FLAGS $TEST_CS_FLAGS -o keyword_test ./keyword_test.fbs +../flatc --csharp $TEST_BASE_FLAGS $TEST_CS_FLAGS ./keyword_test.fbs ../flatc --rust $TEST_RUST_FLAGS -o keyword_test ./keyword_test.fbs working_dir=`pwd` diff --git a/tests/keyword_test.fbs b/tests/keyword_test.fbs index a7187eb2..4ca761bf 100644 --- a/tests/keyword_test.fbs +++ b/tests/keyword_test.fbs @@ -1,3 +1,4 @@ +namespace KeywordTest; enum ABC: int { void, where, stackalloc } diff --git a/tests/keyword_test/abc_generated.rs b/tests/keyword_test/keyword_test/abc_generated.rs index 99b43e46..99b43e46 100644 --- a/tests/keyword_test/abc_generated.rs +++ b/tests/keyword_test/keyword_test/abc_generated.rs diff --git a/tests/keyword_test/keywords_in_table_generated.rs b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs index 5ced5c0a..17bcd0c0 100644 --- a/tests/keyword_test/keywords_in_table_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs @@ -25,7 +25,7 @@ impl<'a> KeywordsInTable<'a> { pub const VT_TYPE_: flatbuffers::VOffsetT = 8; pub const fn get_fully_qualified_name() -> &'static str { - "KeywordsInTable" + "KeywordTest.KeywordsInTable" } #[inline] diff --git a/tests/keyword_test/keywords_in_union_generated.rs b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs index cf03797f..cf03797f 100644 --- a/tests/keyword_test/keywords_in_union_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs diff --git a/tests/keyword_test/public_generated.rs b/tests/keyword_test/keyword_test/public_generated.rs index 2de4c0b2..2de4c0b2 100644 --- a/tests/keyword_test/public_generated.rs +++ b/tests/keyword_test/keyword_test/public_generated.rs diff --git a/tests/keyword_test/mod.rs b/tests/keyword_test/mod.rs index 02506f8e..94ce6504 100644 --- a/tests/keyword_test/mod.rs +++ b/tests/keyword_test/mod.rs @@ -1,9 +1,12 @@ // Automatically generated by the Flatbuffers compiler. Do not modify. -mod abc_generated; -pub use self::abc_generated::*; -mod public_generated; -pub use self::public_generated::*; -mod keywords_in_union_generated; -pub use self::keywords_in_union_generated::*; -mod keywords_in_table_generated; -pub use self::keywords_in_table_generated::*; +pub mod keyword_test { + use super::*; + mod abc_generated; + pub use self::abc_generated::*; + mod public_generated; + pub use self::public_generated::*; + mod keywords_in_union_generated; + pub use self::keywords_in_union_generated::*; + mod keywords_in_table_generated; + pub use self::keywords_in_table_generated::*; +} // keyword_test diff --git a/tests/keyword_test/type.cs b/tests/keyword_test/type.cs deleted file mode 100644 index 9938a2fa..00000000 --- a/tests/keyword_test/type.cs +++ /dev/null @@ -1,10 +0,0 @@ -// <auto-generated> -// automatically generated by the FlatBuffers compiler, do not modify -// </auto-generated> - -[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -public enum type : sbyte -{ - NONE = 0, -}; - diff --git a/tests/keyword_test/type_generated.rs b/tests/keyword_test/type_generated.rs deleted file mode 100644 index ff932391..00000000 --- a/tests/keyword_test/type_generated.rs +++ /dev/null @@ -1,89 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; -use super::*; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_TYPE_: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_TYPE_: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_TYPE_: [type_; 1] = [ - type_::NONE, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct type_(pub i8); -#[allow(non_upper_case_globals)] -impl type_ { - pub const NONE: Self = Self(0); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 0; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::NONE, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::NONE => Some("NONE"), - _ => None, - } - } -} -impl std::fmt::Debug for type_ { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for type_ { - type Inner = Self; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { - flatbuffers::read_scalar_at::<i8>(buf, loc) - }; - Self(b) - } -} - -impl flatbuffers::Push for type_ { - type Output = type_; - #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); } - } -} - -impl flatbuffers::EndianScalar for type_ { - #[inline] - fn to_little_endian(self) -> Self { - let b = i8::to_le(self.0); - Self(b) - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(self) -> Self { - let b = i8::from_le(self.0); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for type_ { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for type_ {} |