mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
[C#] Use @ for keyword escaping (#6834)
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
namespace KeywordTest;
|
||||
|
||||
enum ABC: int { void, where, stackalloc }
|
||||
|
||||
|
||||
@@ -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]
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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_ {}
|
||||
Reference in New Issue
Block a user