Merge commit '0f6aab9da6fe982218a01f4a5b896e65fcced437' as 'third_party/flatbuffers'
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# Generated files shouldn't be checked in for tests.
|
||||
**_generated.h
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace v1;
|
||||
|
||||
table RootTable {
|
||||
a:float;
|
||||
b:[uint8];
|
||||
}
|
||||
|
||||
root_type RootTable;
|
||||
@@ -0,0 +1,219 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_V1_V1_H_
|
||||
#define FLATBUFFERS_GENERATED_V1_V1_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 25,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace v1 {
|
||||
|
||||
struct RootTable;
|
||||
struct RootTableBuilder;
|
||||
struct RootTableT;
|
||||
|
||||
bool operator==(const RootTableT &lhs, const RootTableT &rhs);
|
||||
bool operator!=(const RootTableT &lhs, const RootTableT &rhs);
|
||||
|
||||
inline const ::flatbuffers::TypeTable *RootTableTypeTable();
|
||||
|
||||
struct RootTableT : public ::flatbuffers::NativeTable {
|
||||
typedef RootTable TableType;
|
||||
float a = 0.0f;
|
||||
std::vector<uint8_t> b{};
|
||||
};
|
||||
|
||||
struct RootTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef RootTableT NativeTableType;
|
||||
typedef RootTableBuilder Builder;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return RootTableTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_A = 4,
|
||||
VT_B = 6
|
||||
};
|
||||
float a() const {
|
||||
return GetField<float>(VT_A, 0.0f);
|
||||
}
|
||||
bool mutate_a(float _a = 0.0f) {
|
||||
return SetField<float>(VT_A, _a, 0.0f);
|
||||
}
|
||||
const ::flatbuffers::Vector<uint8_t> *b() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_B);
|
||||
}
|
||||
::flatbuffers::Vector<uint8_t> *mutable_b() {
|
||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_B);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<float>(verifier, VT_A, 4) &&
|
||||
VerifyOffset(verifier, VT_B) &&
|
||||
verifier.VerifyVector(b()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
RootTableT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(RootTableT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<RootTable> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const RootTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
struct RootTableBuilder {
|
||||
typedef RootTable Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_a(float a) {
|
||||
fbb_.AddElement<float>(RootTable::VT_A, a, 0.0f);
|
||||
}
|
||||
void add_b(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> b) {
|
||||
fbb_.AddOffset(RootTable::VT_B, b);
|
||||
}
|
||||
explicit RootTableBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RootTable> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RootTable>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTable(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
float a = 0.0f,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> b = 0) {
|
||||
RootTableBuilder builder_(_fbb);
|
||||
builder_.add_b(b);
|
||||
builder_.add_a(a);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTableDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
float a = 0.0f,
|
||||
const std::vector<uint8_t> *b = nullptr) {
|
||||
auto b__ = b ? _fbb.CreateVector<uint8_t>(*b) : 0;
|
||||
return v1::CreateRootTable(
|
||||
_fbb,
|
||||
a,
|
||||
b__);
|
||||
}
|
||||
|
||||
::flatbuffers::Offset<RootTable> CreateRootTable(::flatbuffers::FlatBufferBuilder &_fbb, const RootTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
|
||||
inline bool operator==(const RootTableT &lhs, const RootTableT &rhs) {
|
||||
return
|
||||
(lhs.a == rhs.a) &&
|
||||
(lhs.b == rhs.b);
|
||||
}
|
||||
|
||||
inline bool operator!=(const RootTableT &lhs, const RootTableT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline RootTableT *RootTable::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<RootTableT>(new RootTableT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void RootTable::UnPackTo(RootTableT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = a(); _o->a = _e; }
|
||||
{ auto _e = b(); if (_e) { _o->b.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->b.begin()); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> RootTable::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const RootTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateRootTable(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTable(::flatbuffers::FlatBufferBuilder &_fbb, const RootTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const RootTableT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _a = _o->a;
|
||||
auto _b = _o->b.size() ? _fbb.CreateVector(_o->b) : 0;
|
||||
return v1::CreateRootTable(
|
||||
_fbb,
|
||||
_a,
|
||||
_b);
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *RootTableTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 }
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"a",
|
||||
"b"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const v1::RootTable *GetRootTable(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<v1::RootTable>(buf);
|
||||
}
|
||||
|
||||
inline const v1::RootTable *GetSizePrefixedRootTable(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<v1::RootTable>(buf);
|
||||
}
|
||||
|
||||
inline RootTable *GetMutableRootTable(void *buf) {
|
||||
return ::flatbuffers::GetMutableRoot<RootTable>(buf);
|
||||
}
|
||||
|
||||
inline v1::RootTable *GetMutableSizePrefixedRootTable(void *buf) {
|
||||
return ::flatbuffers::GetMutableSizePrefixedRoot<v1::RootTable>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyRootTableBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<v1::RootTable>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedRootTableBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<v1::RootTable>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishRootTableBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<v1::RootTable> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedRootTableBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<v1::RootTable> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
inline std::unique_ptr<v1::RootTableT> UnPackRootTable(
|
||||
const void *buf,
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<v1::RootTableT>(GetRootTable(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
inline std::unique_ptr<v1::RootTableT> UnPackSizePrefixedRootTable(
|
||||
const void *buf,
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<v1::RootTableT>(GetSizePrefixedRootTable(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
} // namespace v1
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_V1_V1_H_
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace v2;
|
||||
|
||||
table RootTable {
|
||||
a:float;
|
||||
b:[uint8];
|
||||
big_vector:[uint8] (vector64);
|
||||
}
|
||||
|
||||
root_type RootTable;
|
||||
@@ -0,0 +1,243 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_V2_V2_H_
|
||||
#define FLATBUFFERS_GENERATED_V2_V2_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 25,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace v2 {
|
||||
|
||||
struct RootTable;
|
||||
struct RootTableBuilder;
|
||||
struct RootTableT;
|
||||
|
||||
bool operator==(const RootTableT &lhs, const RootTableT &rhs);
|
||||
bool operator!=(const RootTableT &lhs, const RootTableT &rhs);
|
||||
|
||||
inline const ::flatbuffers::TypeTable *RootTableTypeTable();
|
||||
|
||||
struct RootTableT : public ::flatbuffers::NativeTable {
|
||||
typedef RootTable TableType;
|
||||
float a = 0.0f;
|
||||
std::vector<uint8_t> b{};
|
||||
std::vector<uint8_t> big_vector{};
|
||||
};
|
||||
|
||||
struct RootTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef RootTableT NativeTableType;
|
||||
typedef RootTableBuilder Builder;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return RootTableTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_A = 4,
|
||||
VT_B = 6,
|
||||
VT_BIG_VECTOR = 8
|
||||
};
|
||||
float a() const {
|
||||
return GetField<float>(VT_A, 0.0f);
|
||||
}
|
||||
bool mutate_a(float _a = 0.0f) {
|
||||
return SetField<float>(VT_A, _a, 0.0f);
|
||||
}
|
||||
const ::flatbuffers::Vector<uint8_t> *b() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_B);
|
||||
}
|
||||
::flatbuffers::Vector<uint8_t> *mutable_b() {
|
||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_B);
|
||||
}
|
||||
const ::flatbuffers::Vector64<uint8_t> *big_vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector64<uint8_t> *>(VT_BIG_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector64<uint8_t> *mutable_big_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector64<uint8_t> *>(VT_BIG_VECTOR);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<float>(verifier, VT_A, 4) &&
|
||||
VerifyOffset(verifier, VT_B) &&
|
||||
verifier.VerifyVector(b()) &&
|
||||
VerifyOffset64(verifier, VT_BIG_VECTOR) &&
|
||||
verifier.VerifyVector(big_vector()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
RootTableT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(RootTableT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<RootTable> Pack(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
struct RootTableBuilder {
|
||||
typedef RootTable Table;
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_a(float a) {
|
||||
fbb_.AddElement<float>(RootTable::VT_A, a, 0.0f);
|
||||
}
|
||||
void add_b(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> b) {
|
||||
fbb_.AddOffset(RootTable::VT_B, b);
|
||||
}
|
||||
void add_big_vector(::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> big_vector) {
|
||||
fbb_.AddOffset(RootTable::VT_BIG_VECTOR, big_vector);
|
||||
}
|
||||
explicit RootTableBuilder(::flatbuffers::FlatBufferBuilder64 &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RootTable> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RootTable>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTable(
|
||||
::flatbuffers::FlatBufferBuilder64 &_fbb,
|
||||
float a = 0.0f,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> b = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> big_vector = 0) {
|
||||
RootTableBuilder builder_(_fbb);
|
||||
builder_.add_big_vector(big_vector);
|
||||
builder_.add_b(b);
|
||||
builder_.add_a(a);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTableDirect(
|
||||
::flatbuffers::FlatBufferBuilder64 &_fbb,
|
||||
float a = 0.0f,
|
||||
const std::vector<uint8_t> *b = nullptr,
|
||||
const std::vector<uint8_t> *big_vector = nullptr) {
|
||||
auto big_vector__ = big_vector ? _fbb.CreateVector64(*big_vector) : 0;
|
||||
auto b__ = b ? _fbb.CreateVector<uint8_t>(*b) : 0;
|
||||
return v2::CreateRootTable(
|
||||
_fbb,
|
||||
a,
|
||||
b__,
|
||||
big_vector__);
|
||||
}
|
||||
|
||||
::flatbuffers::Offset<RootTable> CreateRootTable(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
|
||||
inline bool operator==(const RootTableT &lhs, const RootTableT &rhs) {
|
||||
return
|
||||
(lhs.a == rhs.a) &&
|
||||
(lhs.b == rhs.b) &&
|
||||
(lhs.big_vector == rhs.big_vector);
|
||||
}
|
||||
|
||||
inline bool operator!=(const RootTableT &lhs, const RootTableT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline RootTableT *RootTable::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<RootTableT>(new RootTableT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void RootTable::UnPackTo(RootTableT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = a(); _o->a = _e; }
|
||||
{ auto _e = b(); if (_e) { _o->b.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->b.begin()); } }
|
||||
{ auto _e = big_vector(); if (_e) { _o->big_vector.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->big_vector.begin()); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> RootTable::Pack(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateRootTable(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTable(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder64 *__fbb; const RootTableT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _a = _o->a;
|
||||
auto _b = _o->b.size() ? _fbb.CreateVector(_o->b) : 0;
|
||||
auto _big_vector = _o->big_vector.size() ? _fbb.CreateVector64(_o->big_vector) : 0;
|
||||
return v2::CreateRootTable(
|
||||
_fbb,
|
||||
_a,
|
||||
_b,
|
||||
_big_vector);
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *RootTableTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 }
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"a",
|
||||
"b",
|
||||
"big_vector"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 3, type_codes, nullptr, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const v2::RootTable *GetRootTable(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<v2::RootTable>(buf);
|
||||
}
|
||||
|
||||
inline const v2::RootTable *GetSizePrefixedRootTable(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<v2::RootTable,::flatbuffers::uoffset64_t>(buf);
|
||||
}
|
||||
|
||||
inline RootTable *GetMutableRootTable(void *buf) {
|
||||
return ::flatbuffers::GetMutableRoot<RootTable>(buf);
|
||||
}
|
||||
|
||||
inline v2::RootTable *GetMutableSizePrefixedRootTable(void *buf) {
|
||||
return ::flatbuffers::GetMutableSizePrefixedRoot<v2::RootTable,::flatbuffers::uoffset64_t>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyRootTableBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<v2::RootTable>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedRootTableBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<v2::RootTable,::flatbuffers::uoffset64_t>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishRootTableBuffer(
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb,
|
||||
::flatbuffers::Offset<v2::RootTable> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedRootTableBuffer(
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb,
|
||||
::flatbuffers::Offset<v2::RootTable> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
inline std::unique_ptr<v2::RootTableT> UnPackRootTable(
|
||||
const void *buf,
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<v2::RootTableT>(GetRootTable(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
inline std::unique_ptr<v2::RootTableT> UnPackSizePrefixedRootTable(
|
||||
const void *buf,
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<v2::RootTableT>(GetSizePrefixedRootTable(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
} // namespace v2
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_V2_V2_H_
|
||||
@@ -0,0 +1,458 @@
|
||||
#include "offset64_test.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/buffer.h"
|
||||
#include "flatbuffers/flatbuffer_builder.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "tests/64bit/evolution/v1_generated.h"
|
||||
#include "tests/64bit/evolution/v2_generated.h"
|
||||
#include "tests/64bit/test_64bit_generated.h"
|
||||
#include "tests/test_assert.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace tests {
|
||||
|
||||
void Offset64Test() {
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
const size_t far_vector_size = 1LL << 2;
|
||||
// Make a large number if wanting to test a real large buffer.
|
||||
const size_t big_vector_size = 1LL << 2;
|
||||
|
||||
{
|
||||
// First create the vectors that will be copied to the buffer.
|
||||
std::vector<uint8_t> far_data;
|
||||
far_data.resize(far_vector_size);
|
||||
far_data[0] = 4;
|
||||
far_data[far_vector_size - 1] = 2;
|
||||
|
||||
std::vector<uint8_t> big_data;
|
||||
big_data.resize(big_vector_size);
|
||||
big_data[0] = 8;
|
||||
big_data[big_vector_size - 1] = 3;
|
||||
|
||||
// Then serialize all the fields that have 64-bit offsets, as these must be
|
||||
// serialized before any 32-bit fields are added to the buffer.
|
||||
const Offset64<Vector<uint8_t>> far_vector_offset =
|
||||
builder.CreateVector64<Vector>(far_data);
|
||||
|
||||
const Offset64<String> far_string_offset =
|
||||
builder.CreateString<Offset64>("some far string");
|
||||
|
||||
const Offset64<Vector64<uint8_t>> big_vector_offset =
|
||||
builder.CreateVector64(big_data);
|
||||
|
||||
// Now that we are done with the 64-bit fields, we can create and add the
|
||||
// normal fields.
|
||||
const Offset<String> near_string_offset =
|
||||
builder.CreateString("some near string");
|
||||
|
||||
// Finish by building the root table by passing in all the offsets.
|
||||
const Offset<RootTable> root_table_offset =
|
||||
CreateRootTable(builder, far_vector_offset, 0, far_string_offset,
|
||||
big_vector_offset, near_string_offset);
|
||||
|
||||
// Finish the buffer.
|
||||
builder.Finish(root_table_offset);
|
||||
|
||||
Verifier::Options options;
|
||||
// Allow the verifier to verify 64-bit buffers.
|
||||
options.max_size = FLATBUFFERS_MAX_64_BUFFER_SIZE;
|
||||
options.assert = true;
|
||||
|
||||
Verifier verifier(builder.GetBufferPointer(), builder.GetSize(), options);
|
||||
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
}
|
||||
|
||||
{
|
||||
const RootTable *root_table = GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Expect the far vector to be properly sized.
|
||||
TEST_EQ(root_table->far_vector()->size(), far_vector_size);
|
||||
TEST_EQ(root_table->far_vector()->Get(0), 4);
|
||||
TEST_EQ(root_table->far_vector()->Get(far_vector_size - 1), 2);
|
||||
|
||||
TEST_EQ_STR(root_table->far_string()->c_str(), "some far string");
|
||||
|
||||
// Expect the big vector to be properly sized.
|
||||
TEST_EQ(root_table->big_vector()->size(), big_vector_size);
|
||||
TEST_EQ(root_table->big_vector()->Get(0), 8);
|
||||
TEST_EQ(root_table->big_vector()->Get(big_vector_size - 1), 3);
|
||||
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "some near string");
|
||||
}
|
||||
}
|
||||
|
||||
void Offset64SerializedFirst() {
|
||||
FlatBufferBuilder64 fbb;
|
||||
|
||||
// First create the vectors that will be copied to the buffer.
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(64);
|
||||
|
||||
// Then serialize all the fields that have 64-bit offsets, as these must be
|
||||
// serialized before any 32-bit fields are added to the buffer.
|
||||
fbb.CreateVector64(data);
|
||||
|
||||
// TODO(derekbailey): figure out how to test assertions.
|
||||
// Uncommenting this line should fail the test with an assertion.
|
||||
// fbb.CreateString("some near string");
|
||||
|
||||
fbb.CreateVector64(data);
|
||||
}
|
||||
|
||||
void Offset64NestedFlatBuffer() {
|
||||
FlatBufferBuilder64 fbb;
|
||||
|
||||
// First serialize a nested buffer.
|
||||
const Offset<String> near_string_offset =
|
||||
fbb.CreateString("nested: some near string");
|
||||
|
||||
// Finish by building the root table by passing in all the offsets.
|
||||
const Offset<RootTable> root_table_offset =
|
||||
CreateRootTable(fbb, 0, 0, 0, 0, near_string_offset, 0);
|
||||
|
||||
// Finish the buffer.
|
||||
fbb.Finish(root_table_offset);
|
||||
|
||||
// Ensure the buffer is valid.
|
||||
const RootTable *root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "nested: some near string");
|
||||
|
||||
// Copy the data out of the builder.
|
||||
std::vector<uint8_t> nested_data{ fbb.GetBufferPointer(),
|
||||
fbb.GetBufferPointer() + fbb.GetSize() };
|
||||
|
||||
{
|
||||
// Clear so we can reuse the builder.
|
||||
fbb.Clear();
|
||||
|
||||
const Offset64<Vector64<uint8_t>> nested_flatbuffer_offset =
|
||||
fbb.CreateVector64<Vector64>(nested_data);
|
||||
|
||||
// Now that we are done with the 64-bit fields, we can create and add the
|
||||
// normal fields.
|
||||
const Offset<String> near_string_offset =
|
||||
fbb.CreateString("some near string");
|
||||
|
||||
// Finish by building the root table by passing in all the offsets.
|
||||
const Offset<RootTable> root_table_offset = CreateRootTable(
|
||||
fbb, 0, 0, 0, 0, near_string_offset, nested_flatbuffer_offset);
|
||||
|
||||
// Finish the buffer.
|
||||
fbb.Finish(root_table_offset);
|
||||
|
||||
Verifier::Options options;
|
||||
// Allow the verifier to verify 64-bit buffers.
|
||||
options.max_size = FLATBUFFERS_MAX_64_BUFFER_SIZE;
|
||||
options.assert = true;
|
||||
|
||||
Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize(), options);
|
||||
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
}
|
||||
|
||||
{
|
||||
const RootTable *root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
|
||||
// Test that the parent buffer field is ok.
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "some near string");
|
||||
|
||||
// Expect nested buffer to be properly sized.
|
||||
TEST_EQ(root_table->nested_root()->size(), nested_data.size());
|
||||
|
||||
// Expect the direct accessors to the nested buffer work.
|
||||
TEST_EQ_STR(root_table->nested_root_nested_root()->near_string()->c_str(),
|
||||
"nested: some near string");
|
||||
}
|
||||
}
|
||||
|
||||
void Offset64CreateDirect() {
|
||||
FlatBufferBuilder64 fbb;
|
||||
|
||||
// Create a vector of some data
|
||||
std::vector<uint8_t> data{ 0, 1, 2 };
|
||||
|
||||
// Call the "Direct" creation method to ensure that things are added to the
|
||||
// buffer in the correct order, Offset64 first followed by any Offsets.
|
||||
const Offset<RootTable> root_table_offset = CreateRootTableDirect(
|
||||
fbb, &data, 0, "some far string", &data, "some near string");
|
||||
|
||||
// Finish the buffer.
|
||||
fbb.Finish(root_table_offset);
|
||||
|
||||
Verifier::Options options;
|
||||
// Allow the verifier to verify 64-bit buffers.
|
||||
options.max_size = FLATBUFFERS_MAX_64_BUFFER_SIZE;
|
||||
options.assert = true;
|
||||
|
||||
Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize(), options);
|
||||
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
|
||||
// Verify the data.
|
||||
const RootTable *root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
TEST_EQ(root_table->far_vector()->size(), data.size());
|
||||
TEST_EQ(root_table->big_vector()->size(), data.size());
|
||||
TEST_EQ_STR(root_table->far_string()->c_str(), "some far string");
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "some near string");
|
||||
}
|
||||
|
||||
void Offset64Evolution() {
|
||||
// Some common data for the tests.
|
||||
const std::vector<uint8_t> data = { 1, 2, 3, 4 };
|
||||
const std::vector<uint8_t> big_data = { 6, 7, 8, 9, 10 };
|
||||
|
||||
// Built V1 read V2
|
||||
{
|
||||
// Use the 32-bit builder since V1 doesn't have any 64-bit offsets.
|
||||
FlatBufferBuilder builder;
|
||||
|
||||
builder.Finish(v1::CreateRootTableDirect(builder, 1234, &data));
|
||||
|
||||
// Use each version to get a view at the root table.
|
||||
auto v1_root = v1::GetRootTable(builder.GetBufferPointer());
|
||||
auto v2_root = v2::GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Test field equivalents for fields common to V1 and V2.
|
||||
TEST_EQ(v1_root->a(), v2_root->a());
|
||||
|
||||
TEST_EQ(v1_root->b(), v2_root->b());
|
||||
TEST_EQ(v1_root->b()->Get(2), 3);
|
||||
TEST_EQ(v2_root->b()->Get(2), 3);
|
||||
|
||||
// This field is added in V2, so it should be null since V1 couldn't have
|
||||
// written it.
|
||||
TEST_ASSERT(v2_root->big_vector() == nullptr);
|
||||
}
|
||||
|
||||
// Built V2 read V1
|
||||
{
|
||||
// Use the 64-bit builder since V2 has 64-bit offsets.
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
builder.Finish(v2::CreateRootTableDirect(builder, 1234, &data, &big_data));
|
||||
|
||||
// Use each version to get a view at the root table.
|
||||
auto v1_root = v1::GetRootTable(builder.GetBufferPointer());
|
||||
auto v2_root = v2::GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Test field equivalents for fields common to V1 and V2.
|
||||
TEST_EQ(v1_root->a(), v2_root->a());
|
||||
|
||||
TEST_EQ(v1_root->b(), v2_root->b());
|
||||
TEST_EQ(v1_root->b()->Get(2), 3);
|
||||
TEST_EQ(v2_root->b()->Get(2), 3);
|
||||
|
||||
// Test that V2 can read the big vector, which V1 doesn't even have
|
||||
// accessors for (i.e. v1_root->big_vector() doesn't exist).
|
||||
TEST_ASSERT(v2_root->big_vector() != nullptr);
|
||||
TEST_EQ(v2_root->big_vector()->size(), big_data.size());
|
||||
TEST_EQ(v2_root->big_vector()->Get(2), 8);
|
||||
}
|
||||
|
||||
// Built V2 read V1, bigger than max 32-bit buffer sized.
|
||||
// This checks that even a large buffer can still be read by V1.
|
||||
{
|
||||
// Use the 64-bit builder since V2 has 64-bit offsets.
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
std::vector<uint8_t> giant_data;
|
||||
giant_data.resize(1LL << 3);
|
||||
giant_data[2] = 42;
|
||||
|
||||
builder.Finish(
|
||||
v2::CreateRootTableDirect(builder, 1234, &data, &giant_data));
|
||||
|
||||
// Use each version to get a view at the root table.
|
||||
auto v1_root = v1::GetRootTable(builder.GetBufferPointer());
|
||||
auto v2_root = v2::GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Test field equivalents for fields common to V1 and V2.
|
||||
TEST_EQ(v1_root->a(), v2_root->a());
|
||||
|
||||
TEST_EQ(v1_root->b(), v2_root->b());
|
||||
TEST_EQ(v1_root->b()->Get(2), 3);
|
||||
TEST_EQ(v2_root->b()->Get(2), 3);
|
||||
|
||||
// Test that V2 can read the big vector, which V1 doesn't even have
|
||||
// accessors for (i.e. v1_root->big_vector() doesn't exist).
|
||||
TEST_ASSERT(v2_root->big_vector() != nullptr);
|
||||
TEST_EQ(v2_root->big_vector()->size(), giant_data.size());
|
||||
TEST_EQ(v2_root->big_vector()->Get(2), 42);
|
||||
}
|
||||
}
|
||||
|
||||
void Offset64VectorOfStructs() {
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
std::vector<LeafStruct> far_leaves;
|
||||
far_leaves.emplace_back(LeafStruct{ 123, 4.567 });
|
||||
far_leaves.emplace_back(LeafStruct{ 987, 6.543 });
|
||||
|
||||
std::vector<LeafStruct> big_leaves;
|
||||
big_leaves.emplace_back(LeafStruct{ 72, 72.8 });
|
||||
big_leaves.emplace_back(LeafStruct{ 82, 82.8 });
|
||||
big_leaves.emplace_back(LeafStruct{ 92, 92.8 });
|
||||
|
||||
// Add the two vectors of leaf structs.
|
||||
const Offset<RootTable> root_table_offset =
|
||||
CreateRootTableDirect(builder, nullptr, 0, nullptr, nullptr, nullptr,
|
||||
nullptr, &far_leaves, &big_leaves);
|
||||
|
||||
// Finish the buffer.
|
||||
builder.Finish(root_table_offset);
|
||||
|
||||
Verifier::Options options;
|
||||
// Allow the verifier to verify 64-bit buffers.
|
||||
options.max_size = FLATBUFFERS_MAX_64_BUFFER_SIZE;
|
||||
options.assert = true;
|
||||
|
||||
Verifier verifier(builder.GetBufferPointer(), builder.GetSize(), options);
|
||||
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
|
||||
// Verify the data.
|
||||
const RootTable *root_table = GetRootTable(builder.GetBufferPointer());
|
||||
TEST_EQ(root_table->far_struct_vector()->size(), far_leaves.size());
|
||||
TEST_EQ(root_table->far_struct_vector()->Get(0)->a(), 123);
|
||||
TEST_EQ(root_table->far_struct_vector()->Get(0)->b(), 4.567);
|
||||
TEST_EQ(root_table->far_struct_vector()->Get(1)->a(), 987);
|
||||
TEST_EQ(root_table->far_struct_vector()->Get(1)->b(), 6.543);
|
||||
|
||||
TEST_EQ(root_table->big_struct_vector()->size(), big_leaves.size());
|
||||
TEST_EQ(root_table->big_struct_vector()->Get(0)->a(), 72);
|
||||
TEST_EQ(root_table->big_struct_vector()->Get(0)->b(), 72.8);
|
||||
TEST_EQ(root_table->big_struct_vector()->Get(1)->a(), 82);
|
||||
TEST_EQ(root_table->big_struct_vector()->Get(1)->b(), 82.8);
|
||||
TEST_EQ(root_table->big_struct_vector()->Get(2)->a(), 92);
|
||||
TEST_EQ(root_table->big_struct_vector()->Get(2)->b(), 92.8);
|
||||
}
|
||||
|
||||
void Offset64SizePrefix() {
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
// First serialize a nested buffer.
|
||||
const Offset<String> near_string_offset =
|
||||
builder.CreateString("some near string");
|
||||
|
||||
// Finish by building the root table by passing in all the offsets.
|
||||
const Offset<RootTable> root_table_offset =
|
||||
CreateRootTable(builder, 0, 0, 0, 0, near_string_offset, 0);
|
||||
|
||||
// Finish the buffer.
|
||||
FinishSizePrefixedRootTableBuffer(builder, root_table_offset);
|
||||
|
||||
TEST_EQ(GetPrefixedSize<uoffset64_t>(builder.GetBufferPointer()),
|
||||
builder.GetSize() - sizeof(uoffset64_t));
|
||||
|
||||
Verifier::Options options;
|
||||
// Allow the verifier to verify 64-bit buffers.
|
||||
options.max_size = FLATBUFFERS_MAX_64_BUFFER_SIZE;
|
||||
options.assert = true;
|
||||
|
||||
Verifier verifier(builder.GetBufferPointer(), builder.GetSize(), options);
|
||||
|
||||
TEST_EQ(VerifySizePrefixedRootTableBuffer(verifier), true);
|
||||
|
||||
const RootTable *root_table =
|
||||
GetSizePrefixedRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Verify the fields.
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "some near string");
|
||||
}
|
||||
|
||||
void Offset64ManyVectors() {
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
// Setup some data to serialize.
|
||||
std::vector<int8_t> data;
|
||||
data.resize(20);
|
||||
data.front() = 42;
|
||||
data.back() = 18;
|
||||
|
||||
const size_t kNumVectors = 20;
|
||||
|
||||
// First serialize all the 64-bit address vectors. We need to store all the
|
||||
// offsets to later add to a wrapper table. We cannot serialize one vector and
|
||||
// then add it to a table immediately, as it would violate the strict ordering
|
||||
// of putting all 64-bit things at the tail of the buffer.
|
||||
std::array<Offset64<Vector<int8_t>>, kNumVectors> offsets_64bit;
|
||||
for (size_t i = 0; i < kNumVectors; ++i) {
|
||||
offsets_64bit[i] = builder.CreateVector64<Vector>(data);
|
||||
}
|
||||
|
||||
// Create some unrelated, 64-bit offset value for later testing.
|
||||
const Offset64<String> far_string_offset =
|
||||
builder.CreateString<Offset64>("some far string");
|
||||
|
||||
// Now place all the offsets into their own wrapper tables. Again, we have to
|
||||
// store the offsets before we can add them to the root table vector.
|
||||
std::array<Offset<WrapperTable>, kNumVectors> offsets_wrapper;
|
||||
for (size_t i = 0; i < kNumVectors; ++i) {
|
||||
offsets_wrapper[i] = CreateWrapperTable(builder, offsets_64bit[i]);
|
||||
}
|
||||
|
||||
// Now create the 32-bit vector that is stored in the root table.
|
||||
// TODO(derekbailey): the array type wasn't auto deduced, see if that could be
|
||||
// fixed.
|
||||
const Offset<Vector<Offset<WrapperTable>>> many_vectors_offset =
|
||||
builder.CreateVector<Offset<WrapperTable>>(offsets_wrapper);
|
||||
|
||||
// Finish by building using the root table builder, to exercise a different
|
||||
// code path than the other tests.
|
||||
RootTableBuilder root_table_builder(builder);
|
||||
root_table_builder.add_many_vectors(many_vectors_offset);
|
||||
root_table_builder.add_far_string(far_string_offset);
|
||||
const Offset<RootTable> root_table_offset = root_table_builder.Finish();
|
||||
|
||||
// Finish the buffer.
|
||||
FinishRootTableBuffer(builder, root_table_offset);
|
||||
|
||||
Verifier::Options options;
|
||||
// Allow the verifier to verify 64-bit buffers.
|
||||
options.max_size = FLATBUFFERS_MAX_64_BUFFER_SIZE;
|
||||
options.assert = true;
|
||||
|
||||
Verifier verifier(builder.GetBufferPointer(), builder.GetSize(), options);
|
||||
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
|
||||
const RootTable *root_table = GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Verify the fields.
|
||||
TEST_EQ_STR(root_table->far_string()->c_str(), "some far string");
|
||||
TEST_EQ(root_table->many_vectors()->size(), kNumVectors);
|
||||
|
||||
// Spot check one of the vectors.
|
||||
TEST_EQ(root_table->many_vectors()->Get(12)->vector()->size(), 20);
|
||||
TEST_EQ(root_table->many_vectors()->Get(12)->vector()->Get(0), 42);
|
||||
TEST_EQ(root_table->many_vectors()->Get(12)->vector()->Get(19), 18);
|
||||
}
|
||||
|
||||
void Offset64ForceAlign() {
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
// Setup some data to serialize that is less than the force_align size of 32
|
||||
// bytes.
|
||||
std::vector<uint8_t> data{ 1, 2, 3 };
|
||||
|
||||
// Use the CreateDirect which calls the ForceVectorAlign
|
||||
const auto root_table_offset =
|
||||
CreateRootTableDirect(builder, nullptr, 0, nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr, &data);
|
||||
|
||||
// Finish the buffer.
|
||||
FinishRootTableBuffer(builder, root_table_offset);
|
||||
}
|
||||
|
||||
} // namespace tests
|
||||
} // namespace flatbuffers
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef TESTS_64BIT_OFFSET64_TEST_H
|
||||
#define TESTS_64BIT_OFFSET64_TEST_H
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace tests {
|
||||
|
||||
void Offset64Test();
|
||||
void Offset64SerializedFirst();
|
||||
void Offset64NestedFlatBuffer();
|
||||
void Offset64CreateDirect();
|
||||
void Offset64Evolution();
|
||||
void Offset64VectorOfStructs();
|
||||
void Offset64SizePrefix();
|
||||
void Offset64ManyVectors();
|
||||
void Offset64ForceAlign();
|
||||
|
||||
} // namespace tests
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // TESTS_64BIT_OFFSET64_TEST_H
|
||||
@@ -0,0 +1,74 @@
|
||||
// Annotated Flatbuffer Binary
|
||||
//
|
||||
// Schema file: tests/64bit/test_64bit.fbs
|
||||
// Binary file: tests/64bit/test_64bit.bin
|
||||
|
||||
header:
|
||||
+0x00 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: 0x1C | offset to root table `RootTable`
|
||||
|
||||
padding:
|
||||
+0x04 | 00 00 00 00 | uint8_t[4] | .... | padding
|
||||
|
||||
vtable (RootTable):
|
||||
+0x08 | 14 00 | uint16_t | 0x0014 (20) | size of this vtable
|
||||
+0x0A | 34 00 | uint16_t | 0x0034 (52) | size of referring table
|
||||
+0x0C | 04 00 | VOffset16 | 0x0004 (4) | offset to field `far_vector` (id: 0)
|
||||
+0x0E | 10 00 | VOffset16 | 0x0010 (16) | offset to field `a` (id: 1)
|
||||
+0x10 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `far_string` (id: 2)
|
||||
+0x12 | 24 00 | VOffset16 | 0x0024 (36) | offset to field `big_vector` (id: 3)
|
||||
+0x14 | 20 00 | VOffset16 | 0x0020 (32) | offset to field `near_string` (id: 4)
|
||||
+0x16 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `nested_root` (id: 5) <null> (Vector64)
|
||||
+0x18 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `far_struct_vector` (id: 6) <null> (Vector)
|
||||
+0x1A | 2C 00 | VOffset16 | 0x002C (44) | offset to field `big_struct_vector` (id: 7)
|
||||
|
||||
root_table (RootTable):
|
||||
+0x1C | 14 00 00 00 | SOffset32 | 0x00000014 (20) Loc: 0x08 | offset to vtable
|
||||
+0x20 | D0 00 00 00 00 00 00 00 | UOffset64 | 0x00000000000000D0 (208) Loc: 0xF0 | offset to field `far_vector` (vector)
|
||||
+0x28 | 00 00 00 00 | uint8_t[4] | .... | padding
|
||||
+0x2C | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `a` (Int)
|
||||
+0x30 | 8C 00 00 00 00 00 00 00 | UOffset64 | 0x000000000000008C (140) Loc: 0xBC | offset to field `far_string` (string)
|
||||
+0x38 | 00 00 00 00 | uint8_t[4] | .... | padding
|
||||
+0x3C | 40 00 00 00 | UOffset32 | 0x00000040 (64) Loc: 0x7C | offset to field `near_string` (string)
|
||||
+0x40 | 70 00 00 00 00 00 00 00 | UOffset64 | 0x0000000000000070 (112) Loc: 0xB0 | offset to field `big_vector` (vector64)
|
||||
+0x48 | 08 00 00 00 00 00 00 00 | UOffset64 | 0x0000000000000008 (8) Loc: 0x50 | offset to field `big_struct_vector` (vector64)
|
||||
|
||||
vector64 (RootTable.big_struct_vector):
|
||||
+0x50 | 02 00 00 00 00 00 00 00 | uint64_t | 0x0000000000000002 (2) | length of vector (# items)
|
||||
+0x58 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `[0].a` of 'LeafStruct' (Int)
|
||||
<4 regions omitted>
|
||||
+0x70 | 33 33 33 33 33 33 22 40 | double | 0x4022333333333333 (9.1) | struct field `[1].b` of 'LeafStruct' (Double)
|
||||
|
||||
padding:
|
||||
+0x78 | 00 00 00 00 | uint8_t[4] | .... | padding
|
||||
|
||||
string (RootTable.near_string):
|
||||
+0x7C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string
|
||||
+0x80 | 74 68 69 73 20 69 73 20 | char[47] | this is | string literal
|
||||
+0x88 | 61 20 6E 65 61 72 20 73 | | a near s
|
||||
+0x90 | 74 72 69 6E 67 20 77 68 | | tring wh
|
||||
+0x98 | 69 63 68 20 68 61 73 20 | | ich has
|
||||
+0xA0 | 61 20 33 32 2D 62 69 74 | | a 32-bit
|
||||
+0xA8 | 20 6F 66 66 73 65 74 | | offset
|
||||
+0xAF | 00 | char | 0x00 (0) | string terminator
|
||||
|
||||
vector64 (RootTable.big_vector):
|
||||
+0xB0 | 04 00 00 00 00 00 00 00 | uint64_t | 0x0000000000000004 (4) | length of vector (# items)
|
||||
+0xB8 | 05 | uint8_t | 0x05 (5) | value[0]
|
||||
<2 regions omitted>
|
||||
+0xBB | 08 | uint8_t | 0x08 (8) | value[3]
|
||||
|
||||
string (RootTable.far_string):
|
||||
+0xBC | 2E 00 00 00 | uint32_t | 0x0000002E (46) | length of string
|
||||
+0xC0 | 74 68 69 73 20 69 73 20 | char[46] | this is | string literal
|
||||
+0xC8 | 61 20 66 61 72 20 73 74 | | a far st
|
||||
+0xD0 | 72 69 6E 67 20 77 68 69 | | ring whi
|
||||
+0xD8 | 63 68 20 68 61 73 20 61 | | ch has a
|
||||
+0xE0 | 20 36 34 2D 62 69 74 20 | | 64-bit
|
||||
+0xE8 | 6F 66 66 73 65 74 | | offset
|
||||
+0xEE | 00 | char | 0x00 (0) | string terminator
|
||||
|
||||
vector (RootTable.far_vector):
|
||||
+0xF0 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items)
|
||||
+0xF4 | 01 | uint8_t | 0x01 (1) | value[0]
|
||||
+0xF5 | 02 | uint8_t | 0x02 (2) | value[1]
|
||||
+0xF6 | 03 | uint8_t | 0x03 (3) | value[2]
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
struct LeafStruct {
|
||||
a:int;
|
||||
b:double;
|
||||
}
|
||||
|
||||
table WrapperTable {
|
||||
// A normal 32-bit sized vector that could be very far away (64-bit address).
|
||||
vector:[int8] (offset64);
|
||||
}
|
||||
|
||||
table RootTable {
|
||||
// A normal 32-bit sized vector, that could be very far away (64-bit address).
|
||||
far_vector:[ubyte] (offset64);
|
||||
|
||||
// An inplace value just to check that vtable offsets are correct.
|
||||
a:int;
|
||||
|
||||
// A normal 32-bit sized string, that could be very far away (64-bit address).
|
||||
far_string:string (offset64);
|
||||
|
||||
// A big 64-bit sized vector, that could be very far away (64-bit address).
|
||||
big_vector:[ubyte] (vector64);
|
||||
|
||||
// A normal 32-bit sized string that is no far away (32-bit address).
|
||||
near_string:string;
|
||||
|
||||
// A big 64-bit sized vector that is a nested flatbuffers (64-bit address).
|
||||
nested_root:[ubyte] (vector64, nested_flatbuffer: "RootTable");
|
||||
|
||||
// A normal 32-bit size vector of structs, that could be very far away
|
||||
// (64-bit address)
|
||||
far_struct_vector:[LeafStruct] (offset64);
|
||||
|
||||
// A big 64-bit size vector of structs that could be very far away
|
||||
// (64-bit address)
|
||||
big_struct_vector:[LeafStruct] (vector64);
|
||||
|
||||
// A normal 32-bit size vector of tables. Currently 64-bit vectors don't
|
||||
// support tables as it would require serializing a table (32-bit) before the
|
||||
// vector (64-bit), which is not allowed.
|
||||
//
|
||||
// This demonstrates how you could have many vectors in the buffer, by
|
||||
// effectively having a vector of 64-bit vectors. The IDL doesn't support
|
||||
// nested vecotrs (e.g.: [[type]] ), so going through a wrapper table allows
|
||||
// this.
|
||||
many_vectors:[WrapperTable];
|
||||
|
||||
// A vector that has force_align to test that the 32/64 bit region of the
|
||||
// builder is respected.
|
||||
forced_aligned_vector:[ubyte] (vector64, force_align:32);
|
||||
}
|
||||
|
||||
root_type RootTable;
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"far_vector": [1, 2, 3],
|
||||
"a": 1234,
|
||||
"far_string": "this is a far string which has a 64-bit offset",
|
||||
"big_vector": [5, 6, 7, 8],
|
||||
"near_string": "this is a near string which has a 32-bit offset",
|
||||
"big_struct_vector": [
|
||||
{
|
||||
"a": 12,
|
||||
"b": 3.456
|
||||
},
|
||||
{
|
||||
"a": 78,
|
||||
"b": 9.10
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_TEST64BIT_BFBS_H_
|
||||
#define FLATBUFFERS_GENERATED_TEST64BIT_BFBS_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
struct RootTableBinarySchema {
|
||||
static const uint8_t *data() {
|
||||
// Buffer containing the binary schema.
|
||||
static const uint8_t bfbsData[1248] = {
|
||||
0x1C,0x00,0x00,0x00,0x42,0x46,0x42,0x53,0x14,0x00,0x20,0x00,0x04,0x00,0x08,0x00,0x0C,0x00,0x10,0x00,
|
||||
0x14,0x00,0x18,0x00,0x00,0x00,0x1C,0x00,0x14,0x00,0x00,0x00,0x34,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
|
||||
0x20,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x54,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xA4,0x03,0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
|
||||
0x01,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x08,0x00,0x0C,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x00,0x00,
|
||||
0xA0,0x03,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xFD,0xFF,0xFF,0x3C,0x00,0x00,0x00,
|
||||
0x0C,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x84,0x03,0x00,0x00,0x0A,0x00,0x00,0x00,0x60,0x02,0x00,0x00,
|
||||
0xAC,0x00,0x00,0x00,0xC4,0x01,0x00,0x00,0x24,0x02,0x00,0x00,0xF0,0x00,0x00,0x00,0x70,0x02,0x00,0x00,
|
||||
0x20,0x00,0x00,0x00,0x5C,0x00,0x00,0x00,0x7C,0x01,0x00,0x00,0x28,0x01,0x00,0x00,0x09,0x00,0x00,0x00,
|
||||
0x52,0x6F,0x6F,0x74,0x54,0x61,0x62,0x6C,0x65,0x00,0x00,0x00,0x28,0xFE,0xFF,0xFF,0x00,0x00,0x01,0x01,
|
||||
0x09,0x00,0x16,0x00,0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6C,0xFE,0xFF,0xFF,0x00,0x00,0x12,0x04,
|
||||
0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x66,0x6F,0x72,0x63,0x65,0x64,0x5F,0x61,
|
||||
0x6C,0x69,0x67,0x6E,0x65,0x64,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0x00,0xF8,0xFE,0xFF,0xFF,
|
||||
0x00,0x00,0x00,0x01,0x08,0x00,0x14,0x00,0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x78,0xFF,0xFF,0xFF,
|
||||
0x00,0x00,0x0E,0x0F,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x6D,0x61,0x6E,0x79,
|
||||
0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x73,0x00,0x00,0x00,0x00,0xA0,0xFE,0xFF,0xFF,0x00,0x00,0x01,0x01,
|
||||
0x07,0x00,0x12,0x00,0x2C,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x14,0x00,0x06,0x00,0x07,0x00,
|
||||
0x08,0x00,0x00,0x00,0x0C,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x12,0x0F,0x00,0x00,0x00,0x00,
|
||||
0x08,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x62,0x69,0x67,0x5F,0x73,0x74,0x72,0x75,
|
||||
0x63,0x74,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0x00,0xF0,0xFE,0xFF,0xFF,0x00,0x00,0x01,0x01,
|
||||
0x06,0x00,0x10,0x00,0x28,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x06,0x00,0x07,0x00,
|
||||
0x08,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x0E,0x0F,0x00,0x00,0x00,0x00,
|
||||
0x10,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x66,0x61,0x72,0x5F,0x73,0x74,0x72,0x75,0x63,0x74,0x5F,0x76,
|
||||
0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0x00,0x3C,0xFF,0xFF,0xFF,0x00,0x00,0x01,0x01,0x05,0x00,0x0E,0x00,
|
||||
0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x00,0x00,0x12,0x04,0x08,0x00,0x00,0x00,
|
||||
0x01,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x6E,0x65,0x73,0x74,0x65,0x64,0x5F,0x72,0x6F,0x6F,0x74,0x00,
|
||||
0x1C,0x00,0x14,0x00,0x0C,0x00,0x10,0x00,0x08,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x00,0x0C,0x00,
|
||||
0x14,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x90,0xFD,0xFF,0xFF,0x00,0x00,0x00,0x0D,0x01,0x00,0x00,0x00,
|
||||
0x0B,0x00,0x00,0x00,0x6E,0x65,0x61,0x72,0x5F,0x73,0x74,0x72,0x69,0x6E,0x67,0x00,0xBC,0xFF,0xFF,0xFF,
|
||||
0x00,0x00,0x01,0x01,0x03,0x00,0x0A,0x00,0x28,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x10,0x00,
|
||||
0x06,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x12,0x04,
|
||||
0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x62,0x69,0x67,0x5F,0x76,0x65,0x63,0x74,
|
||||
0x6F,0x72,0x00,0x00,0x20,0x00,0x14,0x00,0x0C,0x00,0x10,0x00,0x08,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x20,0x00,0x00,0x00,
|
||||
0x00,0x00,0x01,0x01,0x02,0x00,0x08,0x00,0x14,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x24,0xFE,0xFF,0xFF,
|
||||
0x00,0x00,0x00,0x0D,0x01,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x66,0x61,0x72,0x5F,0x73,0x74,0x72,0x69,
|
||||
0x6E,0x67,0x00,0x00,0xB0,0xFE,0xFF,0xFF,0x01,0x00,0x06,0x00,0x14,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
|
||||
0x50,0xFE,0xFF,0xFF,0x00,0x00,0x00,0x07,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x61,0x00,0x00,0x00,
|
||||
0x90,0xFF,0xFF,0xFF,0x01,0x01,0x04,0x00,0x14,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x70,0xFF,0xFF,0xFF,
|
||||
0x00,0x00,0x0E,0x04,0x01,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x66,0x61,0x72,0x5F,0x76,0x65,0x63,0x74,
|
||||
0x6F,0x72,0x00,0x00,0x14,0x00,0x14,0x00,0x04,0x00,0x08,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x00,0x14,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
|
||||
0xA8,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x57,0x72,0x61,0x70,
|
||||
0x70,0x65,0x72,0x54,0x61,0x62,0x6C,0x65,0x00,0x00,0x00,0x00,0x20,0x00,0x10,0x00,0x08,0x00,0x0C,0x00,
|
||||
0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,
|
||||
0x00,0x00,0x05,0x00,0x20,0x00,0x00,0x00,0x01,0x01,0x04,0x00,0x24,0x00,0x00,0x00,0x14,0x00,0x00,0x00,
|
||||
0x10,0x00,0x0C,0x00,0x06,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x0E,0x03,0x01,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,
|
||||
0x14,0x00,0x1C,0x00,0x08,0x00,0x0C,0x00,0x07,0x00,0x10,0x00,0x14,0x00,0x00,0x00,0x00,0x00,0x18,0x00,
|
||||
0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x38,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
|
||||
0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x2F,0x2F,0x74,0x65,0x73,0x74,0x5F,0x36,
|
||||
0x34,0x62,0x69,0x74,0x2E,0x66,0x62,0x73,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x78,0x00,0x00,0x00,
|
||||
0x20,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x4C,0x65,0x61,0x66,0x53,0x74,0x72,0x75,0x63,0x74,0x00,0x00,
|
||||
0x0C,0x00,0x10,0x00,0x08,0x00,0x0C,0x00,0x04,0x00,0x06,0x00,0x0C,0x00,0x00,0x00,0x01,0x00,0x08,0x00,
|
||||
0x28,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x00,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
|
||||
0x01,0x00,0x00,0x00,0x62,0x00,0x1E,0x00,0x10,0x00,0x08,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x1E,0x00,0x00,0x00,
|
||||
0x00,0x00,0x04,0x00,0x24,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x0C,0x00,0x07,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x01,0x00,0x00,0x00,
|
||||
0x01,0x00,0x00,0x00,0x61,0x00,0x00,0x00
|
||||
};
|
||||
return bfbsData;
|
||||
}
|
||||
static size_t size() {
|
||||
return 1248;
|
||||
}
|
||||
const uint8_t *begin() {
|
||||
return data();
|
||||
}
|
||||
const uint8_t *end() {
|
||||
return data() + size();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_TEST64BIT_BFBS_H_
|
||||
@@ -0,0 +1,653 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_TEST64BIT_H_
|
||||
#define FLATBUFFERS_GENERATED_TEST64BIT_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 25,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
// For access to the binary schema that produced this file.
|
||||
#include "test_64bit_bfbs_generated.h"
|
||||
|
||||
struct LeafStruct;
|
||||
|
||||
struct WrapperTable;
|
||||
struct WrapperTableBuilder;
|
||||
struct WrapperTableT;
|
||||
|
||||
struct RootTable;
|
||||
struct RootTableBuilder;
|
||||
struct RootTableT;
|
||||
|
||||
bool operator==(const LeafStruct &lhs, const LeafStruct &rhs);
|
||||
bool operator!=(const LeafStruct &lhs, const LeafStruct &rhs);
|
||||
bool operator==(const WrapperTableT &lhs, const WrapperTableT &rhs);
|
||||
bool operator!=(const WrapperTableT &lhs, const WrapperTableT &rhs);
|
||||
bool operator==(const RootTableT &lhs, const RootTableT &rhs);
|
||||
bool operator!=(const RootTableT &lhs, const RootTableT &rhs);
|
||||
|
||||
inline const ::flatbuffers::TypeTable *LeafStructTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *WrapperTableTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *RootTableTypeTable();
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) LeafStruct FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
int32_t a_;
|
||||
int32_t padding0__;
|
||||
double b_;
|
||||
|
||||
public:
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return LeafStructTypeTable();
|
||||
}
|
||||
LeafStruct()
|
||||
: a_(0),
|
||||
padding0__(0),
|
||||
b_(0) {
|
||||
(void)padding0__;
|
||||
}
|
||||
LeafStruct(int32_t _a, double _b)
|
||||
: a_(::flatbuffers::EndianScalar(_a)),
|
||||
padding0__(0),
|
||||
b_(::flatbuffers::EndianScalar(_b)) {
|
||||
(void)padding0__;
|
||||
}
|
||||
int32_t a() const {
|
||||
return ::flatbuffers::EndianScalar(a_);
|
||||
}
|
||||
void mutate_a(int32_t _a) {
|
||||
::flatbuffers::WriteScalar(&a_, _a);
|
||||
}
|
||||
double b() const {
|
||||
return ::flatbuffers::EndianScalar(b_);
|
||||
}
|
||||
void mutate_b(double _b) {
|
||||
::flatbuffers::WriteScalar(&b_, _b);
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(LeafStruct, 16);
|
||||
|
||||
inline bool operator==(const LeafStruct &lhs, const LeafStruct &rhs) {
|
||||
return
|
||||
(lhs.a() == rhs.a()) &&
|
||||
(lhs.b() == rhs.b());
|
||||
}
|
||||
|
||||
inline bool operator!=(const LeafStruct &lhs, const LeafStruct &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
struct WrapperTableT : public ::flatbuffers::NativeTable {
|
||||
typedef WrapperTable TableType;
|
||||
std::vector<int8_t> vector{};
|
||||
};
|
||||
|
||||
struct WrapperTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef WrapperTableT NativeTableType;
|
||||
typedef WrapperTableBuilder Builder;
|
||||
typedef RootTableBinarySchema BinarySchema;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return WrapperTableTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VECTOR = 4
|
||||
};
|
||||
const ::flatbuffers::Vector<int8_t> *vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector<int8_t> *>(VT_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector<int8_t> *mutable_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector<int8_t> *>(VT_VECTOR);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset64(verifier, VT_VECTOR) &&
|
||||
verifier.VerifyVector(vector()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
WrapperTableT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(WrapperTableT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<WrapperTable> Pack(::flatbuffers::FlatBufferBuilder64 &_fbb, const WrapperTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
struct WrapperTableBuilder {
|
||||
typedef WrapperTable Table;
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_vector(::flatbuffers::Offset64<::flatbuffers::Vector<int8_t>> vector) {
|
||||
fbb_.AddOffset(WrapperTable::VT_VECTOR, vector);
|
||||
}
|
||||
explicit WrapperTableBuilder(::flatbuffers::FlatBufferBuilder64 &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<WrapperTable> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<WrapperTable>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<WrapperTable> CreateWrapperTable(
|
||||
::flatbuffers::FlatBufferBuilder64 &_fbb,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector<int8_t>> vector = 0) {
|
||||
WrapperTableBuilder builder_(_fbb);
|
||||
builder_.add_vector(vector);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<WrapperTable> CreateWrapperTableDirect(
|
||||
::flatbuffers::FlatBufferBuilder64 &_fbb,
|
||||
const std::vector<int8_t> *vector = nullptr) {
|
||||
auto vector__ = vector ? _fbb.CreateVector64<::flatbuffers::Vector>(*vector) : 0;
|
||||
return CreateWrapperTable(
|
||||
_fbb,
|
||||
vector__);
|
||||
}
|
||||
|
||||
::flatbuffers::Offset<WrapperTable> CreateWrapperTable(::flatbuffers::FlatBufferBuilder64 &_fbb, const WrapperTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
struct RootTableT : public ::flatbuffers::NativeTable {
|
||||
typedef RootTable TableType;
|
||||
std::vector<uint8_t> far_vector{};
|
||||
int32_t a = 0;
|
||||
std::string far_string{};
|
||||
std::vector<uint8_t> big_vector{};
|
||||
std::string near_string{};
|
||||
std::vector<uint8_t> nested_root{};
|
||||
std::vector<LeafStruct> far_struct_vector{};
|
||||
std::vector<LeafStruct> big_struct_vector{};
|
||||
std::vector<std::unique_ptr<WrapperTableT>> many_vectors{};
|
||||
std::vector<uint8_t> forced_aligned_vector{};
|
||||
RootTableT() = default;
|
||||
RootTableT(const RootTableT &o);
|
||||
RootTableT(RootTableT&&) FLATBUFFERS_NOEXCEPT = default;
|
||||
RootTableT &operator=(RootTableT o) FLATBUFFERS_NOEXCEPT;
|
||||
};
|
||||
|
||||
struct RootTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef RootTableT NativeTableType;
|
||||
typedef RootTableBuilder Builder;
|
||||
typedef RootTableBinarySchema BinarySchema;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return RootTableTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_FAR_VECTOR = 4,
|
||||
VT_A = 6,
|
||||
VT_FAR_STRING = 8,
|
||||
VT_BIG_VECTOR = 10,
|
||||
VT_NEAR_STRING = 12,
|
||||
VT_NESTED_ROOT = 14,
|
||||
VT_FAR_STRUCT_VECTOR = 16,
|
||||
VT_BIG_STRUCT_VECTOR = 18,
|
||||
VT_MANY_VECTORS = 20,
|
||||
VT_FORCED_ALIGNED_VECTOR = 22
|
||||
};
|
||||
const ::flatbuffers::Vector<uint8_t> *far_vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector<uint8_t> *>(VT_FAR_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector<uint8_t> *mutable_far_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector<uint8_t> *>(VT_FAR_VECTOR);
|
||||
}
|
||||
int32_t a() const {
|
||||
return GetField<int32_t>(VT_A, 0);
|
||||
}
|
||||
bool mutate_a(int32_t _a = 0) {
|
||||
return SetField<int32_t>(VT_A, _a, 0);
|
||||
}
|
||||
const ::flatbuffers::String *far_string() const {
|
||||
return GetPointer64<const ::flatbuffers::String *>(VT_FAR_STRING);
|
||||
}
|
||||
::flatbuffers::String *mutable_far_string() {
|
||||
return GetPointer64<::flatbuffers::String *>(VT_FAR_STRING);
|
||||
}
|
||||
const ::flatbuffers::Vector64<uint8_t> *big_vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector64<uint8_t> *>(VT_BIG_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector64<uint8_t> *mutable_big_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector64<uint8_t> *>(VT_BIG_VECTOR);
|
||||
}
|
||||
const ::flatbuffers::String *near_string() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NEAR_STRING);
|
||||
}
|
||||
::flatbuffers::String *mutable_near_string() {
|
||||
return GetPointer<::flatbuffers::String *>(VT_NEAR_STRING);
|
||||
}
|
||||
const ::flatbuffers::Vector64<uint8_t> *nested_root() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector64<uint8_t> *>(VT_NESTED_ROOT);
|
||||
}
|
||||
::flatbuffers::Vector64<uint8_t> *mutable_nested_root() {
|
||||
return GetPointer64<::flatbuffers::Vector64<uint8_t> *>(VT_NESTED_ROOT);
|
||||
}
|
||||
const RootTable *nested_root_nested_root() const {
|
||||
const auto _f = nested_root();
|
||||
return _f ? ::flatbuffers::GetRoot<RootTable>(_f->Data())
|
||||
: nullptr;
|
||||
}
|
||||
const ::flatbuffers::Vector<const LeafStruct *> *far_struct_vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector<const LeafStruct *> *>(VT_FAR_STRUCT_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector<const LeafStruct *> *mutable_far_struct_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector<const LeafStruct *> *>(VT_FAR_STRUCT_VECTOR);
|
||||
}
|
||||
const ::flatbuffers::Vector64<const LeafStruct *> *big_struct_vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector64<const LeafStruct *> *>(VT_BIG_STRUCT_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector64<const LeafStruct *> *mutable_big_struct_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector64<const LeafStruct *> *>(VT_BIG_STRUCT_VECTOR);
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<WrapperTable>> *many_vectors() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<WrapperTable>> *>(VT_MANY_VECTORS);
|
||||
}
|
||||
::flatbuffers::Vector<::flatbuffers::Offset<WrapperTable>> *mutable_many_vectors() {
|
||||
return GetPointer<::flatbuffers::Vector<::flatbuffers::Offset<WrapperTable>> *>(VT_MANY_VECTORS);
|
||||
}
|
||||
const ::flatbuffers::Vector64<uint8_t> *forced_aligned_vector() const {
|
||||
return GetPointer64<const ::flatbuffers::Vector64<uint8_t> *>(VT_FORCED_ALIGNED_VECTOR);
|
||||
}
|
||||
::flatbuffers::Vector64<uint8_t> *mutable_forced_aligned_vector() {
|
||||
return GetPointer64<::flatbuffers::Vector64<uint8_t> *>(VT_FORCED_ALIGNED_VECTOR);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset64(verifier, VT_FAR_VECTOR) &&
|
||||
verifier.VerifyVector(far_vector()) &&
|
||||
VerifyField<int32_t>(verifier, VT_A, 4) &&
|
||||
VerifyOffset64(verifier, VT_FAR_STRING) &&
|
||||
verifier.VerifyString(far_string()) &&
|
||||
VerifyOffset64(verifier, VT_BIG_VECTOR) &&
|
||||
verifier.VerifyVector(big_vector()) &&
|
||||
VerifyOffset(verifier, VT_NEAR_STRING) &&
|
||||
verifier.VerifyString(near_string()) &&
|
||||
VerifyOffset64(verifier, VT_NESTED_ROOT) &&
|
||||
verifier.VerifyVector(nested_root()) &&
|
||||
verifier.VerifyNestedFlatBuffer<RootTable>(nested_root(), nullptr) &&
|
||||
VerifyOffset64(verifier, VT_FAR_STRUCT_VECTOR) &&
|
||||
verifier.VerifyVector(far_struct_vector()) &&
|
||||
VerifyOffset64(verifier, VT_BIG_STRUCT_VECTOR) &&
|
||||
verifier.VerifyVector(big_struct_vector()) &&
|
||||
VerifyOffset(verifier, VT_MANY_VECTORS) &&
|
||||
verifier.VerifyVector(many_vectors()) &&
|
||||
verifier.VerifyVectorOfTables(many_vectors()) &&
|
||||
VerifyOffset64(verifier, VT_FORCED_ALIGNED_VECTOR) &&
|
||||
verifier.VerifyVector(forced_aligned_vector()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
RootTableT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(RootTableT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<RootTable> Pack(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
struct RootTableBuilder {
|
||||
typedef RootTable Table;
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_far_vector(::flatbuffers::Offset64<::flatbuffers::Vector<uint8_t>> far_vector) {
|
||||
fbb_.AddOffset(RootTable::VT_FAR_VECTOR, far_vector);
|
||||
}
|
||||
void add_a(int32_t a) {
|
||||
fbb_.AddElement<int32_t>(RootTable::VT_A, a, 0);
|
||||
}
|
||||
void add_far_string(::flatbuffers::Offset64<::flatbuffers::String> far_string) {
|
||||
fbb_.AddOffset(RootTable::VT_FAR_STRING, far_string);
|
||||
}
|
||||
void add_big_vector(::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> big_vector) {
|
||||
fbb_.AddOffset(RootTable::VT_BIG_VECTOR, big_vector);
|
||||
}
|
||||
void add_near_string(::flatbuffers::Offset<::flatbuffers::String> near_string) {
|
||||
fbb_.AddOffset(RootTable::VT_NEAR_STRING, near_string);
|
||||
}
|
||||
void add_nested_root(::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> nested_root) {
|
||||
fbb_.AddOffset(RootTable::VT_NESTED_ROOT, nested_root);
|
||||
}
|
||||
void add_far_struct_vector(::flatbuffers::Offset64<::flatbuffers::Vector<const LeafStruct *>> far_struct_vector) {
|
||||
fbb_.AddOffset(RootTable::VT_FAR_STRUCT_VECTOR, far_struct_vector);
|
||||
}
|
||||
void add_big_struct_vector(::flatbuffers::Offset64<::flatbuffers::Vector64<const LeafStruct *>> big_struct_vector) {
|
||||
fbb_.AddOffset(RootTable::VT_BIG_STRUCT_VECTOR, big_struct_vector);
|
||||
}
|
||||
void add_many_vectors(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<WrapperTable>>> many_vectors) {
|
||||
fbb_.AddOffset(RootTable::VT_MANY_VECTORS, many_vectors);
|
||||
}
|
||||
void add_forced_aligned_vector(::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> forced_aligned_vector) {
|
||||
fbb_.AddOffset(RootTable::VT_FORCED_ALIGNED_VECTOR, forced_aligned_vector);
|
||||
}
|
||||
explicit RootTableBuilder(::flatbuffers::FlatBufferBuilder64 &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RootTable> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RootTable>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTable(
|
||||
::flatbuffers::FlatBufferBuilder64 &_fbb,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector<uint8_t>> far_vector = 0,
|
||||
int32_t a = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::String> far_string = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> big_vector = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::String> near_string = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> nested_root = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector<const LeafStruct *>> far_struct_vector = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector64<const LeafStruct *>> big_struct_vector = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<WrapperTable>>> many_vectors = 0,
|
||||
::flatbuffers::Offset64<::flatbuffers::Vector64<uint8_t>> forced_aligned_vector = 0) {
|
||||
RootTableBuilder builder_(_fbb);
|
||||
builder_.add_forced_aligned_vector(forced_aligned_vector);
|
||||
builder_.add_big_struct_vector(big_struct_vector);
|
||||
builder_.add_nested_root(nested_root);
|
||||
builder_.add_big_vector(big_vector);
|
||||
builder_.add_many_vectors(many_vectors);
|
||||
builder_.add_far_struct_vector(far_struct_vector);
|
||||
builder_.add_near_string(near_string);
|
||||
builder_.add_far_string(far_string);
|
||||
builder_.add_a(a);
|
||||
builder_.add_far_vector(far_vector);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTableDirect(
|
||||
::flatbuffers::FlatBufferBuilder64 &_fbb,
|
||||
const std::vector<uint8_t> *far_vector = nullptr,
|
||||
int32_t a = 0,
|
||||
const char *far_string = nullptr,
|
||||
const std::vector<uint8_t> *big_vector = nullptr,
|
||||
const char *near_string = nullptr,
|
||||
const std::vector<uint8_t> *nested_root = nullptr,
|
||||
const std::vector<LeafStruct> *far_struct_vector = nullptr,
|
||||
const std::vector<LeafStruct> *big_struct_vector = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<WrapperTable>> *many_vectors = nullptr,
|
||||
const std::vector<uint8_t> *forced_aligned_vector = nullptr) {
|
||||
auto far_vector__ = far_vector ? _fbb.CreateVector64<::flatbuffers::Vector>(*far_vector) : 0;
|
||||
auto far_string__ = far_string ? _fbb.CreateString<::flatbuffers::Offset64>(far_string) : 0;
|
||||
auto big_vector__ = big_vector ? _fbb.CreateVector64(*big_vector) : 0;
|
||||
auto nested_root__ = nested_root ? _fbb.CreateVector64(*nested_root) : 0;
|
||||
auto far_struct_vector__ = far_struct_vector ? _fbb.CreateVectorOfStructs64<::flatbuffers::Vector>(*far_struct_vector) : 0;
|
||||
auto big_struct_vector__ = big_struct_vector ? _fbb.CreateVectorOfStructs64(*big_struct_vector) : 0;
|
||||
if (forced_aligned_vector) { _fbb.ForceVectorAlignment64(forced_aligned_vector->size(), sizeof(uint8_t), 32); }
|
||||
auto forced_aligned_vector__ = forced_aligned_vector ? _fbb.CreateVector64(*forced_aligned_vector) : 0;
|
||||
auto near_string__ = near_string ? _fbb.CreateString(near_string) : 0;
|
||||
auto many_vectors__ = many_vectors ? _fbb.CreateVector<::flatbuffers::Offset<WrapperTable>>(*many_vectors) : 0;
|
||||
return CreateRootTable(
|
||||
_fbb,
|
||||
far_vector__,
|
||||
a,
|
||||
far_string__,
|
||||
big_vector__,
|
||||
near_string__,
|
||||
nested_root__,
|
||||
far_struct_vector__,
|
||||
big_struct_vector__,
|
||||
many_vectors__,
|
||||
forced_aligned_vector__);
|
||||
}
|
||||
|
||||
::flatbuffers::Offset<RootTable> CreateRootTable(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
|
||||
inline bool operator==(const WrapperTableT &lhs, const WrapperTableT &rhs) {
|
||||
return
|
||||
(lhs.vector == rhs.vector);
|
||||
}
|
||||
|
||||
inline bool operator!=(const WrapperTableT &lhs, const WrapperTableT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline WrapperTableT *WrapperTable::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<WrapperTableT>(new WrapperTableT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void WrapperTable::UnPackTo(WrapperTableT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = vector(); if (_e) { _o->vector.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->vector.begin()); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<WrapperTable> WrapperTable::Pack(::flatbuffers::FlatBufferBuilder64 &_fbb, const WrapperTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateWrapperTable(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<WrapperTable> CreateWrapperTable(::flatbuffers::FlatBufferBuilder64 &_fbb, const WrapperTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder64 *__fbb; const WrapperTableT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _vector = _o->vector.size() ? _fbb.CreateVector64<::flatbuffers::Vector>(_o->vector) : 0;
|
||||
return CreateWrapperTable(
|
||||
_fbb,
|
||||
_vector);
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==(const RootTableT &lhs, const RootTableT &rhs) {
|
||||
return
|
||||
(lhs.far_vector == rhs.far_vector) &&
|
||||
(lhs.a == rhs.a) &&
|
||||
(lhs.far_string == rhs.far_string) &&
|
||||
(lhs.big_vector == rhs.big_vector) &&
|
||||
(lhs.near_string == rhs.near_string) &&
|
||||
(lhs.nested_root == rhs.nested_root) &&
|
||||
(lhs.far_struct_vector == rhs.far_struct_vector) &&
|
||||
(lhs.big_struct_vector == rhs.big_struct_vector) &&
|
||||
(lhs.many_vectors.size() == rhs.many_vectors.size() && std::equal(lhs.many_vectors.cbegin(), lhs.many_vectors.cend(), rhs.many_vectors.cbegin(), [](std::unique_ptr<WrapperTableT> const &a, std::unique_ptr<WrapperTableT> const &b) { return (a == b) || (a && b && *a == *b); })) &&
|
||||
(lhs.forced_aligned_vector == rhs.forced_aligned_vector);
|
||||
}
|
||||
|
||||
inline bool operator!=(const RootTableT &lhs, const RootTableT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline RootTableT::RootTableT(const RootTableT &o)
|
||||
: far_vector(o.far_vector),
|
||||
a(o.a),
|
||||
far_string(o.far_string),
|
||||
big_vector(o.big_vector),
|
||||
near_string(o.near_string),
|
||||
nested_root(o.nested_root),
|
||||
far_struct_vector(o.far_struct_vector),
|
||||
big_struct_vector(o.big_struct_vector),
|
||||
forced_aligned_vector(o.forced_aligned_vector) {
|
||||
many_vectors.reserve(o.many_vectors.size());
|
||||
for (const auto &many_vectors_ : o.many_vectors) { many_vectors.emplace_back((many_vectors_) ? new WrapperTableT(*many_vectors_) : nullptr); }
|
||||
}
|
||||
|
||||
inline RootTableT &RootTableT::operator=(RootTableT o) FLATBUFFERS_NOEXCEPT {
|
||||
std::swap(far_vector, o.far_vector);
|
||||
std::swap(a, o.a);
|
||||
std::swap(far_string, o.far_string);
|
||||
std::swap(big_vector, o.big_vector);
|
||||
std::swap(near_string, o.near_string);
|
||||
std::swap(nested_root, o.nested_root);
|
||||
std::swap(far_struct_vector, o.far_struct_vector);
|
||||
std::swap(big_struct_vector, o.big_struct_vector);
|
||||
std::swap(many_vectors, o.many_vectors);
|
||||
std::swap(forced_aligned_vector, o.forced_aligned_vector);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline RootTableT *RootTable::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<RootTableT>(new RootTableT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void RootTable::UnPackTo(RootTableT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = far_vector(); if (_e) { _o->far_vector.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->far_vector.begin()); } }
|
||||
{ auto _e = a(); _o->a = _e; }
|
||||
{ auto _e = far_string(); if (_e) _o->far_string = _e->str(); }
|
||||
{ auto _e = big_vector(); if (_e) { _o->big_vector.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->big_vector.begin()); } }
|
||||
{ auto _e = near_string(); if (_e) _o->near_string = _e->str(); }
|
||||
{ auto _e = nested_root(); if (_e) { _o->nested_root.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->nested_root.begin()); } }
|
||||
{ auto _e = far_struct_vector(); if (_e) { _o->far_struct_vector.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->far_struct_vector[_i] = *_e->Get(_i); } } else { _o->far_struct_vector.resize(0); } }
|
||||
{ auto _e = big_struct_vector(); if (_e) { _o->big_struct_vector.resize(_e->size()); for (::flatbuffers::uoffset64_t _i = 0; _i < _e->size(); _i++) { _o->big_struct_vector[_i] = *_e->Get(_i); } } else { _o->big_struct_vector.resize(0); } }
|
||||
{ auto _e = many_vectors(); if (_e) { _o->many_vectors.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->many_vectors[_i]) { _e->Get(_i)->UnPackTo(_o->many_vectors[_i].get(), _resolver); } else { _o->many_vectors[_i] = std::unique_ptr<WrapperTableT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->many_vectors.resize(0); } }
|
||||
{ auto _e = forced_aligned_vector(); if (_e) { _o->forced_aligned_vector.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->forced_aligned_vector.begin()); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> RootTable::Pack(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateRootTable(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RootTable> CreateRootTable(::flatbuffers::FlatBufferBuilder64 &_fbb, const RootTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder64 *__fbb; const RootTableT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _far_vector = _o->far_vector.size() ? _fbb.CreateVector64<::flatbuffers::Vector>(_o->far_vector) : 0;
|
||||
auto _a = _o->a;
|
||||
auto _far_string = _o->far_string.empty() ? 0 : _fbb.CreateString<::flatbuffers::Offset64>(_o->far_string);
|
||||
auto _big_vector = _o->big_vector.size() ? _fbb.CreateVector64(_o->big_vector) : 0;
|
||||
auto _near_string = _o->near_string.empty() ? 0 : _fbb.CreateString(_o->near_string);
|
||||
auto _nested_root = _o->nested_root.size() ? _fbb.CreateVector64(_o->nested_root) : 0;
|
||||
auto _far_struct_vector = _o->far_struct_vector.size() ? _fbb.CreateVectorOfStructs64<::flatbuffers::Vector>(_o->far_struct_vector) : 0;
|
||||
auto _big_struct_vector = _o->big_struct_vector.size() ? _fbb.CreateVectorOfStructs64(_o->big_struct_vector) : 0;
|
||||
auto _many_vectors = _o->many_vectors.size() ? _fbb.CreateVector<::flatbuffers::Offset<WrapperTable>> (_o->many_vectors.size(), [](size_t i, _VectorArgs *__va) { return CreateWrapperTable(*__va->__fbb, __va->__o->many_vectors[i].get(), __va->__rehasher); }, &_va ) : 0;
|
||||
_fbb.ForceVectorAlignment64(_o->forced_aligned_vector.size(), sizeof(uint8_t), 32);
|
||||
auto _forced_aligned_vector = _o->forced_aligned_vector.size() ? _fbb.CreateVector64(_o->forced_aligned_vector) : 0;
|
||||
return CreateRootTable(
|
||||
_fbb,
|
||||
_far_vector,
|
||||
_a,
|
||||
_far_string,
|
||||
_big_vector,
|
||||
_near_string,
|
||||
_nested_root,
|
||||
_far_struct_vector,
|
||||
_big_struct_vector,
|
||||
_many_vectors,
|
||||
_forced_aligned_vector);
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *LeafStructTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_INT, 0, -1 },
|
||||
{ ::flatbuffers::ET_DOUBLE, 0, -1 }
|
||||
};
|
||||
static const int64_t values[] = { 0, 8, 16 };
|
||||
static const char * const names[] = {
|
||||
"a",
|
||||
"b"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_STRUCT, 2, type_codes, nullptr, nullptr, values, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *WrapperTableTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 1, -1 }
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"vector"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 1, type_codes, nullptr, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *RootTableTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ ::flatbuffers::ET_INT, 0, -1 },
|
||||
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
LeafStructTypeTable,
|
||||
WrapperTableTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"far_vector",
|
||||
"a",
|
||||
"far_string",
|
||||
"big_vector",
|
||||
"near_string",
|
||||
"nested_root",
|
||||
"far_struct_vector",
|
||||
"big_struct_vector",
|
||||
"many_vectors",
|
||||
"forced_aligned_vector"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 10, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const RootTable *GetRootTable(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<RootTable>(buf);
|
||||
}
|
||||
|
||||
inline const RootTable *GetSizePrefixedRootTable(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<RootTable,::flatbuffers::uoffset64_t>(buf);
|
||||
}
|
||||
|
||||
inline RootTable *GetMutableRootTable(void *buf) {
|
||||
return ::flatbuffers::GetMutableRoot<RootTable>(buf);
|
||||
}
|
||||
|
||||
inline RootTable *GetMutableSizePrefixedRootTable(void *buf) {
|
||||
return ::flatbuffers::GetMutableSizePrefixedRoot<RootTable,::flatbuffers::uoffset64_t>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyRootTableBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<RootTable>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedRootTableBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<RootTable,::flatbuffers::uoffset64_t>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishRootTableBuffer(
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb,
|
||||
::flatbuffers::Offset<RootTable> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedRootTableBuffer(
|
||||
::flatbuffers::FlatBufferBuilder64 &fbb,
|
||||
::flatbuffers::Offset<RootTable> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
inline std::unique_ptr<RootTableT> UnPackRootTable(
|
||||
const void *buf,
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<RootTableT>(GetRootTable(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
inline std::unique_ptr<RootTableT> UnPackSizePrefixedRootTable(
|
||||
const void *buf,
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<RootTableT>(GetSizePrefixedRootTable(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_TEST64BIT_H_
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
#[ Abc
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by :
|
||||
]#
|
||||
|
||||
type Abc*{.pure.} = enum
|
||||
A = 0.int32,
|
||||
B = 1.int32,
|
||||
C = 2.int32,
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
||||
load("//:build_defs.bzl", "DEFAULT_FLATC_ARGS", "flatbuffer_cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:private"])
|
||||
|
||||
# rules_js works around various JS tooling limitations by copying everything
|
||||
# into the output directory. Make the test data available to the tests this way.
|
||||
copy_to_bin(
|
||||
name = "test_data_copied_to_bin",
|
||||
srcs = glob([
|
||||
"*.mon",
|
||||
"*.json",
|
||||
]),
|
||||
visibility = ["//tests/ts:__subpackages__"],
|
||||
)
|
||||
|
||||
# Test binary.
|
||||
cc_test(
|
||||
name = "flatbuffers_test",
|
||||
testonly = 1,
|
||||
srcs = [
|
||||
"64bit/evolution/v1_generated.h",
|
||||
"64bit/evolution/v2_generated.h",
|
||||
"64bit/offset64_test.cpp",
|
||||
"64bit/offset64_test.h",
|
||||
"64bit/test_64bit_bfbs_generated.h",
|
||||
"64bit/test_64bit_generated.h",
|
||||
"alignment_test.cpp",
|
||||
"alignment_test.h",
|
||||
"alignment_test_generated.h",
|
||||
"evolution_test.cpp",
|
||||
"evolution_test.h",
|
||||
"evolution_test/evolution_v1_generated.h",
|
||||
"evolution_test/evolution_v2_generated.h",
|
||||
"flexbuffers_test.cpp",
|
||||
"flexbuffers_test.h",
|
||||
"fuzz_test.cpp",
|
||||
"fuzz_test.h",
|
||||
"is_quiet_nan.h",
|
||||
"json_test.cpp",
|
||||
"json_test.h",
|
||||
"key_field/key_field_sample_generated.h",
|
||||
"key_field_test.cpp",
|
||||
"key_field_test.h",
|
||||
"monster_test.cpp",
|
||||
"monster_test.h",
|
||||
"monster_test_bfbs_generated.h",
|
||||
"namespace_test/namespace_test1_generated.h",
|
||||
"namespace_test/namespace_test2_generated.h",
|
||||
"native_inline_table_test_generated.h",
|
||||
"native_type_test_impl.cpp",
|
||||
"native_type_test_impl.h",
|
||||
"optional_scalars_generated.h",
|
||||
"optional_scalars_test.cpp",
|
||||
"optional_scalars_test.h",
|
||||
"parser_test.cpp",
|
||||
"parser_test.h",
|
||||
"proto_test.cpp",
|
||||
"proto_test.h",
|
||||
"reflection_test.cpp",
|
||||
"reflection_test.h",
|
||||
"test.cpp",
|
||||
"test_assert.cpp",
|
||||
"test_assert.h",
|
||||
"test_builder.cpp",
|
||||
"test_builder.h",
|
||||
"union_underlying_type_test_generated.h",
|
||||
"union_vector/union_vector_generated.h",
|
||||
"util_test.cpp",
|
||||
"util_test.h",
|
||||
],
|
||||
copts = [
|
||||
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
|
||||
],
|
||||
data = [
|
||||
":alignment_test.fbs",
|
||||
":arrays_test.bfbs",
|
||||
":arrays_test.fbs",
|
||||
":arrays_test.golden",
|
||||
":evolution_test/evolution_v1.fbs",
|
||||
":evolution_test/evolution_v1.json",
|
||||
":evolution_test/evolution_v2.fbs",
|
||||
":evolution_test/evolution_v2.json",
|
||||
":include_test/include_test1.fbs",
|
||||
":include_test/sub/include_test2.fbs",
|
||||
":key_field/key_field_sample.fbs",
|
||||
":monster_extra.fbs",
|
||||
":monster_test.bfbs",
|
||||
":monster_test.fbs",
|
||||
":monsterdata_extra.json",
|
||||
":monsterdata_test.golden",
|
||||
":monsterdata_test.json",
|
||||
":name_clash_test/invalid_test1.fbs",
|
||||
":name_clash_test/invalid_test2.fbs",
|
||||
":name_clash_test/valid_test1.fbs",
|
||||
":name_clash_test/valid_test2.fbs",
|
||||
":native_type_test.fbs",
|
||||
":optional_scalars.fbs",
|
||||
":optional_scalars.json",
|
||||
":optional_scalars_defaults.json",
|
||||
":prototest/imported.proto",
|
||||
":prototest/non-positive-id.proto",
|
||||
":prototest/test.golden.fbs",
|
||||
":prototest/test.proto",
|
||||
":prototest/test_id.golden.fbs",
|
||||
":prototest/test_include.golden.fbs",
|
||||
":prototest/test_include_id.golden.fbs",
|
||||
":prototest/test_suffix.golden.fbs",
|
||||
":prototest/test_suffix_id.golden.fbs",
|
||||
":prototest/test_union.golden.fbs",
|
||||
":prototest/test_union_id.golden.fbs",
|
||||
":prototest/test_union_include.golden.fbs",
|
||||
":prototest/test_union_include_id.golden.fbs",
|
||||
":prototest/test_union_suffix.golden.fbs",
|
||||
":prototest/test_union_suffix_id.golden.fbs",
|
||||
":prototest/twice-id.proto",
|
||||
":prototest/use-reserved-id.proto",
|
||||
":unicode_test.json",
|
||||
":union_vector/union_vector.fbs",
|
||||
":union_vector/union_vector.json",
|
||||
],
|
||||
includes = [
|
||||
"",
|
||||
"include/",
|
||||
],
|
||||
deps = [
|
||||
":alignment_test_cc_fbs",
|
||||
":arrays_test_cc_fbs",
|
||||
":monster_extra_cc_fbs",
|
||||
":monster_test_cc_fbs",
|
||||
":native_type_test_cc_fbs",
|
||||
"//:flatbuffers",
|
||||
"//src:generate_fbs",
|
||||
],
|
||||
)
|
||||
|
||||
# Test bzl rules
|
||||
|
||||
cc_library(
|
||||
name = "test_assert",
|
||||
srcs = ["test_assert.cpp"],
|
||||
hdrs = ["test_assert.h"],
|
||||
visibility = ["//grpc/tests:__subpackages__"],
|
||||
deps = ["//:flatbuffers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "test_builder",
|
||||
srcs = ["test_builder.cpp"],
|
||||
hdrs = ["test_builder.h"],
|
||||
visibility = ["//grpc/tests:__subpackages__"],
|
||||
deps = [
|
||||
":monster_test_grpc",
|
||||
":test_assert",
|
||||
"//:flatbuffers",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "monster_test_grpc",
|
||||
srcs = [
|
||||
"monster_test.grpc.fb.cc",
|
||||
"monster_test.grpc.fb.h",
|
||||
"monster_test_generated.h",
|
||||
],
|
||||
hdrs = [
|
||||
"monster_test.grpc.fb.h",
|
||||
"monster_test_bfbs_generated.h",
|
||||
"monster_test_generated.h",
|
||||
],
|
||||
includes = ["."],
|
||||
visibility = ["//grpc/tests:__subpackages__"],
|
||||
deps = [
|
||||
"//:flatbuffers",
|
||||
"@com_github_grpc_grpc//:grpc++",
|
||||
],
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "include_test_fbs",
|
||||
srcs = [
|
||||
"include_test/include_test1.fbs",
|
||||
"include_test/sub/include_test2.fbs",
|
||||
],
|
||||
include_paths = ["tests/include_test"],
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "monster_test_cc_fbs",
|
||||
srcs = ["monster_test.fbs"],
|
||||
outs = ["monster_test_bfbs_generated.h"],
|
||||
flatc_args = DEFAULT_FLATC_ARGS + [
|
||||
"--bfbs-comments",
|
||||
"--bfbs-builtins",
|
||||
"--bfbs-gen-embed",
|
||||
"--bfbs-filenames tests",
|
||||
],
|
||||
include_paths = ["tests/include_test"],
|
||||
visibility = ["//grpc/tests:__subpackages__"],
|
||||
deps = [":include_test_fbs"],
|
||||
)
|
||||
|
||||
# Test that running without --no-includes works properly (monster_test doesn't
|
||||
# work cleanly due to the circular dependency in the include_tests/ files).
|
||||
include_test_args = [
|
||||
"--gen-object-api",
|
||||
"--gen-compare",
|
||||
"--gen-mutable",
|
||||
"--reflect-names",
|
||||
"--cpp-ptr-type flatbuffers::unique_ptr",
|
||||
"--force-empty",
|
||||
]
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "included_test_fbs",
|
||||
srcs = ["included_test.fbs"],
|
||||
flatc_args = include_test_args,
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "includer_test_fbs",
|
||||
srcs = ["includer_test.fbs"],
|
||||
flatc_args = include_test_args,
|
||||
deps = [":included_test_fbs"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "include_build_test",
|
||||
srcs = ["include_build_test.cc"],
|
||||
deps = [":includer_test_fbs"],
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "monster_extra_cc_fbs",
|
||||
srcs = ["monster_extra.fbs"],
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "arrays_test_cc_fbs",
|
||||
srcs = ["arrays_test.fbs"],
|
||||
flatc_args = [
|
||||
"--gen-object-api",
|
||||
"--gen-compare",
|
||||
"--no-includes",
|
||||
"--gen-mutable",
|
||||
"--reflect-names",
|
||||
"--cpp-ptr-type flatbuffers::unique_ptr",
|
||||
"--scoped-enums",
|
||||
],
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "native_type_test_cc_fbs",
|
||||
srcs = ["native_type_test.fbs"],
|
||||
flatc_args = [
|
||||
"--gen-object-api",
|
||||
"--gen-mutable",
|
||||
"--cpp-ptr-type flatbuffers::unique_ptr",
|
||||
],
|
||||
)
|
||||
|
||||
flatbuffer_cc_library(
|
||||
name = "alignment_test_cc_fbs",
|
||||
srcs = ["alignment_test.fbs"],
|
||||
)
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright 2016 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
pushd "$(dirname $0)" >/dev/null
|
||||
|
||||
command -v dart >/dev/null 2>&1 || { echo >&2 "Dart tests require dart to be in path but it's not installed. Aborting."; exit 1; }
|
||||
# output required files to the dart folder so that pub will be able to
|
||||
# distribute them and more people can more easily run the dart tests
|
||||
../flatc --dart --gen-object-api -I include_test -o ../dart/test monster_test.fbs
|
||||
../flatc --dart --gen-object-api -I include_test/sub -o ../dart/test include_test/include_test1.fbs
|
||||
../flatc --dart --gen-object-api -I include_test -o ../dart/test include_test/sub/include_test2.fbs
|
||||
|
||||
cp monsterdata_test.mon ../dart/test
|
||||
cp monster_test.fbs ../dart/test
|
||||
|
||||
cd ../dart
|
||||
|
||||
../flatc --dart --gen-object-api -o ./test ./test/list_of_enums.fbs
|
||||
../flatc --dart --gen-object-api -o ./test ./test/bool_structs.fbs
|
||||
|
||||
# update packages
|
||||
dart pub get
|
||||
# Execute the sample.
|
||||
dart test
|
||||
@@ -0,0 +1,87 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package DictionaryLookup;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class LongFloatEntry extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); }
|
||||
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb) { return getRootAsLongFloatEntry(_bb, new LongFloatEntry()); }
|
||||
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb, LongFloatEntry obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public LongFloatEntry __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public long key() { int o = __offset(4); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
|
||||
public float value() { int o = __offset(6); return o != 0 ? bb.getFloat(o + bb_pos) : 0.0f; }
|
||||
|
||||
public static int createLongFloatEntry(FlatBufferBuilder builder,
|
||||
long key,
|
||||
float value) {
|
||||
builder.startTable(2);
|
||||
LongFloatEntry.addKey(builder, key);
|
||||
LongFloatEntry.addValue(builder, value);
|
||||
return LongFloatEntry.endLongFloatEntry(builder);
|
||||
}
|
||||
|
||||
public static void startLongFloatEntry(FlatBufferBuilder builder) { builder.startTable(2); }
|
||||
public static void addKey(FlatBufferBuilder builder, long key) { builder.addLong(key); builder.slot(0); }
|
||||
public static void addValue(FlatBufferBuilder builder, float value) { builder.addFloat(1, value, 0.0f); }
|
||||
public static int endLongFloatEntry(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) {
|
||||
long val_1 = _bb.getLong(__offset(4, o1, _bb));
|
||||
long val_2 = _bb.getLong(__offset(4, o2, _bb));
|
||||
return val_1 > val_2 ? 1 : val_1 < val_2 ? -1 : 0;
|
||||
}
|
||||
|
||||
public static LongFloatEntry __lookup_by_key(LongFloatEntry obj, int vectorLocation, long key, ByteBuffer bb) {
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
long val = bb.getLong(__offset(4, bb.capacity() - tableOffset, bb));
|
||||
int comp = val > key ? 1 : val < key ? -1 : 0;
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new LongFloatEntry() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public LongFloatEntry get(int j) { return get(new LongFloatEntry(), j); }
|
||||
public LongFloatEntry get(LongFloatEntry obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public LongFloatEntry getByKey(long key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public LongFloatEntry getByKey(LongFloatEntry obj, long key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package DictionaryLookup
|
||||
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
|
||||
@Suppress("unused")
|
||||
class LongFloatEntry : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
}
|
||||
fun __assign(_i: Int, _bb: ByteBuffer) : LongFloatEntry {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
}
|
||||
val key : Long
|
||||
get() {
|
||||
val o = __offset(4)
|
||||
return if(o != 0) bb.getLong(o + bb_pos) else 0L
|
||||
}
|
||||
val value : Float
|
||||
get() {
|
||||
val o = __offset(6)
|
||||
return if(o != 0) bb.getFloat(o + bb_pos) else 0.0f
|
||||
}
|
||||
override fun keysCompare(o1: Int, o2: Int, _bb: ByteBuffer) : Int {
|
||||
val val_1 = _bb.getLong(__offset(4, o1, _bb))
|
||||
val val_2 = _bb.getLong(__offset(4, o2, _bb))
|
||||
return (val_1 - val_2).sign
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_25()
|
||||
fun getRootAsLongFloatEntry(_bb: ByteBuffer): LongFloatEntry = getRootAsLongFloatEntry(_bb, LongFloatEntry())
|
||||
fun getRootAsLongFloatEntry(_bb: ByteBuffer, obj: LongFloatEntry): LongFloatEntry {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun createLongFloatEntry(builder: FlatBufferBuilder, key: Long, value: Float) : Int {
|
||||
builder.startTable(2)
|
||||
addKey(builder, key)
|
||||
addValue(builder, value)
|
||||
return endLongFloatEntry(builder)
|
||||
}
|
||||
fun startLongFloatEntry(builder: FlatBufferBuilder) = builder.startTable(2)
|
||||
fun addKey(builder: FlatBufferBuilder, key: Long) {
|
||||
builder.addLong(key)
|
||||
builder.slot(0)
|
||||
}
|
||||
fun addValue(builder: FlatBufferBuilder, value: Float) = builder.addFloat(1, value, 0.0)
|
||||
fun endLongFloatEntry(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
}
|
||||
fun __lookup_by_key(obj: LongFloatEntry?, vectorLocation: Int, key: Long, bb: ByteBuffer) : LongFloatEntry? {
|
||||
var span = bb.getInt(vectorLocation - 4)
|
||||
var start = 0
|
||||
while (span != 0) {
|
||||
var middle = span / 2
|
||||
val tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb)
|
||||
val value = bb.getLong(__offset(4, bb.capacity() - tableOffset, bb))
|
||||
val comp = value.compareTo(key)
|
||||
when {
|
||||
comp > 0 -> span = middle
|
||||
comp < 0 -> {
|
||||
middle++
|
||||
start += middle
|
||||
span -= middle
|
||||
}
|
||||
else -> {
|
||||
return (obj ?: LongFloatEntry()).__assign(tableOffset, bb)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package DictionaryLookup;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class LongFloatMap extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); }
|
||||
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb) { return getRootAsLongFloatMap(_bb, new LongFloatMap()); }
|
||||
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb, LongFloatMap obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public LongFloatMap __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public DictionaryLookup.LongFloatEntry entries(int j) { return entries(new DictionaryLookup.LongFloatEntry(), j); }
|
||||
public DictionaryLookup.LongFloatEntry entries(DictionaryLookup.LongFloatEntry obj, int j) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int entriesLength() { int o = __offset(4); return o != 0 ? __vector_len(o) : 0; }
|
||||
public DictionaryLookup.LongFloatEntry entriesByKey(long key) { int o = __offset(4); return o != 0 ? DictionaryLookup.LongFloatEntry.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public DictionaryLookup.LongFloatEntry entriesByKey(DictionaryLookup.LongFloatEntry obj, long key) { int o = __offset(4); return o != 0 ? DictionaryLookup.LongFloatEntry.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public DictionaryLookup.LongFloatEntry.Vector entriesVector() { return entriesVector(new DictionaryLookup.LongFloatEntry.Vector()); }
|
||||
public DictionaryLookup.LongFloatEntry.Vector entriesVector(DictionaryLookup.LongFloatEntry.Vector obj) { int o = __offset(4); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createLongFloatMap(FlatBufferBuilder builder,
|
||||
int entriesOffset) {
|
||||
builder.startTable(1);
|
||||
LongFloatMap.addEntries(builder, entriesOffset);
|
||||
return LongFloatMap.endLongFloatMap(builder);
|
||||
}
|
||||
|
||||
public static void startLongFloatMap(FlatBufferBuilder builder) { builder.startTable(1); }
|
||||
public static void addEntries(FlatBufferBuilder builder, int entriesOffset) { builder.addOffset(0, entriesOffset, 0); }
|
||||
public static int createEntriesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startEntriesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static int endLongFloatMap(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
public static void finishLongFloatMapBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset); }
|
||||
public static void finishSizePrefixedLongFloatMapBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset); }
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public LongFloatMap get(int j) { return get(new LongFloatMap(), j); }
|
||||
public LongFloatMap get(LongFloatMap obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package DictionaryLookup
|
||||
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
|
||||
@Suppress("unused")
|
||||
class LongFloatMap : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
}
|
||||
fun __assign(_i: Int, _bb: ByteBuffer) : LongFloatMap {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
}
|
||||
fun entries(j: Int) : DictionaryLookup.LongFloatEntry? = entries(DictionaryLookup.LongFloatEntry(), j)
|
||||
fun entries(obj: DictionaryLookup.LongFloatEntry, j: Int) : DictionaryLookup.LongFloatEntry? {
|
||||
val o = __offset(4)
|
||||
return if (o != 0) {
|
||||
obj.__assign(__indirect(__vector(o) + j * 4), bb)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val entriesLength : Int
|
||||
get() {
|
||||
val o = __offset(4); return if (o != 0) __vector_len(o) else 0
|
||||
}
|
||||
fun entriesByKey(key: Long) : DictionaryLookup.LongFloatEntry? {
|
||||
val o = __offset(4)
|
||||
return if (o != 0) {
|
||||
DictionaryLookup.LongFloatEntry.__lookup_by_key(null, __vector(o), key, bb)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
fun entriesByKey(obj: DictionaryLookup.LongFloatEntry, key: Long) : DictionaryLookup.LongFloatEntry? {
|
||||
val o = __offset(4)
|
||||
return if (o != 0) {
|
||||
DictionaryLookup.LongFloatEntry.__lookup_by_key(obj, __vector(o), key, bb)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_25()
|
||||
fun getRootAsLongFloatMap(_bb: ByteBuffer): LongFloatMap = getRootAsLongFloatMap(_bb, LongFloatMap())
|
||||
fun getRootAsLongFloatMap(_bb: ByteBuffer, obj: LongFloatMap): LongFloatMap {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun createLongFloatMap(builder: FlatBufferBuilder, entriesOffset: Int) : Int {
|
||||
builder.startTable(1)
|
||||
addEntries(builder, entriesOffset)
|
||||
return endLongFloatMap(builder)
|
||||
}
|
||||
fun startLongFloatMap(builder: FlatBufferBuilder) = builder.startTable(1)
|
||||
fun addEntries(builder: FlatBufferBuilder, entries: Int) = builder.addOffset(0, entries, 0)
|
||||
fun createEntriesVector(builder: FlatBufferBuilder, data: IntArray) : Int {
|
||||
builder.startVector(4, data.size, 4)
|
||||
for (i in data.size - 1 downTo 0) {
|
||||
builder.addOffset(data[i])
|
||||
}
|
||||
return builder.endVector()
|
||||
}
|
||||
fun startEntriesVector(builder: FlatBufferBuilder, numElems: Int) = builder.startVector(4, numElems, 4)
|
||||
fun endLongFloatMap(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
}
|
||||
fun finishLongFloatMapBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
||||
fun finishSizePrefixedLongFloatMapBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finishSizePrefixed(offset)
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using MyGame.Example;
|
||||
|
||||
namespace Google.FlatBuffers.Benchmarks
|
||||
{
|
||||
//[EtwProfiler] - needs elevated privileges
|
||||
[MemoryDiagnoser]
|
||||
public class FlatBufferBuilderBenchmark
|
||||
{
|
||||
private const int NumberOfRows = 10_000;
|
||||
|
||||
[Benchmark]
|
||||
public void BuildNestedMonster()
|
||||
{
|
||||
const string nestedMonsterName = "NestedMonsterName";
|
||||
const short nestedMonsterHp = 600;
|
||||
const short nestedMonsterMana = 1024;
|
||||
|
||||
for (int i = 0; i < NumberOfRows; i++)
|
||||
{
|
||||
// Create nested buffer as a Monster type
|
||||
var fbb1 = new FlatBufferBuilder(16);
|
||||
var str1 = fbb1.CreateString(nestedMonsterName);
|
||||
Monster.StartMonster(fbb1);
|
||||
Monster.AddName(fbb1, str1);
|
||||
Monster.AddHp(fbb1, nestedMonsterHp);
|
||||
Monster.AddMana(fbb1, nestedMonsterMana);
|
||||
var monster1 = Monster.EndMonster(fbb1);
|
||||
Monster.FinishMonsterBuffer(fbb1, monster1);
|
||||
var fbb1Bytes = fbb1.SizedByteArray();
|
||||
fbb1 = null;
|
||||
|
||||
// Create a Monster which has the first buffer as a nested buffer
|
||||
var fbb2 = new FlatBufferBuilder(16);
|
||||
var str2 = fbb2.CreateString("My Monster");
|
||||
var nestedBuffer = Monster.CreateTestnestedflatbufferVector(fbb2, fbb1Bytes);
|
||||
Monster.StartMonster(fbb2);
|
||||
Monster.AddName(fbb2, str2);
|
||||
Monster.AddHp(fbb2, 50);
|
||||
Monster.AddMana(fbb2, 32);
|
||||
Monster.AddTestnestedflatbuffer(fbb2, nestedBuffer);
|
||||
var monster = Monster.EndMonster(fbb2);
|
||||
Monster.FinishMonsterBuffer(fbb2, monster);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void BuildMonster()
|
||||
{
|
||||
for (int i = 0; i < NumberOfRows; i++)
|
||||
{
|
||||
var builder = new FlatBufferBuilder(16);
|
||||
var str1 = builder.CreateString("MonsterName");
|
||||
Monster.StartMonster(builder);
|
||||
Monster.AddName(builder, str1);
|
||||
Monster.AddHp(builder, 600);
|
||||
Monster.AddMana(builder, 1024);
|
||||
Monster.AddColor(builder, Color.Blue);
|
||||
Monster.AddTestbool(builder, true);
|
||||
Monster.AddTestf(builder, 0.3f);
|
||||
Monster.AddTestf2(builder, 0.2f);
|
||||
Monster.AddTestf3(builder, 0.1f);
|
||||
|
||||
var monster1 = Monster.EndMonster(builder);
|
||||
Monster.FinishMonsterBuffer(builder, monster1);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TestTables()
|
||||
{
|
||||
FlatBufferBuilder builder = new FlatBufferBuilder(1024 * 1024 * 32);
|
||||
for (int x = 0; x < 500000; ++x)
|
||||
{
|
||||
var offset = builder.CreateString("T");
|
||||
builder.StartObject(4);
|
||||
builder.AddDouble(3.2);
|
||||
builder.AddDouble(4.2);
|
||||
builder.AddDouble(5.2);
|
||||
builder.AddOffset(offset.Value);
|
||||
builder.EndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants>$(DefineConstants);UNSAFE_BYTEBUFFER;BYTEBUFFER_NO_BOUNDS_CHECK;ENABLE_SPAN_T</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.11.3" />
|
||||
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.11.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\net\FlatBuffers\*.cs" Link="FlatBuffers\%(FileName).cs" />
|
||||
<Compile Include="..\MyGame\**\*.cs" Link="MyGame\Example\%(FileName).cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
namespace Google.FlatBuffers.Benchmarks
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BenchmarkSwitcher
|
||||
.FromAssembly(typeof(Program).Assembly)
|
||||
.Run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
dotnet-install.sh
|
||||
.dotnet_tmp/
|
||||
.tmp/
|
||||
packages/
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
|
||||
public class AssertFailedException : Exception
|
||||
{
|
||||
private readonly object _expected;
|
||||
private readonly object _actual;
|
||||
|
||||
public AssertFailedException(object expected, object actual)
|
||||
{
|
||||
_expected = expected;
|
||||
_actual = actual;
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get { return string.Format("Expected {0} but saw {1}", _expected, _actual); }
|
||||
}
|
||||
}
|
||||
|
||||
public class AssertArrayFailedException : Exception
|
||||
{
|
||||
private readonly int _index;
|
||||
private readonly object _expected;
|
||||
private readonly object _actual;
|
||||
|
||||
public AssertArrayFailedException(int index, object expected, object actual)
|
||||
{
|
||||
_index = index;
|
||||
_expected = expected;
|
||||
_actual = actual;
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get { return string.Format("Expected {0} at index {1} but saw {2}", _expected, _index, _actual); }
|
||||
}
|
||||
}
|
||||
|
||||
public class AssertUnexpectedThrowException : Exception
|
||||
{
|
||||
private readonly object _expected;
|
||||
|
||||
public AssertUnexpectedThrowException(object expected)
|
||||
{
|
||||
_expected = expected;
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get { return string.Format("Expected exception of type {0}", _expected); }
|
||||
}
|
||||
}
|
||||
|
||||
public static class Assert
|
||||
{
|
||||
public static void AreEqual<T>(T expected, T actual)
|
||||
{
|
||||
if (!expected.Equals(actual))
|
||||
{
|
||||
throw new AssertFailedException(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ArrayEqual<T>(T[] expected, T[] actual)
|
||||
{
|
||||
if (expected.Length != actual.Length)
|
||||
{
|
||||
throw new AssertFailedException(expected, actual);
|
||||
}
|
||||
|
||||
for(var i = 0; i < expected.Length; ++i)
|
||||
{
|
||||
if (!expected[i].Equals(actual[i]))
|
||||
{
|
||||
throw new AssertArrayFailedException(i, expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ArrayEqual<T>(ArraySegment<T> expected, T[] actual)
|
||||
{
|
||||
#if NETCOREAPP
|
||||
ArrayEqual(expected.ToArray(), actual);
|
||||
#else
|
||||
if (expected.Count != actual.Length)
|
||||
{
|
||||
throw new AssertFailedException(expected, actual);
|
||||
}
|
||||
|
||||
for (var i = 0; i < expected.Count; ++i)
|
||||
{
|
||||
if (!expected.Array[expected.Offset + i].Equals(actual[i]))
|
||||
{
|
||||
throw new AssertArrayFailedException(i, expected, actual);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void IsTrue(bool value)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
throw new AssertFailedException(true, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IsFalse(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
throw new AssertFailedException(false, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Throws<T>(Action action) where T : Exception
|
||||
{
|
||||
var caught = false;
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (T)
|
||||
{
|
||||
caught = true;
|
||||
}
|
||||
|
||||
if (!caught)
|
||||
{
|
||||
throw new AssertUnexpectedThrowException(typeof (T));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,742 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
[FlatBuffersTestClass]
|
||||
public class ByteBufferTests
|
||||
{
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Length_MatchesBufferLength()
|
||||
{
|
||||
var buffer = new byte[1000];
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.AreEqual(buffer.Length, uut.Length);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutBytePopulatesBufferAtZeroOffset()
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var uut = new ByteBuffer(buffer);
|
||||
uut.PutByte(0, (byte)99);
|
||||
|
||||
Assert.AreEqual((byte)99, buffer[0]);
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutByteCannotPutAtOffsetPastLength()
|
||||
{
|
||||
var uut = new ByteBuffer(1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutByte(1, 99));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutShortPopulatesBufferCorrectly()
|
||||
{
|
||||
var buffer = new byte[2];
|
||||
var uut = new ByteBuffer(buffer);
|
||||
uut.PutShort(0, (short)1);
|
||||
|
||||
// Ensure Endianness was written correctly
|
||||
Assert.AreEqual((byte)1, buffer[0]);
|
||||
Assert.AreEqual((byte)0, buffer[1]);
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutShortCannotPutAtOffsetPastLength()
|
||||
{
|
||||
var uut = new ByteBuffer(2);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutShort(2, 99));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutShortChecksLength()
|
||||
{
|
||||
var uut = new ByteBuffer(1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutShort(0, 99));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutShortChecksLengthAndOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(2);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutShort(1, 99));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutIntPopulatesBufferCorrectly()
|
||||
{
|
||||
var buffer = new byte[4];
|
||||
var uut = new ByteBuffer(buffer);
|
||||
uut.PutInt(0, 0x0A0B0C0D);
|
||||
|
||||
// Ensure Endianness was written correctly
|
||||
Assert.AreEqual(0x0D, buffer[0]);
|
||||
Assert.AreEqual(0x0C, buffer[1]);
|
||||
Assert.AreEqual(0x0B, buffer[2]);
|
||||
Assert.AreEqual(0x0A, buffer[3]);
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutIntCannotPutAtOffsetPastLength()
|
||||
{
|
||||
var uut = new ByteBuffer(4);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutInt(2, 0x0A0B0C0D));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutIntChecksLength()
|
||||
{
|
||||
var uut = new ByteBuffer(1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutInt(0, 0x0A0B0C0D));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutIntChecksLengthAndOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(4);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutInt(2, 0x0A0B0C0D));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutLongPopulatesBufferCorrectly()
|
||||
{
|
||||
var buffer = new byte[8];
|
||||
var uut = new ByteBuffer(buffer);
|
||||
uut.PutLong(0, 0x010203040A0B0C0D);
|
||||
|
||||
// Ensure Endianness was written correctly
|
||||
Assert.AreEqual(0x0D, buffer[0]);
|
||||
Assert.AreEqual(0x0C, buffer[1]);
|
||||
Assert.AreEqual(0x0B, buffer[2]);
|
||||
Assert.AreEqual(0x0A, buffer[3]);
|
||||
Assert.AreEqual(0x04, buffer[4]);
|
||||
Assert.AreEqual(0x03, buffer[5]);
|
||||
Assert.AreEqual(0x02, buffer[6]);
|
||||
Assert.AreEqual(0x01, buffer[7]);
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutLongCannotPutAtOffsetPastLength()
|
||||
{
|
||||
var uut = new ByteBuffer(8);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutLong(2, 0x010203040A0B0C0D));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutLongChecksLength()
|
||||
{
|
||||
var uut = new ByteBuffer(1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutLong(0, 0x010203040A0B0C0D));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_PutLongChecksLengthAndOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(8);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutLong(2, 0x010203040A0B0C0D));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetByteReturnsCorrectData()
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
buffer[0] = 99;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.AreEqual((byte)99, uut.Get(0));
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetByteChecksOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.Get(1));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetShortReturnsCorrectData()
|
||||
{
|
||||
var buffer = new byte[2];
|
||||
buffer[0] = 1;
|
||||
buffer[1] = 0;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.AreEqual(1, uut.GetShort(0));
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetShortChecksOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(2);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetShort(2));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetShortChecksLength()
|
||||
{
|
||||
var uut = new ByteBuffer(2);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetShort(1));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetIntReturnsCorrectData()
|
||||
{
|
||||
var buffer = new byte[4];
|
||||
buffer[0] = 0x0D;
|
||||
buffer[1] = 0x0C;
|
||||
buffer[2] = 0x0B;
|
||||
buffer[3] = 0x0A;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.AreEqual(0x0A0B0C0D, uut.GetInt(0));
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetIntChecksOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(4);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetInt(4));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetIntChecksLength()
|
||||
{
|
||||
var uut = new ByteBuffer(2);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetInt(0));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetLongReturnsCorrectData()
|
||||
{
|
||||
var buffer = new byte[8];
|
||||
buffer[0] = 0x0D;
|
||||
buffer[1] = 0x0C;
|
||||
buffer[2] = 0x0B;
|
||||
buffer[3] = 0x0A;
|
||||
buffer[4] = 0x04;
|
||||
buffer[5] = 0x03;
|
||||
buffer[6] = 0x02;
|
||||
buffer[7] = 0x01;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.AreEqual(0x010203040A0B0C0D, uut.GetLong(0));
|
||||
}
|
||||
|
||||
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetLongChecksOffset()
|
||||
{
|
||||
var uut = new ByteBuffer(8);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetLong(8));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_GetLongChecksLength()
|
||||
{
|
||||
var uut = new ByteBuffer(7);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetLong(0));
|
||||
}
|
||||
#endif
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_ReverseBytesUshort()
|
||||
{
|
||||
const ushort original = (ushort)0x1234U;
|
||||
var reverse = ByteBuffer.ReverseBytes(original);
|
||||
Assert.AreEqual(0x3412U, reverse);
|
||||
|
||||
var rereverse = ByteBuffer.ReverseBytes(reverse);
|
||||
Assert.AreEqual(original, rereverse);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_ReverseBytesUint()
|
||||
{
|
||||
const uint original = 0x12345678;
|
||||
var reverse = ByteBuffer.ReverseBytes(original);
|
||||
Assert.AreEqual(0x78563412U, reverse);
|
||||
|
||||
var rereverse = ByteBuffer.ReverseBytes(reverse);
|
||||
Assert.AreEqual(original, rereverse);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_ReverseBytesUlong()
|
||||
{
|
||||
const ulong original = 0x1234567890ABCDEFUL;
|
||||
var reverse = ByteBuffer.ReverseBytes(original);
|
||||
Assert.AreEqual(0xEFCDAB9078563412UL, reverse);
|
||||
|
||||
var rereverse = ByteBuffer.ReverseBytes(reverse);
|
||||
Assert.AreEqual(original, rereverse);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_ToFullArray_MatchesBuffer()
|
||||
{
|
||||
var buffer = new byte[4];
|
||||
buffer[0] = 0x0D;
|
||||
buffer[1] = 0x0C;
|
||||
buffer[2] = 0x0B;
|
||||
buffer[3] = 0x0A;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.ArrayEqual(buffer, uut.ToFullArray());
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_ToSizedArray_MatchesBuffer()
|
||||
{
|
||||
var buffer = new byte[4];
|
||||
buffer[0] = 0x0D;
|
||||
buffer[1] = 0x0C;
|
||||
buffer[2] = 0x0B;
|
||||
buffer[3] = 0x0A;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.ArrayEqual(buffer, uut.ToFullArray());
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Duplicate_MatchesBuffer()
|
||||
{
|
||||
var buffer = new byte[4];
|
||||
buffer[0] = 0x0D;
|
||||
buffer[1] = 0x0C;
|
||||
buffer[2] = 0x0B;
|
||||
buffer[3] = 0x0A;
|
||||
var uut = new ByteBuffer(buffer);
|
||||
Assert.AreEqual(0x0A0B0C0D, uut.GetInt(0));
|
||||
|
||||
// Advance by two bytes
|
||||
uut.Position = 2; uut = uut.Duplicate();
|
||||
Assert.AreEqual(0x0A0B, uut.GetShort(2));
|
||||
|
||||
// Advance by one more byte
|
||||
uut.Position = 1; uut = uut.Duplicate();
|
||||
Assert.AreEqual(0x0A, uut.Get(3));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_To_Array_Float()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var fData = new float[len];
|
||||
fData[0] = 1.0079F;
|
||||
fData[1] = 4.0026F;
|
||||
fData[2] = 6.941F;
|
||||
fData[3] = 9.0122F;
|
||||
fData[4] = 10.811F;
|
||||
fData[5] = 12.0107F;
|
||||
fData[6] = 14.0067F;
|
||||
fData[7] = 15.9994F;
|
||||
fData[8] = 18.9984F;
|
||||
|
||||
// Tranfer it to a byte array
|
||||
var buffer = new byte[sizeof(float) * fData.Length];
|
||||
Buffer.BlockCopy(fData, 0, buffer, 0, buffer.Length);
|
||||
|
||||
// Create the Byte Buffer from byte array
|
||||
var uut = new ByteBuffer(buffer);
|
||||
|
||||
// Get the full array back out and ensure they are equivalent
|
||||
var bbArray = uut.ToArray<float>(0, len);
|
||||
Assert.ArrayEqual(fData, bbArray);
|
||||
|
||||
// Get a portion of the full array back out and ensure the
|
||||
// subrange agrees
|
||||
var bbArray2 = uut.ToArray<float>(4, len - 1);
|
||||
Assert.AreEqual(bbArray2.Length, len - 1);
|
||||
for (int i = 1; i < len - 1; i++)
|
||||
{
|
||||
Assert.AreEqual(fData[i], bbArray2[i - 1]);
|
||||
}
|
||||
|
||||
// Get a sub portion of the full array back out and ensure the
|
||||
// subrange agrees
|
||||
var bbArray3 = uut.ToArray<float>(8, len - 4);
|
||||
Assert.AreEqual(bbArray3.Length, len - 4);
|
||||
for (int i = 2; i < len - 4; i++)
|
||||
{
|
||||
Assert.AreEqual(fData[i], bbArray3[i - 2]);
|
||||
}
|
||||
}
|
||||
|
||||
public void ByteBuffer_Put_Array_Helper<T>(T[] data, int typeSize)
|
||||
where T : struct
|
||||
{
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// Put the data into the buffer and make sure the offset is
|
||||
// calculated correctly
|
||||
int nOffset = uut.Put(1024, data);
|
||||
Assert.AreEqual(1024 - typeSize * data.Length, nOffset);
|
||||
|
||||
// Get the full array back out and ensure they are equivalent
|
||||
var bbArray = uut.ToArray<T>(nOffset, data.Length);
|
||||
Assert.ArrayEqual(data, bbArray);
|
||||
}
|
||||
|
||||
public void ByteBuffer_Put_ArraySegment_Helper<T>(ArraySegment<T> data, int typeSize)
|
||||
where T : struct
|
||||
{
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// Put the data into the buffer and make sure the offset is
|
||||
// calculated correctly
|
||||
int nOffset = uut.Put(1024, data);
|
||||
Assert.AreEqual(1024 - typeSize * data.Count, nOffset);
|
||||
|
||||
// Get the full array back out and ensure they are equivalent
|
||||
var bbArray = uut.ToArray<T>(nOffset, data.Count);
|
||||
Assert.ArrayEqual(data, bbArray);
|
||||
}
|
||||
|
||||
public unsafe void ByteBuffer_Put_IntPtr_Helper<T>(T[] data, int typeSize)
|
||||
where T : struct
|
||||
{
|
||||
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
try
|
||||
{
|
||||
var dataPtr = handle.AddrOfPinnedObject();
|
||||
var sizeInBytes = data.Length * typeSize;
|
||||
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// Put the data into the buffer and make sure the offset is
|
||||
// calculated correctly
|
||||
int nOffset = uut.Put<T>(1024, dataPtr, sizeInBytes);
|
||||
Assert.AreEqual(1024 - sizeInBytes, nOffset);
|
||||
|
||||
// Get the full array back out and ensure they are equivalent
|
||||
var bbArray = uut.ToArray<T>(nOffset, data.Length);
|
||||
Assert.ArrayEqual(data, bbArray);
|
||||
}
|
||||
finally
|
||||
{
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public void ByteBuffer_Put_ArrayTypes_Helper<T>(T[] data, int typeSize)
|
||||
where T : struct
|
||||
{
|
||||
ByteBuffer_Put_Array_Helper(data, typeSize);
|
||||
|
||||
var arraySegment = CreateArraySegment(data);
|
||||
ByteBuffer_Put_ArraySegment_Helper(arraySegment, typeSize);
|
||||
|
||||
ByteBuffer_Put_IntPtr_Helper(data, typeSize);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Float()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new float[len];
|
||||
data[0] = 1.0079F;
|
||||
data[1] = 4.0026F;
|
||||
data[2] = 6.941F;
|
||||
data[3] = 9.0122F;
|
||||
data[4] = 10.811F;
|
||||
data[5] = 12.0107F;
|
||||
data[6] = 14.0067F;
|
||||
data[7] = 15.9994F;
|
||||
data[8] = 18.9984F;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(float));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Double()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new double[len];
|
||||
data[0] = 1.0079;
|
||||
data[1] = 4.0026;
|
||||
data[2] = 6.941;
|
||||
data[3] = 9.0122;
|
||||
data[4] = 10.811;
|
||||
data[5] = 12.0107;
|
||||
data[6] = 14.0067;
|
||||
data[7] = 15.9994;
|
||||
data[8] = 18.9984;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(double));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Int()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new int[len];
|
||||
data[0] = 1;
|
||||
data[1] = 4;
|
||||
data[2] = 6;
|
||||
data[3] = 9;
|
||||
data[4] = 10;
|
||||
data[5] = 12;
|
||||
data[6] = 14;
|
||||
data[7] = 15;
|
||||
data[8] = 18;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(int));
|
||||
}
|
||||
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_UInt()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new uint[len];
|
||||
data[0] = 1;
|
||||
data[1] = 4;
|
||||
data[2] = 6;
|
||||
data[3] = 9;
|
||||
data[4] = 10;
|
||||
data[5] = 12;
|
||||
data[6] = 14;
|
||||
data[7] = 15;
|
||||
data[8] = 18;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(uint));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Bool()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new bool[len];
|
||||
data[0] = true;
|
||||
data[1] = true;
|
||||
data[2] = false;
|
||||
data[3] = true;
|
||||
data[4] = false;
|
||||
data[5] = true;
|
||||
data[6] = true;
|
||||
data[7] = true;
|
||||
data[8] = false;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(bool));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Long()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new long[len];
|
||||
data[0] = 1;
|
||||
data[1] = 4;
|
||||
data[2] = 6;
|
||||
data[3] = 9;
|
||||
data[4] = 10;
|
||||
data[5] = 12;
|
||||
data[6] = 14;
|
||||
data[7] = 15;
|
||||
data[8] = 18;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(long));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Byte()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new byte[len];
|
||||
data[0] = 1;
|
||||
data[1] = 4;
|
||||
data[2] = 6;
|
||||
data[3] = 9;
|
||||
data[4] = 10;
|
||||
data[5] = 12;
|
||||
data[6] = 14;
|
||||
data[7] = 15;
|
||||
data[8] = 18;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(byte));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_SByte()
|
||||
{
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new sbyte[len];
|
||||
data[0] = 1;
|
||||
data[1] = 4;
|
||||
data[2] = 6;
|
||||
data[3] = 9;
|
||||
data[4] = 10;
|
||||
data[5] = 12;
|
||||
data[6] = 14;
|
||||
data[7] = 15;
|
||||
data[8] = 18;
|
||||
|
||||
ByteBuffer_Put_ArrayTypes_Helper(data, sizeof(sbyte));
|
||||
}
|
||||
|
||||
private static ArraySegment<T> CreateArraySegment<T>(T[] data)
|
||||
where T : struct
|
||||
{
|
||||
const int arraySegmentPadding = 7;
|
||||
var newData = new T[data.Length + 2 * arraySegmentPadding];
|
||||
Array.Copy(data, 0, newData, arraySegmentPadding, data.Length);
|
||||
return new ArraySegment<T>(newData, arraySegmentPadding, data.Length);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Put_Array_Null_Throws()
|
||||
{
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// create a null array and try to put it into the buffer
|
||||
float[] data = null;
|
||||
Assert.Throws<ArgumentNullException>(() => uut.Put(1024, data));
|
||||
|
||||
ArraySegment<float> dataArraySegment = default(ArraySegment<float>);
|
||||
Assert.Throws<ArgumentNullException>(() => uut.Put(1024, dataArraySegment));
|
||||
|
||||
IntPtr dataPtr = IntPtr.Zero;
|
||||
int dataPtrLength = 100;
|
||||
Assert.Throws<ArgumentNullException>(() => uut.Put<float>(1024, dataPtr, dataPtrLength));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void ByteBuffer_Put_Array_Empty_Throws()
|
||||
{
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// create an array of length == 0, and try to put it into the buffer
|
||||
float[] data = new float[0];
|
||||
Assert.Throws<ArgumentException>(() => uut.Put(1024, data));
|
||||
|
||||
var dataArraySegment = new ArraySegment<float>(new float[10], 5, 0);
|
||||
Assert.Throws<ArgumentException>(() => uut.Put(1024, dataArraySegment));
|
||||
|
||||
fixed(float* floatPtr = data)
|
||||
{
|
||||
var dataPtr = (IntPtr)floatPtr;
|
||||
var dataPtrLength = 0;
|
||||
Assert.Throws<ArgumentException>(() => uut.Put<float>(1024, dataPtr, dataPtrLength));
|
||||
}
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void ByteBuffer_Put_IntPtr_NegativeSize_Throws()
|
||||
{
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// create an array of length == 0, and try to put it into the buffer
|
||||
float[] data = new float[10];
|
||||
fixed(float* floatPtr = data)
|
||||
{
|
||||
var dataPtr = (IntPtr)floatPtr;
|
||||
var dataPtrLength = -1;
|
||||
Assert.Throws<ArgumentException>(() => uut.Put<float>(1024, dataPtr, dataPtrLength));
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable 0169
|
||||
// These are purposely not used and the warning is suppress
|
||||
private struct dummyStruct
|
||||
{
|
||||
int a;
|
||||
float b;
|
||||
}
|
||||
#pragma warning restore 0169
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void ByteBuffer_Put_Array_IncorrectType_Throws()
|
||||
{
|
||||
// Create the Byte Buffer
|
||||
var uut = new ByteBuffer(1024);
|
||||
|
||||
// Create an array of dummy structures that shouldn't be
|
||||
// able to be put into the buffer
|
||||
var data = new dummyStruct[10];
|
||||
Assert.Throws<ArgumentException>(() => uut.Put(1024, data));
|
||||
|
||||
var dataArraySegment = new ArraySegment<dummyStruct>(data);
|
||||
Assert.Throws<ArgumentException>(() => uut.Put(1024, dataArraySegment));
|
||||
|
||||
fixed(dummyStruct* floatPtr = data)
|
||||
{
|
||||
var dataPtr = (IntPtr)floatPtr;
|
||||
var dataPtrLength = data.Length * sizeof(dummyStruct);
|
||||
Assert.Throws<ArgumentException>(() => uut.Put<dummyStruct>(1024, dataPtr, dataPtrLength));
|
||||
}
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Get_Double()
|
||||
{
|
||||
var uut = new ByteBuffer(1024);
|
||||
double value = 3.14159265;
|
||||
uut.PutDouble(900, value);
|
||||
double getValue = uut.GetDouble(900);
|
||||
Assert.AreEqual(value, getValue);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void ByteBuffer_Get_Float()
|
||||
{
|
||||
var uut = new ByteBuffer(1024);
|
||||
float value = 3.14159265F;
|
||||
uut.PutFloat(900, value);
|
||||
double getValue = uut.GetFloat(900);
|
||||
Assert.AreEqual(value, getValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,766 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
[FlatBuffersTestClass]
|
||||
public class FlatBufferBuilderTests
|
||||
{
|
||||
private FlatBufferBuilder CreateBuffer(bool forceDefaults = true)
|
||||
{
|
||||
var fbb = new FlatBufferBuilder(16) {ForceDefaults = forceDefaults};
|
||||
fbb.StartTable(1);
|
||||
return fbb;
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddBool_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddBool(0, false, false);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(bool), endOffset-storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddSByte_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddSbyte(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(sbyte), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddByte_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddByte(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(byte), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddShort_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddShort(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(short), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddUShort_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUshort(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(ushort), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddInt_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddInt(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(int), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddUInt_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUint(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(uint), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddLong_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddLong(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(long), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddULong_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUlong(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(ulong), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddFloat_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddFloat(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(float), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WithForceDefaults_WhenAddDouble_AndDefaultValue_OffsetIncreasesBySize()
|
||||
{
|
||||
var fbb = CreateBuffer();
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddDouble(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(double), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddBool_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddBool(0, false, false);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddSByte_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddSbyte(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddByte_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddByte(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddShort_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddShort(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddUShort_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUshort(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddInt_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddInt(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddUInt_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUint(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddLong_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddLong(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddULong_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUlong(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddFloat_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddFloat(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddDouble_AndDefaultValue_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddDouble(0, 0, 0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableBool_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddBool(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableSbyte_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddSbyte(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableByte_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddByte(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableShort_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddShort(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableUShort_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUshort(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableInt_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddInt(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableUInt_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUint(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableLong_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddLong(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableULong_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUlong(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableFloat_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddFloat(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableDouble_OffsetIsUnchanged()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddDouble(0, null);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableBool_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddBool(0, true);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(bool), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableSbyte_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddSbyte(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(sbyte), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableByte_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddByte(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(byte), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableShort_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddShort(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(short), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableUShort_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUshort(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(ushort), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableInt_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddInt(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(int), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableUInt_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUint(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(uint), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableLong_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddLong(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(long), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableULong_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddUlong(0, 1);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(ulong), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableFloat_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddFloat(0, 1.0F);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(float), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_WhenAddNullableDouble_OffsetIsChangedBySize()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
fbb.AddDouble(0, 1.0);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(sizeof(double), endOffset - storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_Array_Float()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new float[len];
|
||||
data[0] = 1.0079F;
|
||||
data[1] = 4.0026F;
|
||||
data[2] = 6.941F;
|
||||
data[3] = 9.0122F;
|
||||
data[4] = 10.811F;
|
||||
data[5] = 12.0107F;
|
||||
data[6] = 14.0067F;
|
||||
data[7] = 15.9994F;
|
||||
data[8] = 18.9984F;
|
||||
|
||||
fbb.Add(data);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset + sizeof(float) * data.Length);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_Array_Bool()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new bool[len];
|
||||
data[0] = true;
|
||||
data[1] = true;
|
||||
data[2] = false;
|
||||
data[3] = true;
|
||||
data[4] = false;
|
||||
data[5] = true;
|
||||
data[6] = true;
|
||||
data[7] = true;
|
||||
data[8] = false;
|
||||
|
||||
fbb.Add(data);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset + sizeof(bool) * data.Length);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_Array_Double()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
const int len = 9;
|
||||
|
||||
// Construct the data array
|
||||
var data = new double[len];
|
||||
data[0] = 1.0079;
|
||||
data[1] = 4.0026;
|
||||
data[2] = 6.941;
|
||||
data[3] = 9.0122;
|
||||
data[4] = 10.811;
|
||||
data[5] = 12.0107;
|
||||
data[6] = 14.0067;
|
||||
data[7] = 15.9994;
|
||||
data[8] = 18.9984;
|
||||
|
||||
fbb.Add(data);
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset + sizeof(double) * data.Length);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_Array_Null_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
// Construct the data array
|
||||
float[] data = null;
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => fbb.Add(data));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void FlatBufferBuilder_Add_Array_UnsupportedType_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var data = new DummyStruct[10];
|
||||
Assert.Throws<ArgumentException>(() => fbb.Add(data));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_Array_Empty_Noop()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct an empty data array
|
||||
float[] data = new float[0];
|
||||
fbb.Add(data);
|
||||
|
||||
// Make sure the offset didn't change since nothing
|
||||
// was really added
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_ArraySegment_Default_Throws()
|
||||
{
|
||||
#if NETCOREAPP
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
// Construct the data array
|
||||
ArraySegment<float> data = default(ArraySegment<float>);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => fbb.Add(data));
|
||||
#endif
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void FlatBufferBuilder_Add_ArraySegment_UnsupportedType_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var array = new DummyStruct[10];
|
||||
var data = new ArraySegment<DummyStruct>(array);
|
||||
Assert.Throws<ArgumentException>(() => fbb.Add(data));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_ArraySegment_Empty_Noop()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var array = new float[10];
|
||||
var data = new ArraySegment<float>(array, 5, 0);
|
||||
fbb.Add(data);
|
||||
|
||||
// Make sure the offset didn't change since nothing
|
||||
// was really added
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_IntPtr_Zero_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
// Construct the data array
|
||||
var data = IntPtr.Zero;
|
||||
var length = 100;
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => fbb.Add<float>(data, length));
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void FlatBufferBuilder_Add_IntPtr_SizeNegative_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
// Construct the data array
|
||||
var array = new float[10];
|
||||
fixed(float* ptr = array)
|
||||
{
|
||||
var data = (IntPtr)ptr;
|
||||
var length = -1;
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => fbb.Add<float>(data, length));
|
||||
}
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_IntPtr_Zero_Empty_Noop()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var data = IntPtr.Zero;
|
||||
var length = 0;
|
||||
|
||||
fbb.Add<float>(data, length);
|
||||
|
||||
// make sure that a length of 0 doesn't throw also if ptr is Zero as well
|
||||
// and that nothing was really added
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void FlatBufferBuilder_Add_IntPtr_Empty_Noop()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var array = new float[10];
|
||||
fixed(float* ptr = array)
|
||||
{
|
||||
var data = (IntPtr)ptr;
|
||||
var length = 0;
|
||||
fbb.Add<float>(data, length);
|
||||
}
|
||||
|
||||
// Make sure the offset didn't change since nothing
|
||||
// was really added
|
||||
var endOffset = fbb.Offset;
|
||||
Assert.AreEqual(endOffset, storedOffset);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void FlatBufferBuilder_Add_IntPtr_SizeInBytesNotMatchingDataType_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var array = new float[10];
|
||||
fixed(float* ptr = array)
|
||||
{
|
||||
const int invalidBytes = 1;
|
||||
var data = (IntPtr)ptr;
|
||||
// add some invalid bytes to the length
|
||||
var length = 2 * sizeof(float) + invalidBytes;
|
||||
|
||||
Assert.Throws<ArgumentException>(() => fbb.Add<float>(data, length));
|
||||
}
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public unsafe void FlatBufferBuilder_Add_IntPtr_UnsupportedType_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
var storedOffset = fbb.Offset;
|
||||
|
||||
// Construct the data array
|
||||
var array = new DummyStruct[10];
|
||||
fixed(DummyStruct* ptr = array)
|
||||
{
|
||||
var data = (IntPtr)ptr;
|
||||
var length = 10 * sizeof(DummyStruct);
|
||||
|
||||
Assert.Throws<ArgumentException>(() => fbb.Add<DummyStruct>(data, length));
|
||||
}
|
||||
}
|
||||
|
||||
private struct DummyStruct
|
||||
{
|
||||
int value;
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_null_String()
|
||||
{
|
||||
var fbb = new FlatBufferBuilder(16);
|
||||
string s = null;
|
||||
Assert.AreEqual(fbb.CreateSharedString(s).Value, 0);
|
||||
Assert.AreEqual(fbb.CreateString(s).Value, 0);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Empty_Builder()
|
||||
{
|
||||
var fbb = new FlatBufferBuilder(16);
|
||||
var str = "Hello";
|
||||
var flatbuffer = "Flatbuffers!";
|
||||
var strOffset = fbb.CreateSharedString(str);
|
||||
var flatbufferOffset = fbb.CreateSharedString(flatbuffer);
|
||||
fbb.Clear();
|
||||
var flatbufferOffset2 = fbb.CreateSharedString(flatbuffer);
|
||||
var strOffset2 = fbb.CreateSharedString(str);
|
||||
Assert.IsFalse(strOffset.Value == strOffset2.Value);
|
||||
Assert.IsFalse(flatbufferOffset.Value == flatbufferOffset2.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(UnsafeByteBuffer)' == 'true'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants>$(DefineConstants);UNSAFE_BYTEBUFFER</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(EnableSpanT)' == 'true'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants>$(DefineConstants);ENABLE_SPAN_T</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\net\FlatBuffers\ByteBuffer.cs">
|
||||
<Link>FlatBuffers\ByteBuffer.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\ByteBufferUtil.cs">
|
||||
<Link>FlatBuffers\ByteBufferUtil.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\IFlatbufferObject.cs">
|
||||
<Link>FlatBuffers\IFlatbufferObject.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\Offset.cs">
|
||||
<Link>FlatBuffers\Offset.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\FlatBufferBuilder.cs">
|
||||
<Link>FlatBuffers\FlatBufferBuilder.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\FlatBufferConstants.cs">
|
||||
<Link>FlatBuffers\FlatBufferConstants.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\FlatBufferVerify.cs">
|
||||
<Link>FlatBuffers\FlatBufferVerify.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\Struct.cs">
|
||||
<Link>FlatBuffers\Struct.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\Table.cs">
|
||||
<Link>FlatBuffers\Table.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example2\Monster.cs">
|
||||
<Link>MyGame\Example2\Monster.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Any.cs">
|
||||
<Link>MyGame\Example\Any.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\AnyAmbiguousAliases.cs">
|
||||
<Link>MyGame\Example\AnyAmbiguousAliases.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\AnyUniqueAliases.cs">
|
||||
<Link>MyGame\Example\AnyUniqueAliases.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Color.cs">
|
||||
<Link>MyGame\Example\Color.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Race.cs">
|
||||
<Link>MyGame\Example\Race.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Monster.cs">
|
||||
<Link>MyGame\Example\Monster.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Referrable.cs">
|
||||
<Link>MyGame\Example\Referrable.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Stat.cs">
|
||||
<Link>MyGame\Example\Stat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Test.cs">
|
||||
<Link>MyGame\Example\Test.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\TestSimpleTableWithEnum.cs">
|
||||
<Link>MyGame\Example\TestSimpleTableWithEnum.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\TypeAliases.cs">
|
||||
<Link>MyGame\Example\TypeAliases.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Vec3.cs">
|
||||
<Link>MyGame\Example\Vec3.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Ability.cs">
|
||||
<Link>MyGame\Example\Ability.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\ArrayTable.cs">
|
||||
<Link>MyGame\Example\ArrayTable.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\ArrayStruct.cs">
|
||||
<Link>MyGame\Example\ArrayStruct.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\NestedStruct.cs">
|
||||
<Link>MyGame\Example\NestedStruct.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\LongEnum.cs">
|
||||
<Link>MyGame\Example\LongEnum.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\TestEnum.cs">
|
||||
<Link>MyGame\Example\TestEnum.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\InParentNamespace.cs">
|
||||
<Link>MyGame\InParentNamespace.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\namespace_test\NamespaceA\NamespaceB\EnumInNestedNS.cs">
|
||||
<Link>NamespaceA\NamespaceB\EnumInNestedNS.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\namespace_test\NamespaceA\NamespaceB\StructInNestedNS.cs">
|
||||
<Link>NamespaceA\NamespaceB\StructInNestedNS.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\namespace_test\NamespaceA\NamespaceB\TableInNestedNS.cs">
|
||||
<Link>NamespaceA\NamespaceB\TableInNestedNS.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\namespace_test\NamespaceA\NamespaceB\UnionInNestedNS.cs">
|
||||
<Link>NamespaceA\NamespaceB\UnionInNestedNS.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\namespace_test\NamespaceA\TableInFirstNS.cs">
|
||||
<Link>NamespaceA\TableInFirstNS.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_vector\Attacker.cs">
|
||||
<Link>union_vector\Attacker.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_vector\BookReader.cs">
|
||||
<Link>union_vector\BookReader.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_vector\Character.cs">
|
||||
<Link>union_vector\Character.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_vector\Movie.cs">
|
||||
<Link>union_vector\Movie.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_vector\Rapunzel.cs">
|
||||
<Link>union_vector\Rapunzel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\optional_scalars\OptionalByte.cs">
|
||||
<Link>optional_scalars\OptionalByte.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\optional_scalars\ScalarStuff.cs">
|
||||
<Link>optional_scalars\ScalarStuff.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\KeywordTest\ABC.cs">
|
||||
<Link>KeywordTest\ABC.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\KeywordTest\public.cs">
|
||||
<Link>KeywordTest\public.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\KeywordTest\KeywordsInTable.cs">
|
||||
<Link>KeywordTest\KeywordsInTable.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\KeywordTest\KeywordsInUnion.cs">
|
||||
<Link>KeywordTest\KeywordsInUnion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\nested_namespace_test\nested_namespace_test1_generated.cs">
|
||||
<Link>nested_namespace_test\nested_namespace_test1_generated.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\nested_namespace_test\nested_namespace_test2_generated.cs">
|
||||
<Link>nested_namespace_test\nested_namespace_test2_generated.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\nested_namespace_test\nested_namespace_test3_generated.cs">
|
||||
<Link>nested_namespace_test\nested_namespace_test3_generated.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_value_collsion\union_value_collision_generated.cs">
|
||||
<Link>union_value_collsion\union_value_collision_generated.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove=".gitignore" />
|
||||
<None Remove="clean.sh" />
|
||||
<None Remove="NetTest.sh" />
|
||||
<None Remove="packages.config" />
|
||||
<None Remove="README.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\monsterdata_test.mon">
|
||||
<Link>Resources\monsterdata_test.mon</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\monsterdata_test.json">
|
||||
<Link>Resources\monsterdata_test.json</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class FlatBuffersTestClassAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class FlatBuffersTestMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
internal static class FuzzTestData
|
||||
{
|
||||
private static readonly byte[] _overflowInt32 = new byte[] {0x83, 0x33, 0x33, 0x33};
|
||||
private static readonly byte[] _overflowInt64 = new byte[] { 0x84, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
|
||||
|
||||
public static readonly bool BoolValue = true;
|
||||
public static readonly sbyte Int8Value = -127; // 0x81
|
||||
public static readonly byte UInt8Value = 255; // 0xFF
|
||||
public static readonly short Int16Value = -32222; // 0x8222;
|
||||
public static readonly ushort UInt16Value = 65262; // 0xFEEE
|
||||
public static readonly int Int32Value = BitConverter.ToInt32(_overflowInt32, 0);
|
||||
public static readonly uint UInt32Value = 0xFDDDDDDD;
|
||||
public static readonly long Int64Value = BitConverter.ToInt64(_overflowInt64, 0);
|
||||
public static readonly ulong UInt64Value = 0xFCCCCCCCCCCCCCCC;
|
||||
public static readonly float Float32Value = 3.14159f;
|
||||
public static readonly double Float64Value = 3.14159265359;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Lcg Pseudo RNG
|
||||
/// </summary>
|
||||
internal sealed class Lcg
|
||||
{
|
||||
private const uint InitialValue = 10000;
|
||||
private uint _state;
|
||||
|
||||
public Lcg()
|
||||
{
|
||||
_state = InitialValue;
|
||||
}
|
||||
|
||||
public uint Next()
|
||||
{
|
||||
return (_state = 69069 * _state + 362437);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_state = InitialValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
@REM Builds a .NET solution file, adds the project, builds it
|
||||
@REM and executes it. Cleans up all generated files and directories.
|
||||
|
||||
set TEMP_BIN=.tmp
|
||||
|
||||
@REM Run the .NET tests
|
||||
set CORE_FILE=FlatBuffers.Test
|
||||
set CORE_PROJ_FILE=%CORE_FILE%.csproj
|
||||
set CORE_SLN_FILE=%CORE_FILE%.sln
|
||||
dotnet new sln --force --name %CORE_FILE%
|
||||
dotnet sln %CORE_SLN_FILE% add %CORE_PROJ_FILE%
|
||||
dotnet build -c Release -o %TEMP_BIN% -v quiet %CORE_PROJ_FILE%
|
||||
%TEMP_BIN%\%CORE_FILE%.exe
|
||||
del /f %CORE_SLN_FILE%
|
||||
|
||||
@REM TODO(dbaileychess): Support the other configurations in NetTest.sh
|
||||
|
||||
@REM remove the temp bin directory, with files (/S) and quietly (/Q)
|
||||
RD /S /Q %TEMP_BIN%
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
PROJ_FILE=FlatBuffers.Test.csproj
|
||||
|
||||
TEMP_DOTNET_DIR=.dotnet_tmp
|
||||
TEMP_BIN=.tmp
|
||||
|
||||
[ -d $TEMP_DOTNET_DIR ] || mkdir $TEMP_DOTNET_DIR
|
||||
|
||||
[ -f dotnet-install.sh ] || curl -OL https://dot.net/v1/dotnet-install.sh
|
||||
|
||||
./dotnet-install.sh --version latest --install-dir $TEMP_DOTNET_DIR
|
||||
|
||||
DOTNET=$TEMP_DOTNET_DIR/dotnet
|
||||
|
||||
$DOTNET new sln
|
||||
$DOTNET sln add $PROJ_FILE
|
||||
$DOTNET restore -r linux-x64 $PROJ_FILE
|
||||
|
||||
# Testing with default options.
|
||||
msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:quiet $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:quiet $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:quiet $PROJ_FILE
|
||||
$TEMP_BIN/FlatBuffers.Core.Test.exe
|
||||
rm -fr $TEMP_BIN
|
||||
|
||||
rm FlatBuffers.Test.sln
|
||||
rm -rf obj
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var testResults = new List<bool>();
|
||||
|
||||
var testClasses = Assembly.GetExecutingAssembly().GetExportedTypes()
|
||||
.Where(t => t.IsClass && t.GetCustomAttributes(typeof (FlatBuffersTestClassAttribute), false).Length > 0);
|
||||
|
||||
foreach (var testClass in testClasses)
|
||||
{
|
||||
var methods = testClass.GetMethods(BindingFlags.Public |
|
||||
BindingFlags.Instance)
|
||||
.Where(m => m.GetCustomAttributes(typeof(FlatBuffersTestMethodAttribute), false).Length > 0);
|
||||
|
||||
var inst = Activator.CreateInstance(testClass);
|
||||
|
||||
foreach (var method in methods)
|
||||
{
|
||||
try
|
||||
{
|
||||
method.Invoke(inst, new object[] { });
|
||||
testResults.Add(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0}: FAILED when invoking {1} with error {2}",
|
||||
testClass.Name ,method.Name, ex.GetBaseException());
|
||||
testResults.Add(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var failedCount = testResults.Count(i => i == false);
|
||||
|
||||
Console.WriteLine("{0} tests run, {1} failed", testResults.Count, failedCount);
|
||||
|
||||
if (failedCount > 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("FlatBuffers.Test")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("FlatBuffers.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright (c) 2014 Google Inc")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a1d58a51-3e74-4ae9-aac7-5a399c9eed1a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,38 @@
|
||||
# .NET Tests
|
||||
|
||||
## Running on Linux
|
||||
|
||||
### Prerequisites
|
||||
To run the tests on a Linux a few prerequisites are needed:
|
||||
|
||||
1) mono
|
||||
2) msbuild
|
||||
|
||||
### Running
|
||||
|
||||
To run the tests:
|
||||
|
||||
```
|
||||
./NetTest.sh
|
||||
```
|
||||
|
||||
This will download the .NET installer and core SDK if those are not already
|
||||
installed. Then it will build the tests using `msbuild` and run the resulting
|
||||
test binary with `mono`.
|
||||
|
||||
After running the tests, the downloaded .NET installer and SDK are *not* removed
|
||||
as they can be reused in subsequent invocations. The files are ignored by git by
|
||||
default, and can remain in the working directory.
|
||||
|
||||
### Cleaning
|
||||
|
||||
If you want to clean up the downloaded .NET installer and SDK, run:
|
||||
|
||||
```
|
||||
./clean.sh
|
||||
```
|
||||
|
||||
This will wipe away the downloaded files and directories. Those will be
|
||||
automatically re-downloaded when running `NetTest.sh`.
|
||||
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// A test Table object that gives easy access to the slot data
|
||||
/// </summary>
|
||||
internal struct TestTable
|
||||
{
|
||||
Table t;
|
||||
|
||||
public TestTable(ByteBuffer bb, int pos)
|
||||
{
|
||||
t = new Table(pos, bb);
|
||||
}
|
||||
|
||||
public bool GetSlot(int slot, bool def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetSbyte(t.bb_pos + off) != 0;
|
||||
}
|
||||
|
||||
public sbyte GetSlot(int slot, sbyte def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetSbyte(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public byte GetSlot(int slot, byte def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.Get(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public short GetSlot(int slot, short def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetShort(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public ushort GetSlot(int slot, ushort def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetUshort(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public int GetSlot(int slot, int def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetInt(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public uint GetSlot(int slot, uint def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetUint(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public long GetSlot(int slot, long def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetLong(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public ulong GetSlot(int slot, ulong def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetUlong(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public float GetSlot(int slot, float def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetFloat(t.bb_pos + off);
|
||||
}
|
||||
|
||||
public double GetSlot(int slot, double def)
|
||||
{
|
||||
var off = t.__offset(slot);
|
||||
|
||||
if (off == 0)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
return t.bb.GetDouble(t.bb_pos + off);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Remove files and directory that are needed to build and run the .NET tests.
|
||||
# The script NetTest.sh installs these as needed.
|
||||
|
||||
[ -d .dotnet_tmp ] && rm -rf .dotnet_tmp
|
||||
[ -d packages ] && rm -rf packages
|
||||
[ -d .tmp ] && rm -rf .tmp
|
||||
[ -f nuget.exe ] && rm nuget.exe
|
||||
[ -f dotnet-intall.sh ] && rm dotnet-install.sh
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" />
|
||||
</packages>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# Copyright 2014 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
pushd "$(dirname $0)" >/dev/null
|
||||
test_dir="$(pwd)"
|
||||
go_path=${test_dir}/go_gen
|
||||
go_src=${go_path}/src
|
||||
|
||||
# Emit Go code for the example schemas in the test dir:
|
||||
../flatc -g --gen-object-api -I include_test -o ${go_src} monster_test.fbs optional_scalars.fbs
|
||||
../flatc -g --gen-object-api -I include_test/sub -o ${go_src} include_test/order.fbs
|
||||
../flatc -g --gen-object-api -o ${go_src}/Pizza include_test/sub/no_namespace.fbs
|
||||
|
||||
# Go requires a particular layout of files in order to link multiple packages.
|
||||
# Copy flatbuffer Go files to their own package directories to compile the
|
||||
# test binary:
|
||||
mkdir -p ${go_src}/github.com/google/flatbuffers/go
|
||||
mkdir -p ${go_src}/flatbuffers_test
|
||||
|
||||
cp -a ../go/* ./go_gen/src/github.com/google/flatbuffers/go
|
||||
cp -a ./go_test.go ./go_gen/src/flatbuffers_test/
|
||||
|
||||
# https://stackoverflow.com/a/63545857/7024978
|
||||
# We need to turn off go modules for this script
|
||||
# to work.
|
||||
go env -w GO111MODULE=off
|
||||
|
||||
# Run tests with necessary flags.
|
||||
# Developers may wish to see more detail by appending the verbosity flag
|
||||
# -test.v to arguments for this command, as in:
|
||||
# go -test -test.v ...
|
||||
# Developers may also wish to run benchmarks, which may be achieved with the
|
||||
# flag -test.bench and the wildcard regexp ".":
|
||||
# go -test -test.bench=. ...
|
||||
GOPATH=${go_path} go test flatbuffers_test \
|
||||
--coverpkg=github.com/google/flatbuffers/go \
|
||||
--cpp_data=${test_dir}/monsterdata_test.mon \
|
||||
--out_data=${test_dir}/monsterdata_go_wire.mon \
|
||||
--bench=. \
|
||||
--benchtime=3s \
|
||||
--fuzz=true \
|
||||
--fuzz_fields=4 \
|
||||
--fuzz_objects=10000
|
||||
|
||||
GO_TEST_RESULT=$?
|
||||
rm -rf ${go_path}/{pkg,src}
|
||||
if [[ $GO_TEST_RESULT == 0 ]]; then
|
||||
echo "OK: Go tests passed."
|
||||
else
|
||||
echo "KO: Go tests failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NOT_FMT_FILES=$(gofmt -l .)
|
||||
if [[ ${NOT_FMT_FILES} != "" ]]; then
|
||||
echo "These files are not well gofmt'ed:"
|
||||
echo
|
||||
echo "${NOT_FMT_FILES}"
|
||||
# enable this when enums are properly formated
|
||||
# exit 1
|
||||
fi
|
||||
|
||||
# Re-enable go modules when done tests
|
||||
go env -w GO111MODULE=on
|
||||
@@ -0,0 +1,17 @@
|
||||
// <auto-generated>
|
||||
// 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,
|
||||
where = 1,
|
||||
@stackalloc = 2,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace KeywordTest
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct KeywordsInTable : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_25(); }
|
||||
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb) { return GetRootAsKeywordsInTable(_bb, new KeywordsInTable()); }
|
||||
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb, KeywordsInTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
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 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 bool Default { get { int o = __p.__offset(10); return o != 0 ? 0!=__p.bb.Get(o + __p.bb_pos) : (bool)false; } }
|
||||
public bool MutateDefault(bool @default) { int o = __p.__offset(10); if (o != 0) { __p.bb.Put(o + __p.bb_pos, (byte)(@default ? 1 : 0)); return true; } else { return false; } }
|
||||
|
||||
public static Offset<KeywordTest.KeywordsInTable> CreateKeywordsInTable(FlatBufferBuilder builder,
|
||||
KeywordTest.ABC @is = KeywordTest.ABC.@void,
|
||||
KeywordTest.@public @private = KeywordTest.@public.NONE,
|
||||
int type = 0,
|
||||
bool @default = false) {
|
||||
builder.StartTable(4);
|
||||
KeywordsInTable.AddType(builder, type);
|
||||
KeywordsInTable.AddPrivate(builder, @private);
|
||||
KeywordsInTable.AddIs(builder, @is);
|
||||
KeywordsInTable.AddDefault(builder, @default);
|
||||
return KeywordsInTable.EndKeywordsInTable(builder);
|
||||
}
|
||||
|
||||
public static void StartKeywordsInTable(FlatBufferBuilder builder) { builder.StartTable(4); }
|
||||
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 void AddDefault(FlatBufferBuilder builder, bool @default) { builder.AddBool(3, @default, false); }
|
||||
public static Offset<KeywordTest.KeywordsInTable> EndKeywordsInTable(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<KeywordTest.KeywordsInTable>(o);
|
||||
}
|
||||
public KeywordsInTableT UnPack() {
|
||||
var _o = new KeywordsInTableT();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(KeywordsInTableT _o) {
|
||||
_o.Is = this.Is;
|
||||
_o.Private = this.Private;
|
||||
_o.Type = this.Type;
|
||||
_o.Default = this.Default;
|
||||
}
|
||||
public static Offset<KeywordTest.KeywordsInTable> Pack(FlatBufferBuilder builder, KeywordsInTableT _o) {
|
||||
if (_o == null) return default(Offset<KeywordTest.KeywordsInTable>);
|
||||
return CreateKeywordsInTable(
|
||||
builder,
|
||||
_o.Is,
|
||||
_o.Private,
|
||||
_o.Type,
|
||||
_o.Default);
|
||||
}
|
||||
}
|
||||
|
||||
public class KeywordsInTableT
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("is")]
|
||||
public KeywordTest.ABC Is { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("private")]
|
||||
public KeywordTest.@public Private { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("type")]
|
||||
public int Type { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("default")]
|
||||
public bool Default { get; set; }
|
||||
|
||||
public KeywordsInTableT() {
|
||||
this.Is = KeywordTest.ABC.@void;
|
||||
this.Private = KeywordTest.@public.NONE;
|
||||
this.Type = 0;
|
||||
this.Default = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public class KeywordsInTableVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, uint tablePos)
|
||||
{
|
||||
return verifier.VerifyTableStart(tablePos)
|
||||
&& verifier.VerifyField(tablePos, 4 /*Is*/, 4 /*KeywordTest.ABC*/, 4, false)
|
||||
&& verifier.VerifyField(tablePos, 6 /*Private*/, 4 /*KeywordTest.@public*/, 4, false)
|
||||
&& verifier.VerifyField(tablePos, 8 /*Type*/, 4 /*int*/, 4, false)
|
||||
&& verifier.VerifyField(tablePos, 10 /*Default*/, 1 /*bool*/, 1, false)
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// <auto-generated>
|
||||
// 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,
|
||||
};
|
||||
|
||||
public class KeywordsInUnionUnion {
|
||||
public KeywordsInUnion Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public KeywordsInUnionUnion() {
|
||||
this.Type = KeywordsInUnion.NONE;
|
||||
this.Value = null;
|
||||
}
|
||||
|
||||
public T As<T>() where T : class { return this.Value as T; }
|
||||
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(Google.FlatBuffers.FlatBufferBuilder builder, KeywordsInUnionUnion _o) {
|
||||
switch (_o.Type) {
|
||||
default: return 0;
|
||||
case KeywordsInUnion.@static: return KeywordTest.KeywordsInTable.Pack(builder, _o.Asstatic()).Value;
|
||||
case KeywordsInUnion.@internal: return KeywordTest.KeywordsInTable.Pack(builder, _o.Asinternal()).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class KeywordsInUnionUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
|
||||
public override bool CanConvert(System.Type objectType) {
|
||||
return objectType == typeof(KeywordsInUnionUnion) || objectType == typeof(System.Collections.Generic.List<KeywordsInUnionUnion>);
|
||||
}
|
||||
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = value as System.Collections.Generic.List<KeywordsInUnionUnion>;
|
||||
if (_olist != null) {
|
||||
writer.WriteStartArray();
|
||||
foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
|
||||
writer.WriteEndArray();
|
||||
} else {
|
||||
this.WriteJson(writer, value as KeywordsInUnionUnion, serializer);
|
||||
}
|
||||
}
|
||||
public void WriteJson(Newtonsoft.Json.JsonWriter writer, KeywordsInUnionUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return;
|
||||
serializer.Serialize(writer, _o.Value);
|
||||
}
|
||||
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = existingValue as System.Collections.Generic.List<KeywordsInUnionUnion>;
|
||||
if (_olist != null) {
|
||||
for (var _j = 0; _j < _olist.Count; ++_j) {
|
||||
reader.Read();
|
||||
_olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
|
||||
}
|
||||
reader.Read();
|
||||
return _olist;
|
||||
} else {
|
||||
return this.ReadJson(reader, existingValue as KeywordsInUnionUnion, serializer);
|
||||
}
|
||||
}
|
||||
public KeywordsInUnionUnion ReadJson(Newtonsoft.Json.JsonReader reader, KeywordsInUnionUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return null;
|
||||
switch (_o.Type) {
|
||||
default: 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static public class KeywordsInUnionVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, byte typeId, uint tablePos)
|
||||
{
|
||||
bool result = true;
|
||||
switch((KeywordsInUnion)typeId)
|
||||
{
|
||||
case KeywordsInUnion.@static:
|
||||
result = KeywordTest.KeywordsInTableVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case KeywordsInUnion.@internal:
|
||||
result = KeywordTest.KeywordsInTableVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
default: result = true;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace KeywordTest
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct Table2 : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_25(); }
|
||||
public static Table2 GetRootAsTable2(ByteBuffer _bb) { return GetRootAsTable2(_bb, new Table2()); }
|
||||
public static Table2 GetRootAsTable2(ByteBuffer _bb, Table2 obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
public Table2 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public KeywordTest.KeywordsInUnion TypeType { get { int o = __p.__offset(4); return o != 0 ? (KeywordTest.KeywordsInUnion)__p.bb.Get(o + __p.bb_pos) : KeywordTest.KeywordsInUnion.NONE; } }
|
||||
public TTable? Type<TTable>() where TTable : struct, IFlatbufferObject { int o = __p.__offset(6); return o != 0 ? (TTable?)__p.__union<TTable>(o + __p.bb_pos) : null; }
|
||||
public KeywordTest.KeywordsInTable TypeAsstatic() { return Type<KeywordTest.KeywordsInTable>().Value; }
|
||||
public KeywordTest.KeywordsInTable TypeAsinternal() { return Type<KeywordTest.KeywordsInTable>().Value; }
|
||||
|
||||
public static Offset<KeywordTest.Table2> CreateTable2(FlatBufferBuilder builder,
|
||||
KeywordTest.KeywordsInUnion type_type = KeywordTest.KeywordsInUnion.NONE,
|
||||
int typeOffset = 0) {
|
||||
builder.StartTable(2);
|
||||
Table2.AddType(builder, typeOffset);
|
||||
Table2.AddTypeType(builder, type_type);
|
||||
return Table2.EndTable2(builder);
|
||||
}
|
||||
|
||||
public static void StartTable2(FlatBufferBuilder builder) { builder.StartTable(2); }
|
||||
public static void AddTypeType(FlatBufferBuilder builder, KeywordTest.KeywordsInUnion typeType) { builder.AddByte(0, (byte)typeType, 0); }
|
||||
public static void AddType(FlatBufferBuilder builder, int typeOffset) { builder.AddOffset(1, typeOffset, 0); }
|
||||
public static Offset<KeywordTest.Table2> EndTable2(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<KeywordTest.Table2>(o);
|
||||
}
|
||||
public Table2T UnPack() {
|
||||
var _o = new Table2T();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(Table2T _o) {
|
||||
_o.Type = new KeywordTest.KeywordsInUnionUnion();
|
||||
_o.Type.Type = this.TypeType;
|
||||
switch (this.TypeType) {
|
||||
default: break;
|
||||
case KeywordTest.KeywordsInUnion.static:
|
||||
_o.Type.Value = this.Type<KeywordTest.KeywordsInTable>().HasValue ? this.Type<KeywordTest.KeywordsInTable>().Value.UnPack() : null;
|
||||
break;
|
||||
case KeywordTest.KeywordsInUnion.internal:
|
||||
_o.Type.Value = this.Type<KeywordTest.KeywordsInTable>().HasValue ? this.Type<KeywordTest.KeywordsInTable>().Value.UnPack() : null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static Offset<KeywordTest.Table2> Pack(FlatBufferBuilder builder, Table2T _o) {
|
||||
if (_o == null) return default(Offset<KeywordTest.Table2>);
|
||||
var _type_type = _o.Type == null ? KeywordTest.KeywordsInUnion.NONE : _o.Type.Type;
|
||||
var _type = _o.Type == null ? 0 : KeywordTest.KeywordsInUnionUnion.Pack(builder, _o.Type);
|
||||
return CreateTable2(
|
||||
builder,
|
||||
_type_type,
|
||||
_type);
|
||||
}
|
||||
}
|
||||
|
||||
public class Table2T
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("type_type")]
|
||||
private KeywordTest.KeywordsInUnion TypeType {
|
||||
get {
|
||||
return this.Type != null ? this.Type.Type : KeywordTest.KeywordsInUnion.NONE;
|
||||
}
|
||||
set {
|
||||
this.Type = new KeywordTest.KeywordsInUnionUnion();
|
||||
this.Type.Type = value;
|
||||
}
|
||||
}
|
||||
[Newtonsoft.Json.JsonProperty("type")]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(KeywordTest.KeywordsInUnionUnion_JsonConverter))]
|
||||
public KeywordTest.KeywordsInUnionUnion Type { get; set; }
|
||||
|
||||
public Table2T() {
|
||||
this.Type = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public class Table2Verify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, uint tablePos)
|
||||
{
|
||||
return verifier.VerifyTableStart(tablePos)
|
||||
&& verifier.VerifyField(tablePos, 4 /*TypeType*/, 1 /*KeywordTest.KeywordsInUnion*/, 1, false)
|
||||
&& verifier.VerifyUnion(tablePos, 4, 6 /*Type*/, KeywordTest.KeywordsInUnionVerify.Verify, false)
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// <auto-generated>
|
||||
// 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
|
||||
{
|
||||
NONE = 0,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
+622
@@ -0,0 +1,622 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import DictionaryLookup.*;
|
||||
import MyGame.Example.*
|
||||
import optional_scalars.*
|
||||
import com.google.flatbuffers.ByteBufferUtil
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import NamespaceA.*
|
||||
import NamespaceA.NamespaceB.*
|
||||
import NamespaceA.NamespaceB.TableInNestedNS
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.io.RandomAccessFile
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import java.nio.channels.FileChannel
|
||||
|
||||
import com.google.flatbuffers.Constants.SIZE_PREFIX_LENGTH
|
||||
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class KotlinTest {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
// First, let's test reading a FlatBuffer generated by C++ code:
|
||||
// This file was generated from monsterdata_test.json
|
||||
|
||||
val data = RandomAccessFile(File("monsterdata_test.mon"), "r").use {
|
||||
val temp = ByteArray(it.length().toInt())
|
||||
it.readFully(temp)
|
||||
temp
|
||||
}
|
||||
|
||||
// Now test it:
|
||||
|
||||
val bb = ByteBuffer.wrap(data)
|
||||
TestBuffer(bb)
|
||||
|
||||
// Second, let's create a FlatBuffer from scratch in Java, and test it also.
|
||||
// We use an initial size of 1 to exercise the reallocation algorithm,
|
||||
// normally a size larger than the typical FlatBuffer you generate would be
|
||||
// better for performance.
|
||||
val fbb = FlatBufferBuilder(1)
|
||||
|
||||
TestBuilderBasics(fbb, true)
|
||||
TestBuilderBasics(fbb, false)
|
||||
|
||||
TestExtendedBuffer(fbb.dataBuffer().asReadOnlyBuffer())
|
||||
|
||||
TestNamespaceNesting()
|
||||
|
||||
TestNestedFlatBuffer()
|
||||
|
||||
TestCreateByteVector()
|
||||
|
||||
TestCreateUninitializedVector()
|
||||
|
||||
TestByteBufferFactory()
|
||||
|
||||
TestSizedInputStream()
|
||||
|
||||
TestVectorOfUnions()
|
||||
|
||||
TestSharedStringPool()
|
||||
TestScalarOptional()
|
||||
TestDictionaryLookup()
|
||||
println("FlatBuffers test: completed successfully")
|
||||
}
|
||||
|
||||
fun TestDictionaryLookup() {
|
||||
val fbb = FlatBufferBuilder(16)
|
||||
val lfIndex = LongFloatEntry.createLongFloatEntry(fbb, 0, 99.0f)
|
||||
val vectorEntriesIdx = LongFloatMap.createEntriesVector(fbb, intArrayOf(lfIndex))
|
||||
val rootIdx = LongFloatMap.createLongFloatMap(fbb, vectorEntriesIdx)
|
||||
|
||||
LongFloatMap.finishLongFloatMapBuffer(fbb, rootIdx)
|
||||
val map = LongFloatMap.getRootAsLongFloatMap(fbb.dataBuffer())
|
||||
assert(map.entriesLength == 1)
|
||||
|
||||
val e = map.entries(0)!!
|
||||
assert(e.key == 0L)
|
||||
assert(e.value == 99.0f)
|
||||
|
||||
val e2 = map.entriesByKey(0)!!
|
||||
assert(e2.key == 0L)
|
||||
assert(e2.value == 99.0f)
|
||||
}
|
||||
|
||||
fun TestEnums() {
|
||||
assert(Color.name(Color.Red.toInt()) == "Red")
|
||||
assert(Color.name(Color.Blue.toInt()) == "Blue")
|
||||
assert(Any_.name(Any_.NONE.toInt()) == "NONE")
|
||||
assert(Any_.name(Any_.Monster.toInt()) == "Monster")
|
||||
}
|
||||
|
||||
fun TestBuffer(bb: ByteBuffer) {
|
||||
assert(Monster.MonsterBufferHasIdentifier(bb) == true)
|
||||
|
||||
val monster = Monster.getRootAsMonster(bb)
|
||||
|
||||
assert(monster.hp == 80.toShort())
|
||||
assert(monster.mana == 150.toShort()) // default
|
||||
|
||||
assert(monster.name == "MyMonster")
|
||||
// monster.friendly() // can't access, deprecated
|
||||
|
||||
val pos = monster.pos!!
|
||||
assert(pos.x == 1.0f)
|
||||
assert(pos.y == 2.0f)
|
||||
assert(pos.z == 3.0f)
|
||||
assert(pos.test1 == 3.0)
|
||||
// issue: int != byte
|
||||
assert(pos.test2 == Color.Green)
|
||||
val t = pos.test3!!
|
||||
assert(t.a == 5.toShort())
|
||||
assert(t.b == 6.toByte())
|
||||
|
||||
assert(monster.testType == Any_.Monster)
|
||||
val monster2 = Monster()
|
||||
assert(monster.test(monster2) != null == true)
|
||||
assert(monster2.name == "Fred")
|
||||
|
||||
assert(monster.inventoryLength == 5)
|
||||
var invsum = 0u
|
||||
for (i in 0 until monster.inventoryLength)
|
||||
invsum += monster.inventory(i)
|
||||
assert(invsum == 10u)
|
||||
|
||||
// Alternative way of accessing a vector:
|
||||
val ibb = monster.inventoryAsByteBuffer
|
||||
invsum = 0u
|
||||
while (ibb.position() < ibb.limit())
|
||||
invsum += ibb.get().toUInt()
|
||||
assert(invsum == 10u)
|
||||
|
||||
|
||||
val test_0 = monster.test4(0)!!
|
||||
val test_1 = monster.test4(1)!!
|
||||
assert(monster.test4Length == 2)
|
||||
assert(test_0.a + test_0.b + test_1.a + test_1.b == 100)
|
||||
|
||||
assert(monster.testarrayofstringLength == 2)
|
||||
assert(monster.testarrayofstring(0) == "test1")
|
||||
assert(monster.testarrayofstring(1) == "test2")
|
||||
|
||||
assert(monster.testbool == true)
|
||||
}
|
||||
|
||||
// this method checks additional fields not present in the binary buffer read from file
|
||||
// these new tests are performed on top of the regular tests
|
||||
fun TestExtendedBuffer(bb: ByteBuffer) {
|
||||
TestBuffer(bb)
|
||||
|
||||
val monster = Monster.getRootAsMonster(bb)
|
||||
|
||||
assert(monster.testhashu32Fnv1 == (Integer.MAX_VALUE + 1L).toUInt())
|
||||
}
|
||||
|
||||
fun TestNamespaceNesting() {
|
||||
// reference / manipulate these to verify compilation
|
||||
val fbb = FlatBufferBuilder(1)
|
||||
|
||||
TableInNestedNS.startTableInNestedNS(fbb)
|
||||
TableInNestedNS.addFoo(fbb, 1234)
|
||||
val nestedTableOff = TableInNestedNS.endTableInNestedNS(fbb)
|
||||
|
||||
TableInFirstNS.startTableInFirstNS(fbb)
|
||||
TableInFirstNS.addFooTable(fbb, nestedTableOff)
|
||||
}
|
||||
|
||||
fun TestNestedFlatBuffer() {
|
||||
val nestedMonsterName = "NestedMonsterName"
|
||||
val nestedMonsterHp: Short = 600
|
||||
val nestedMonsterMana: Short = 1024
|
||||
|
||||
var fbb1: FlatBufferBuilder? = FlatBufferBuilder(16)
|
||||
val str1 = fbb1!!.createString(nestedMonsterName)
|
||||
Monster.startMonster(fbb1)
|
||||
Monster.addName(fbb1, str1)
|
||||
Monster.addHp(fbb1, nestedMonsterHp)
|
||||
Monster.addMana(fbb1, nestedMonsterMana)
|
||||
val monster1 = Monster.endMonster(fbb1)
|
||||
Monster.finishMonsterBuffer(fbb1, monster1)
|
||||
val fbb1Bytes = fbb1.sizedByteArray()
|
||||
|
||||
val fbb2 = FlatBufferBuilder(16)
|
||||
val str2 = fbb2.createString("My Monster")
|
||||
val nestedBuffer = Monster.createTestnestedflatbufferVector(fbb2, fbb1Bytes.asUByteArray())
|
||||
Monster.startMonster(fbb2)
|
||||
Monster.addName(fbb2, str2)
|
||||
Monster.addHp(fbb2, 50.toShort())
|
||||
Monster.addMana(fbb2, 32.toShort())
|
||||
Monster.addTestnestedflatbuffer(fbb2, nestedBuffer)
|
||||
val monster = Monster.endMonster(fbb2)
|
||||
Monster.finishMonsterBuffer(fbb2, monster)
|
||||
|
||||
// Now test the data extracted from the nested buffer
|
||||
val mons = Monster.getRootAsMonster(fbb2.dataBuffer())
|
||||
val nestedMonster = mons.testnestedflatbufferAsMonster!!
|
||||
|
||||
assert(nestedMonsterMana == nestedMonster.mana)
|
||||
assert(nestedMonsterHp == nestedMonster.hp)
|
||||
assert(nestedMonsterName == nestedMonster.name)
|
||||
}
|
||||
|
||||
fun TestCreateByteVector() {
|
||||
val fbb = FlatBufferBuilder(16)
|
||||
val str = fbb.createString("MyMonster")
|
||||
val inventory = byteArrayOf(0, 1, 2, 3, 4)
|
||||
val vec = fbb.createByteVector(inventory)
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addInventory(fbb, vec)
|
||||
Monster.addName(fbb, str)
|
||||
val monster1 = Monster.endMonster(fbb)
|
||||
Monster.finishMonsterBuffer(fbb, monster1)
|
||||
val monsterObject = Monster.getRootAsMonster(fbb.dataBuffer())
|
||||
|
||||
assert(monsterObject.inventory(1) == inventory[1].toUByte())
|
||||
assert(monsterObject.inventoryLength == inventory.size)
|
||||
assert(ByteBuffer.wrap(inventory) == monsterObject.inventoryAsByteBuffer)
|
||||
}
|
||||
|
||||
fun TestCreateUninitializedVector() {
|
||||
val fbb = FlatBufferBuilder(16)
|
||||
val str = fbb.createString("MyMonster")
|
||||
val inventory = byteArrayOf(0, 1, 2, 3, 4)
|
||||
val bb = fbb.createUnintializedVector(1, inventory.size, 1)
|
||||
for (i in inventory) {
|
||||
bb.put(i)
|
||||
}
|
||||
val vec = fbb.endVector()
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addInventory(fbb, vec)
|
||||
Monster.addName(fbb, str)
|
||||
val monster1 = Monster.endMonster(fbb)
|
||||
Monster.finishMonsterBuffer(fbb, monster1)
|
||||
val monsterObject = Monster.getRootAsMonster(fbb.dataBuffer())
|
||||
|
||||
assert(monsterObject.inventory(1) == inventory[1].toUByte())
|
||||
assert(monsterObject.inventoryLength == inventory.size)
|
||||
assert(ByteBuffer.wrap(inventory) == monsterObject.inventoryAsByteBuffer)
|
||||
}
|
||||
|
||||
fun TestByteBufferFactory() {
|
||||
class MappedByteBufferFactory : FlatBufferBuilder.ByteBufferFactory() {
|
||||
override fun newByteBuffer(capacity: Int): ByteBuffer? {
|
||||
var bb: ByteBuffer?
|
||||
try {
|
||||
bb = RandomAccessFile("javatest.bin", "rw").channel.map(
|
||||
FileChannel.MapMode.READ_WRITE,
|
||||
0,
|
||||
capacity.toLong()
|
||||
).order(ByteOrder.LITTLE_ENDIAN)
|
||||
} catch (e: Throwable) {
|
||||
println("FlatBuffers test: couldn't map ByteBuffer to a file")
|
||||
bb = null
|
||||
}
|
||||
|
||||
return bb
|
||||
}
|
||||
}
|
||||
|
||||
val fbb = FlatBufferBuilder(1, MappedByteBufferFactory())
|
||||
|
||||
TestBuilderBasics(fbb, false)
|
||||
}
|
||||
|
||||
fun TestSizedInputStream() {
|
||||
// Test on default FlatBufferBuilder that uses HeapByteBuffer
|
||||
val fbb = FlatBufferBuilder(1)
|
||||
|
||||
TestBuilderBasics(fbb, false)
|
||||
|
||||
val `in` = fbb.sizedInputStream()
|
||||
val array = fbb.sizedByteArray()
|
||||
var count = 0
|
||||
var currentVal = 0
|
||||
|
||||
while (currentVal != -1 && count < array.size) {
|
||||
try {
|
||||
currentVal = `in`.read()
|
||||
} catch (e: java.io.IOException) {
|
||||
println("FlatBuffers test: couldn't read from InputStream")
|
||||
return
|
||||
}
|
||||
|
||||
assert(currentVal.toByte() == array[count])
|
||||
count++
|
||||
}
|
||||
assert(count == array.size)
|
||||
}
|
||||
|
||||
fun TestBuilderBasics(fbb: FlatBufferBuilder, sizePrefix: Boolean) {
|
||||
val names = intArrayOf(fbb.createString("Frodo"), fbb.createString("Barney"), fbb.createString("Wilma"))
|
||||
val off = IntArray(3)
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addName(fbb, names[0])
|
||||
off[0] = Monster.endMonster(fbb)
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addName(fbb, names[1])
|
||||
off[1] = Monster.endMonster(fbb)
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addName(fbb, names[2])
|
||||
off[2] = Monster.endMonster(fbb)
|
||||
val sortMons = fbb.createSortedVectorOfTables(Monster(), off)
|
||||
|
||||
// We set up the same values as monsterdata.json:
|
||||
|
||||
val str = fbb.createString("MyMonster")
|
||||
|
||||
val inv = Monster.createInventoryVector(fbb, byteArrayOf(0, 1, 2, 3, 4).asUByteArray())
|
||||
|
||||
val fred = fbb.createString("Fred")
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addName(fbb, fred)
|
||||
val mon2 = Monster.endMonster(fbb)
|
||||
|
||||
Monster.startTest4Vector(fbb, 2)
|
||||
Test.createTest(fbb, 10.toShort(), 20.toByte())
|
||||
Test.createTest(fbb, 30.toShort(), 40.toByte())
|
||||
val test4 = fbb.endVector()
|
||||
|
||||
val testArrayOfString =
|
||||
Monster.createTestarrayofstringVector(fbb, intArrayOf(fbb.createString("test1"), fbb.createString("test2")))
|
||||
|
||||
Monster.startMonster(fbb)
|
||||
Monster.addPos(
|
||||
fbb, Vec3.createVec3(
|
||||
fbb, 1.0f, 2.0f, 3.0f, 3.0,
|
||||
Color.Green, 5.toShort(), 6.toByte()
|
||||
)
|
||||
)
|
||||
Monster.addHp(fbb, 80.toShort())
|
||||
Monster.addName(fbb, str)
|
||||
Monster.addInventory(fbb, inv)
|
||||
Monster.addTestType(fbb, Any_.Monster)
|
||||
Monster.addTest(fbb, mon2)
|
||||
Monster.addTest4(fbb, test4)
|
||||
Monster.addTestarrayofstring(fbb, testArrayOfString)
|
||||
Monster.addTestbool(fbb, true)
|
||||
Monster.addTesthashu32Fnv1(fbb, (Integer.MAX_VALUE + 1L).toUInt())
|
||||
Monster.addTestarrayoftables(fbb, sortMons)
|
||||
val mon = Monster.endMonster(fbb)
|
||||
|
||||
if (sizePrefix) {
|
||||
Monster.finishSizePrefixedMonsterBuffer(fbb, mon)
|
||||
} else {
|
||||
Monster.finishMonsterBuffer(fbb, mon)
|
||||
}
|
||||
|
||||
// Write the result to a file for debugging purposes:
|
||||
// Note that the binaries are not necessarily identical, since the JSON
|
||||
// parser may serialize in a slightly different order than the above
|
||||
// Java code. They are functionally equivalent though.
|
||||
|
||||
try {
|
||||
val filename = "monsterdata_java_wire" + (if (sizePrefix) "_sp" else "") + ".mon"
|
||||
val fc = FileOutputStream(filename).channel
|
||||
fc.write(fbb.dataBuffer().duplicate())
|
||||
fc.close()
|
||||
} catch (e: java.io.IOException) {
|
||||
println("FlatBuffers test: couldn't write file")
|
||||
return
|
||||
}
|
||||
|
||||
// Test it:
|
||||
var dataBuffer = fbb.dataBuffer()
|
||||
if (sizePrefix) {
|
||||
assert(
|
||||
ByteBufferUtil.getSizePrefix(dataBuffer) + SIZE_PREFIX_LENGTH ==
|
||||
dataBuffer.remaining()
|
||||
)
|
||||
dataBuffer = ByteBufferUtil.removeSizePrefix(dataBuffer)
|
||||
}
|
||||
TestExtendedBuffer(dataBuffer)
|
||||
|
||||
// Make sure it also works with read only ByteBuffers. This is slower,
|
||||
// since creating strings incurs an additional copy
|
||||
// (see Table.__string).
|
||||
TestExtendedBuffer(dataBuffer.asReadOnlyBuffer())
|
||||
|
||||
TestEnums()
|
||||
|
||||
//Attempt to mutate Monster fields and check whether the buffer has been mutated properly
|
||||
// revert to original values after testing
|
||||
val monster = Monster.getRootAsMonster(dataBuffer)
|
||||
|
||||
// mana is optional and does not exist in the buffer so the mutation should fail
|
||||
// the mana field should retain its default value
|
||||
assert(monster.mutateMana(10.toShort()) == false)
|
||||
assert(monster.mana == 150.toShort())
|
||||
|
||||
// Accessing a vector of sorted by the key tables
|
||||
assert(monster.testarrayoftables(0)!!.name == "Barney")
|
||||
assert(monster.testarrayoftables(1)!!.name == "Frodo")
|
||||
assert(monster.testarrayoftables(2)!!.name == "Wilma")
|
||||
|
||||
// Example of searching for a table by the key
|
||||
assert(monster.testarrayoftablesByKey("Frodo")!!.name == "Frodo")
|
||||
assert(monster.testarrayoftablesByKey("Barney")!!.name == "Barney")
|
||||
assert(monster.testarrayoftablesByKey("Wilma")!!.name == "Wilma")
|
||||
|
||||
// testType is an existing field and mutating it should succeed
|
||||
assert(monster.testType == Any_.Monster)
|
||||
assert(monster.mutateTestType(Any_.NONE) == true)
|
||||
assert(monster.testType == Any_.NONE)
|
||||
assert(monster.mutateTestType(Any_.Monster) == true)
|
||||
assert(monster.testType == Any_.Monster)
|
||||
|
||||
//mutate the inventory vector
|
||||
assert(monster.mutateInventory(0, 1u) == true)
|
||||
assert(monster.mutateInventory(1, 2u) == true)
|
||||
assert(monster.mutateInventory(2, 3u) == true)
|
||||
assert(monster.mutateInventory(3, 4u) == true)
|
||||
assert(monster.mutateInventory(4, 5u) == true)
|
||||
|
||||
for (i in 0 until monster.inventoryLength) {
|
||||
assert(monster.inventory(i) == (i.toUByte() + 1u).toUByte())
|
||||
}
|
||||
|
||||
//reverse mutation
|
||||
assert(monster.mutateInventory(0, 0u) == true)
|
||||
assert(monster.mutateInventory(1, 1u) == true)
|
||||
assert(monster.mutateInventory(2, 2u) == true)
|
||||
assert(monster.mutateInventory(3, 3u) == true)
|
||||
assert(monster.mutateInventory(4, 4u) == true)
|
||||
|
||||
// get a struct field and edit one of its fields
|
||||
val pos = monster.pos!!
|
||||
assert(pos.x == 1.0f)
|
||||
pos.mutateX(55.0f)
|
||||
assert(pos.x == 55.0f)
|
||||
pos.mutateX(1.0f)
|
||||
assert(pos.x == 1.0f)
|
||||
}
|
||||
|
||||
fun TestVectorOfUnions() {
|
||||
val fbb = FlatBufferBuilder()
|
||||
|
||||
val swordAttackDamage = 1
|
||||
|
||||
val characterVector = intArrayOf(Attacker.createAttacker(fbb, swordAttackDamage))
|
||||
|
||||
val characterTypeVector = ubyteArrayOf(Character_.MuLan)
|
||||
|
||||
Movie.finishMovieBuffer(
|
||||
fbb,
|
||||
Movie.createMovie(
|
||||
fbb,
|
||||
0u,
|
||||
0,
|
||||
Movie.createCharactersTypeVector(fbb, characterTypeVector),
|
||||
Movie.createCharactersVector(fbb, characterVector)
|
||||
)
|
||||
)
|
||||
|
||||
val movie = Movie.getRootAsMovie(fbb.dataBuffer())
|
||||
|
||||
assert(movie.charactersTypeLength == characterTypeVector.size)
|
||||
assert(movie.charactersLength == characterVector.size)
|
||||
|
||||
assert(movie.charactersType(0) == characterTypeVector[0])
|
||||
|
||||
assert((movie.characters(Attacker(), 0) as Attacker).swordAttackDamage == swordAttackDamage)
|
||||
}
|
||||
|
||||
fun TestSharedStringPool() {
|
||||
val fb = FlatBufferBuilder(1);
|
||||
val testString = "My string";
|
||||
val offset = fb.createSharedString(testString);
|
||||
for (i in 0..10) {
|
||||
assert(offset == fb.createSharedString(testString));
|
||||
}
|
||||
}
|
||||
|
||||
fun TestScalarOptional() {
|
||||
val fbb = FlatBufferBuilder(1)
|
||||
ScalarStuff.startScalarStuff(fbb)
|
||||
var pos = ScalarStuff.endScalarStuff(fbb)
|
||||
fbb.finish(pos)
|
||||
|
||||
var scalarStuff = ScalarStuff.getRootAsScalarStuff(fbb.dataBuffer())
|
||||
|
||||
assert(scalarStuff.justI8 == 0.toByte())
|
||||
assert(scalarStuff.maybeI8 == null)
|
||||
assert(scalarStuff.defaultI8 == 42.toByte())
|
||||
assert(scalarStuff.justU8 == 0.toUByte())
|
||||
assert(scalarStuff.maybeU8 == null)
|
||||
assert(scalarStuff.defaultU8 == 42.toUByte())
|
||||
assert(scalarStuff.justI16 == 0.toShort())
|
||||
assert(scalarStuff.maybeI16 == null)
|
||||
assert(scalarStuff.defaultI16 == 42.toShort())
|
||||
assert(scalarStuff.justU16 == 0.toUShort())
|
||||
assert(scalarStuff.maybeU16 == null)
|
||||
assert(scalarStuff.defaultU16 == 42.toUShort())
|
||||
assert(scalarStuff.justI32 == 0)
|
||||
assert(scalarStuff.maybeI32 == null)
|
||||
assert(scalarStuff.defaultI32 == 42)
|
||||
assert(scalarStuff.justU32 == 0.toUInt())
|
||||
assert(scalarStuff.maybeU32 == null)
|
||||
assert(scalarStuff.defaultU32 == 42U)
|
||||
assert(scalarStuff.justI64 == 0L)
|
||||
assert(scalarStuff.maybeI64 == null)
|
||||
assert(scalarStuff.defaultI64 == 42L)
|
||||
assert(scalarStuff.justU64 == 0UL)
|
||||
assert(scalarStuff.maybeU64 == null)
|
||||
assert(scalarStuff.defaultU64 == 42UL)
|
||||
assert(scalarStuff.justF32 == 0.0f)
|
||||
assert(scalarStuff.maybeF32 == null)
|
||||
assert(scalarStuff.defaultF32 == 42.0f)
|
||||
assert(scalarStuff.justF64 == 0.0)
|
||||
assert(scalarStuff.maybeF64 == null)
|
||||
assert(scalarStuff.defaultF64 == 42.0)
|
||||
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()
|
||||
|
||||
ScalarStuff.startScalarStuff(fbb)
|
||||
ScalarStuff.addJustI8(fbb, 5.toByte())
|
||||
ScalarStuff.addMaybeI8(fbb, 5.toByte())
|
||||
ScalarStuff.addDefaultI8(fbb, 5.toByte())
|
||||
ScalarStuff.addJustU8(fbb, 6.toUByte())
|
||||
ScalarStuff.addMaybeU8(fbb, 6.toUByte())
|
||||
ScalarStuff.addDefaultU8(fbb, 6.toUByte())
|
||||
ScalarStuff.addJustI16(fbb, 7.toShort())
|
||||
ScalarStuff.addMaybeI16(fbb, 7.toShort())
|
||||
ScalarStuff.addDefaultI16(fbb, 7.toShort())
|
||||
ScalarStuff.addJustU16(fbb, 8.toUShort())
|
||||
ScalarStuff.addMaybeU16(fbb, 8.toUShort())
|
||||
ScalarStuff.addDefaultU16(fbb, 8.toUShort())
|
||||
ScalarStuff.addJustI32(fbb, 9)
|
||||
ScalarStuff.addMaybeI32(fbb, 9)
|
||||
ScalarStuff.addDefaultI32(fbb, 9)
|
||||
ScalarStuff.addJustU32(fbb, 10.toUInt())
|
||||
ScalarStuff.addMaybeU32(fbb, 10.toUInt())
|
||||
ScalarStuff.addDefaultU32(fbb, 10.toUInt())
|
||||
ScalarStuff.addJustI64(fbb, 11L)
|
||||
ScalarStuff.addMaybeI64(fbb, 11L)
|
||||
ScalarStuff.addDefaultI64(fbb, 11L)
|
||||
ScalarStuff.addJustU64(fbb, 12UL)
|
||||
ScalarStuff.addMaybeU64(fbb, 12UL)
|
||||
ScalarStuff.addDefaultU64(fbb, 12UL)
|
||||
ScalarStuff.addJustF32(fbb, 13.0f)
|
||||
ScalarStuff.addMaybeF32(fbb, 13.0f)
|
||||
ScalarStuff.addDefaultF32(fbb, 13.0f)
|
||||
ScalarStuff.addJustF64(fbb, 14.0)
|
||||
ScalarStuff.addMaybeF64(fbb, 14.0)
|
||||
ScalarStuff.addDefaultF64(fbb, 14.0)
|
||||
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)
|
||||
|
||||
fbb.finish(pos)
|
||||
|
||||
scalarStuff = ScalarStuff.getRootAsScalarStuff(fbb.dataBuffer())
|
||||
|
||||
assert(scalarStuff.justI8 == 5.toByte())
|
||||
assert(scalarStuff.maybeI8 == 5.toByte())
|
||||
assert(scalarStuff.defaultI8 == 5.toByte())
|
||||
assert(scalarStuff.justU8 == 6.toUByte())
|
||||
assert(scalarStuff.maybeU8 == 6.toUByte())
|
||||
assert(scalarStuff.defaultU8 == 6.toUByte())
|
||||
assert(scalarStuff.justI16 == 7.toShort())
|
||||
assert(scalarStuff.maybeI16 == 7.toShort())
|
||||
assert(scalarStuff.defaultI16 == 7.toShort())
|
||||
assert(scalarStuff.justU16 == 8.toUShort())
|
||||
assert(scalarStuff.maybeU16 == 8.toUShort())
|
||||
assert(scalarStuff.defaultU16 == 8.toUShort())
|
||||
assert(scalarStuff.justI32 == 9)
|
||||
assert(scalarStuff.maybeI32 == 9)
|
||||
assert(scalarStuff.defaultI32 == 9)
|
||||
assert(scalarStuff.justU32 == 10u)
|
||||
assert(scalarStuff.maybeU32 == 10u)
|
||||
assert(scalarStuff.defaultU32 == 10u)
|
||||
assert(scalarStuff.justI64 == 11L)
|
||||
assert(scalarStuff.maybeI64 == 11L)
|
||||
assert(scalarStuff.defaultI64 == 11L)
|
||||
assert(scalarStuff.justU64 == 12UL)
|
||||
assert(scalarStuff.maybeU64 == 12UL)
|
||||
assert(scalarStuff.defaultU64 == 12UL)
|
||||
assert(scalarStuff.justF32 == 13.0f)
|
||||
assert(scalarStuff.maybeF32 == 13.0f)
|
||||
assert(scalarStuff.defaultF32 == 13.0f)
|
||||
assert(scalarStuff.justF64 == 14.0)
|
||||
assert(scalarStuff.maybeF64 == 14.0)
|
||||
assert(scalarStuff.defaultF64 == 14.0)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright 2014 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
echo Compile then run the Kotlin test.
|
||||
|
||||
testdir=$(dirname $0)
|
||||
targetdir="${testdir}/kotlin"
|
||||
|
||||
if [[ -e "${targetdir}" ]]; then
|
||||
echo "cleaning target"
|
||||
rm -rf "${targetdir}"
|
||||
fi
|
||||
|
||||
mkdir -v "${targetdir}"
|
||||
|
||||
if ! find "${testdir}/../java" -type f -name "*.class" -delete; then
|
||||
echo "failed to clean .class files from java directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
all_kt_files=`find . -name "*.kt" -print`
|
||||
|
||||
# Compile java FlatBuffer library
|
||||
javac ${testdir}/../java/src/main/java/com/google/flatbuffers/*.java -d $targetdir
|
||||
# Compile Kotlin files
|
||||
kotlinc $all_kt_files -classpath $targetdir -include-runtime -d $targetdir
|
||||
# Make jar
|
||||
jar cvf ${testdir}/kotlin_test.jar -C $targetdir . > /dev/null
|
||||
# Run test
|
||||
kotlin -J"-ea" -cp ${testdir}/kotlin_test.jar KotlinTest
|
||||
# clean up
|
||||
rm -rf $targetdir
|
||||
rm ${testdir}/kotlin_test.jar
|
||||
@@ -0,0 +1,3 @@
|
||||
..\Release\flatc.exe --lobster -I include_test monster_test.fbs
|
||||
..\Release\flatc.exe --lobster -I include_test optional_scalars.fbs
|
||||
..\..\lobster\bin\lobster.exe .\lobstertest.lobster
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
set buildtype=Release
|
||||
if "%1"=="-b" set buildtype=%2
|
||||
|
||||
echo Run with LuaJIT:
|
||||
luajit.exe luatest.lua
|
||||
echo Run with Lua 5.3:
|
||||
lua53.exe luatest.lua
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# Copyright 2019 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
pushd "$(dirname $0)" >/dev/null
|
||||
test_dir="$(pwd)"
|
||||
|
||||
declare -a versions=(luajit lua5.1 lua5.2 lua5.3 lua5.4)
|
||||
|
||||
for i in "${versions[@]}"
|
||||
do
|
||||
if command -v $i &> /dev/null
|
||||
then
|
||||
echo "[$i]"
|
||||
$i luatest.lua
|
||||
fi
|
||||
done
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#[ MoreDefaults
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by :
|
||||
]#
|
||||
|
||||
import Abc as Abc
|
||||
import flatbuffers
|
||||
|
||||
type MoreDefaults* = object of FlatObj
|
||||
func intsLength*(self: MoreDefaults): int =
|
||||
let o = self.tab.Offset(4)
|
||||
if o != 0:
|
||||
return self.tab.VectorLen(o)
|
||||
func ints*(self: MoreDefaults, j: int): int32 =
|
||||
let o = self.tab.Offset(4)
|
||||
if o != 0:
|
||||
var x = self.tab.Vector(o)
|
||||
x += j.uoffset * 4.uoffset
|
||||
return Get[int32](self.tab, x)
|
||||
func ints*(self: MoreDefaults): seq[int32] =
|
||||
let len = self.intsLength
|
||||
for i in countup(0, len - 1):
|
||||
result.add(self.ints(i))
|
||||
func floatsLength*(self: MoreDefaults): int =
|
||||
let o = self.tab.Offset(6)
|
||||
if o != 0:
|
||||
return self.tab.VectorLen(o)
|
||||
func floats*(self: MoreDefaults, j: int): float32 =
|
||||
let o = self.tab.Offset(6)
|
||||
if o != 0:
|
||||
var x = self.tab.Vector(o)
|
||||
x += j.uoffset * 4.uoffset
|
||||
return Get[float32](self.tab, x)
|
||||
func floats*(self: MoreDefaults): seq[float32] =
|
||||
let len = self.floatsLength
|
||||
for i in countup(0, len - 1):
|
||||
result.add(self.floats(i))
|
||||
func emptyString*(self: MoreDefaults): string =
|
||||
let o = self.tab.Offset(8)
|
||||
if o != 0:
|
||||
return self.tab.String(self.tab.Pos + o)
|
||||
return ""
|
||||
func someString*(self: MoreDefaults): string =
|
||||
let o = self.tab.Offset(10)
|
||||
if o != 0:
|
||||
return self.tab.String(self.tab.Pos + o)
|
||||
return ""
|
||||
func abcsLength*(self: MoreDefaults): int =
|
||||
let o = self.tab.Offset(12)
|
||||
if o != 0:
|
||||
return self.tab.VectorLen(o)
|
||||
func abcs*(self: MoreDefaults, j: int): Abc.Abc =
|
||||
let o = self.tab.Offset(12)
|
||||
if o != 0:
|
||||
var x = self.tab.Vector(o)
|
||||
x += j.uoffset * 4.uoffset
|
||||
return Abc.Abc(Get[int32](self.tab, x))
|
||||
func abcs*(self: MoreDefaults): seq[Abc.Abc] =
|
||||
let len = self.abcsLength
|
||||
for i in countup(0, len - 1):
|
||||
result.add(self.abcs(i))
|
||||
func boolsLength*(self: MoreDefaults): int =
|
||||
let o = self.tab.Offset(14)
|
||||
if o != 0:
|
||||
return self.tab.VectorLen(o)
|
||||
func bools*(self: MoreDefaults, j: int): bool =
|
||||
let o = self.tab.Offset(14)
|
||||
if o != 0:
|
||||
var x = self.tab.Vector(o)
|
||||
x += j.uoffset * 1.uoffset
|
||||
return Get[bool](self.tab, x)
|
||||
func bools*(self: MoreDefaults): seq[bool] =
|
||||
let len = self.boolsLength
|
||||
for i in countup(0, len - 1):
|
||||
result.add(self.bools(i))
|
||||
proc MoreDefaultsStart*(builder: var Builder) =
|
||||
builder.StartObject(6)
|
||||
proc MoreDefaultsAddints*(builder: var Builder, ints: uoffset) =
|
||||
builder.PrependSlot(0, ints, default(uoffset))
|
||||
proc MoreDefaultsStartintsVector*(builder: var Builder, numElems: uoffset) =
|
||||
builder.StartVector(4, numElems, 4)
|
||||
proc MoreDefaultsAddfloats*(builder: var Builder, floats: uoffset) =
|
||||
builder.PrependSlot(1, floats, default(uoffset))
|
||||
proc MoreDefaultsStartfloatsVector*(builder: var Builder, numElems: uoffset) =
|
||||
builder.StartVector(4, numElems, 4)
|
||||
proc MoreDefaultsAddemptyString*(builder: var Builder, emptyString: uoffset) =
|
||||
builder.PrependSlot(2, emptyString, default(uoffset))
|
||||
proc MoreDefaultsAddsomeString*(builder: var Builder, someString: uoffset) =
|
||||
builder.PrependSlot(3, someString, default(uoffset))
|
||||
proc MoreDefaultsAddabcs*(builder: var Builder, abcs: uoffset) =
|
||||
builder.PrependSlot(4, abcs, default(uoffset))
|
||||
proc MoreDefaultsStartabcsVector*(builder: var Builder, numElems: uoffset) =
|
||||
builder.StartVector(4, numElems, 4)
|
||||
proc MoreDefaultsAddbools*(builder: var Builder, bools: uoffset) =
|
||||
builder.PrependSlot(5, bools, default(uoffset))
|
||||
proc MoreDefaultsStartboolsVector*(builder: var Builder, numElems: uoffset) =
|
||||
builder.StartVector(1, numElems, 1)
|
||||
proc MoreDefaultsEnd*(builder: var Builder): uoffset =
|
||||
return builder.EndObject()
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
struct Property {
|
||||
property: bool;
|
||||
}
|
||||
|
||||
table TestMutatingBool {
|
||||
b: Property;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct Ability : IFlatbufferObject
|
||||
{
|
||||
private Struct __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
|
||||
public Ability __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public uint Id { get { return __p.bb.GetUint(__p.bb_pos + 0); } }
|
||||
public void MutateId(uint id) { __p.bb.PutUint(__p.bb_pos + 0, id); }
|
||||
public uint Distance { get { return __p.bb.GetUint(__p.bb_pos + 4); } }
|
||||
public void MutateDistance(uint distance) { __p.bb.PutUint(__p.bb_pos + 4, distance); }
|
||||
|
||||
public static Offset<MyGame.Example.Ability> CreateAbility(FlatBufferBuilder builder, uint Id, uint Distance) {
|
||||
builder.Prep(4, 8);
|
||||
builder.PutUint(Distance);
|
||||
builder.PutUint(Id);
|
||||
return new Offset<MyGame.Example.Ability>(builder.Offset);
|
||||
}
|
||||
public AbilityT UnPack() {
|
||||
var _o = new AbilityT();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(AbilityT _o) {
|
||||
_o.Id = this.Id;
|
||||
_o.Distance = this.Distance;
|
||||
}
|
||||
public static Offset<MyGame.Example.Ability> Pack(FlatBufferBuilder builder, AbilityT _o) {
|
||||
if (_o == null) return default(Offset<MyGame.Example.Ability>);
|
||||
return CreateAbility(
|
||||
builder,
|
||||
_o.Id,
|
||||
_o.Distance);
|
||||
}
|
||||
}
|
||||
|
||||
public class AbilityT
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
public uint Id { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("distance")]
|
||||
public uint Distance { get; set; }
|
||||
|
||||
public AbilityT() {
|
||||
this.Id = 0;
|
||||
this.Distance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Example
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
|
||||
type AbilityT struct {
|
||||
Id uint32 `json:"id"`
|
||||
Distance uint32 `json:"distance"`
|
||||
}
|
||||
|
||||
func (t *AbilityT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
return CreateAbility(builder, t.Id, t.Distance)
|
||||
}
|
||||
func (rcv *Ability) UnPackTo(t *AbilityT) {
|
||||
t.Id = rcv.Id()
|
||||
t.Distance = rcv.Distance()
|
||||
}
|
||||
|
||||
func (rcv *Ability) UnPack() *AbilityT {
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &AbilityT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
}
|
||||
|
||||
type Ability struct {
|
||||
_tab flatbuffers.Struct
|
||||
}
|
||||
|
||||
func (rcv *Ability) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
}
|
||||
|
||||
func (rcv *Ability) Table() flatbuffers.Table {
|
||||
return rcv._tab.Table
|
||||
}
|
||||
|
||||
func (rcv *Ability) Id() uint32 {
|
||||
return rcv._tab.GetUint32(rcv._tab.Pos + flatbuffers.UOffsetT(0))
|
||||
}
|
||||
func (rcv *Ability) MutateId(n uint32) bool {
|
||||
return rcv._tab.MutateUint32(rcv._tab.Pos+flatbuffers.UOffsetT(0), n)
|
||||
}
|
||||
|
||||
func (rcv *Ability) Distance() uint32 {
|
||||
return rcv._tab.GetUint32(rcv._tab.Pos + flatbuffers.UOffsetT(4))
|
||||
}
|
||||
func (rcv *Ability) MutateDistance(n uint32) bool {
|
||||
return rcv._tab.MutateUint32(rcv._tab.Pos+flatbuffers.UOffsetT(4), n)
|
||||
}
|
||||
|
||||
func CreateAbility(builder *flatbuffers.Builder, id uint32, distance uint32) flatbuffers.UOffsetT {
|
||||
builder.Prep(4, 8)
|
||||
builder.PrependUint32(distance)
|
||||
builder.PrependUint32(id)
|
||||
return builder.Offset()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Ability extends Struct {
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Ability __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public long id() { return (long)bb.getInt(bb_pos + 0) & 0xFFFFFFFFL; }
|
||||
public void mutateId(long id) { bb.putInt(bb_pos + 0, (int) id); }
|
||||
public long distance() { return (long)bb.getInt(bb_pos + 4) & 0xFFFFFFFFL; }
|
||||
public void mutateDistance(long distance) { bb.putInt(bb_pos + 4, (int) distance); }
|
||||
|
||||
public static int createAbility(FlatBufferBuilder builder, long id, long distance) {
|
||||
builder.prep(4, 8);
|
||||
builder.putInt((int) distance);
|
||||
builder.putInt((int) id);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Ability get(int j) { return get(new Ability(), j); }
|
||||
public Ability get(Ability obj, int j) { return obj.__assign(__element(j), bb); }
|
||||
}
|
||||
public AbilityT unpack() {
|
||||
AbilityT _o = new AbilityT();
|
||||
unpackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void unpackTo(AbilityT _o) {
|
||||
long _oId = id();
|
||||
_o.setId(_oId);
|
||||
long _oDistance = distance();
|
||||
_o.setDistance(_oDistance);
|
||||
}
|
||||
public static int pack(FlatBufferBuilder builder, AbilityT _o) {
|
||||
if (_o == null) return 0;
|
||||
return createAbility(
|
||||
builder,
|
||||
_o.getId(),
|
||||
_o.getDistance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example
|
||||
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
|
||||
@Suppress("unused")
|
||||
class Ability : Struct() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
}
|
||||
fun __assign(_i: Int, _bb: ByteBuffer) : Ability {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
}
|
||||
val id : UInt get() = bb.getInt(bb_pos + 0).toUInt()
|
||||
fun mutateId(id: UInt) : ByteBuffer = bb.putInt(bb_pos + 0, id.toInt())
|
||||
val distance : UInt get() = bb.getInt(bb_pos + 4).toUInt()
|
||||
fun mutateDistance(distance: UInt) : ByteBuffer = bb.putInt(bb_pos + 4, distance.toInt())
|
||||
companion object {
|
||||
fun createAbility(builder: FlatBufferBuilder, id: UInt, distance: UInt) : Int {
|
||||
builder.prep(4, 8)
|
||||
builder.putInt(distance.toInt())
|
||||
builder.putInt(id.toInt())
|
||||
return builder.offset()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
--[[ MyGame.Example.Ability
|
||||
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by : //monster_test.fbs
|
||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||
|
||||
--]]
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Ability = {}
|
||||
local mt = {}
|
||||
|
||||
function Ability.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = mt})
|
||||
return o
|
||||
end
|
||||
|
||||
function mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
|
||||
function mt:Id()
|
||||
return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 0)
|
||||
end
|
||||
|
||||
function mt:Distance()
|
||||
return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 4)
|
||||
end
|
||||
|
||||
function Ability.CreateAbility(builder, id, distance)
|
||||
builder:Prep(4, 8)
|
||||
builder:PrependUint32(distance)
|
||||
builder:PrependUint32(id)
|
||||
return builder:Offset()
|
||||
end
|
||||
|
||||
return Ability
|
||||
@@ -0,0 +1,26 @@
|
||||
#[ MyGame.Example.Ability
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by :
|
||||
Rooting type : MyGame.Example.Monster ()
|
||||
]#
|
||||
|
||||
import flatbuffers
|
||||
|
||||
type Ability* = object of FlatObj
|
||||
func id*(self: Ability): uint32 =
|
||||
return Get[uint32](self.tab, self.tab.Pos + 0)
|
||||
func `id=`*(self: var Ability, n: uint32): bool =
|
||||
return self.tab.Mutate(self.tab.Pos + 0, n)
|
||||
func distance*(self: Ability): uint32 =
|
||||
return Get[uint32](self.tab, self.tab.Pos + 4)
|
||||
func `distance=`*(self: var Ability, n: uint32): bool =
|
||||
return self.tab.Mutate(self.tab.Pos + 4, n)
|
||||
proc AbilityCreate*(self: var Builder, id: uint32, distance: uint32): uoffset =
|
||||
self.Prep(4, 8)
|
||||
self.Prepend(distance)
|
||||
self.Prepend(id)
|
||||
return self.Offset()
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame\Example;
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
use \Google\FlatBuffers\FlatBufferBuilder;
|
||||
|
||||
class Ability extends Struct
|
||||
{
|
||||
/**
|
||||
* @param int $_i offset
|
||||
* @param ByteBuffer $_bb
|
||||
* @return Ability
|
||||
**/
|
||||
public function init($_i, ByteBuffer $_bb)
|
||||
{
|
||||
$this->bb_pos = $_i;
|
||||
$this->bb = $_bb;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return uint
|
||||
*/
|
||||
public function GetId()
|
||||
{
|
||||
return $this->bb->getUint($this->bb_pos + 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return uint
|
||||
*/
|
||||
public function GetDistance()
|
||||
{
|
||||
return $this->bb->getUint($this->bb_pos + 4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int offset
|
||||
*/
|
||||
public static function createAbility(FlatBufferBuilder $builder, $id, $distance)
|
||||
{
|
||||
$builder->prep(4, 8);
|
||||
$builder->putUint($distance);
|
||||
$builder->putUint($id);
|
||||
return $builder->offset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
np = import_numpy()
|
||||
|
||||
class Ability(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def SizeOf(cls):
|
||||
return 8
|
||||
|
||||
# Ability
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# Ability
|
||||
def Id(self): return self._tab.Get(flatbuffers.number_types.Uint32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0))
|
||||
# Ability
|
||||
def Distance(self): return self._tab.Get(flatbuffers.number_types.Uint32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4))
|
||||
|
||||
def CreateAbility(builder, id, distance):
|
||||
builder.Prep(4, 8)
|
||||
builder.PrependUint32(distance)
|
||||
builder.PrependUint32(id)
|
||||
return builder.Offset()
|
||||
|
||||
|
||||
class AbilityT(object):
|
||||
|
||||
# AbilityT
|
||||
def __init__(self):
|
||||
self.id = 0 # type: int
|
||||
self.distance = 0 # type: int
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
ability = Ability()
|
||||
ability.Init(buf, pos)
|
||||
return cls.InitFromObj(ability)
|
||||
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf, pos=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||
return cls.InitFromBuf(buf, pos+n)
|
||||
|
||||
@classmethod
|
||||
def InitFromObj(cls, ability):
|
||||
x = AbilityT()
|
||||
x._UnPack(ability)
|
||||
return x
|
||||
|
||||
# AbilityT
|
||||
def _UnPack(self, ability):
|
||||
if ability is None:
|
||||
return
|
||||
self.id = ability.Id()
|
||||
self.distance = ability.Distance()
|
||||
|
||||
# AbilityT
|
||||
def Pack(self, builder):
|
||||
return CreateAbility(builder, self.id, self.distance)
|
||||
@@ -0,0 +1,40 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class AbilityT {
|
||||
private long id;
|
||||
private long distance;
|
||||
|
||||
public long getId() { return id; }
|
||||
|
||||
public void setId(long id) { this.id = id; }
|
||||
|
||||
public long getDistance() { return distance; }
|
||||
|
||||
public void setDistance(long distance) { this.distance = distance; }
|
||||
|
||||
|
||||
public AbilityT() {
|
||||
this.id = 0L;
|
||||
this.distance = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public enum Any : byte
|
||||
{
|
||||
NONE = 0,
|
||||
Monster = 1,
|
||||
TestSimpleTableWithEnum = 2,
|
||||
MyGame_Example2_Monster = 3,
|
||||
};
|
||||
|
||||
public class AnyUnion {
|
||||
public Any Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public AnyUnion() {
|
||||
this.Type = Any.NONE;
|
||||
this.Value = null;
|
||||
}
|
||||
|
||||
public T As<T>() where T : class { return this.Value as T; }
|
||||
public MyGame.Example.MonsterT AsMonster() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public static AnyUnion FromMonster(MyGame.Example.MonsterT _monster) { return new AnyUnion{ Type = Any.Monster, Value = _monster }; }
|
||||
internal MyGame.Example.TestSimpleTableWithEnumT AsTestSimpleTableWithEnum() { return this.As<MyGame.Example.TestSimpleTableWithEnumT>(); }
|
||||
internal static AnyUnion FromTestSimpleTableWithEnum(MyGame.Example.TestSimpleTableWithEnumT _testsimpletablewithenum) { return new AnyUnion{ Type = Any.TestSimpleTableWithEnum, Value = _testsimpletablewithenum }; }
|
||||
public MyGame.Example2.MonsterT AsMyGame_Example2_Monster() { return this.As<MyGame.Example2.MonsterT>(); }
|
||||
public static AnyUnion FromMyGame_Example2_Monster(MyGame.Example2.MonsterT _mygame_example2_monster) { return new AnyUnion{ Type = Any.MyGame_Example2_Monster, Value = _mygame_example2_monster }; }
|
||||
|
||||
public static int Pack(Google.FlatBuffers.FlatBufferBuilder builder, AnyUnion _o) {
|
||||
switch (_o.Type) {
|
||||
default: return 0;
|
||||
case Any.Monster: return MyGame.Example.Monster.Pack(builder, _o.AsMonster()).Value;
|
||||
case Any.TestSimpleTableWithEnum: return MyGame.Example.TestSimpleTableWithEnum.Pack(builder, _o.AsTestSimpleTableWithEnum()).Value;
|
||||
case Any.MyGame_Example2_Monster: return MyGame.Example2.Monster.Pack(builder, _o.AsMyGame_Example2_Monster()).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnyUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
|
||||
public override bool CanConvert(System.Type objectType) {
|
||||
return objectType == typeof(AnyUnion) || objectType == typeof(System.Collections.Generic.List<AnyUnion>);
|
||||
}
|
||||
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = value as System.Collections.Generic.List<AnyUnion>;
|
||||
if (_olist != null) {
|
||||
writer.WriteStartArray();
|
||||
foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
|
||||
writer.WriteEndArray();
|
||||
} else {
|
||||
this.WriteJson(writer, value as AnyUnion, serializer);
|
||||
}
|
||||
}
|
||||
public void WriteJson(Newtonsoft.Json.JsonWriter writer, AnyUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return;
|
||||
serializer.Serialize(writer, _o.Value);
|
||||
}
|
||||
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = existingValue as System.Collections.Generic.List<AnyUnion>;
|
||||
if (_olist != null) {
|
||||
for (var _j = 0; _j < _olist.Count; ++_j) {
|
||||
reader.Read();
|
||||
_olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
|
||||
}
|
||||
reader.Read();
|
||||
return _olist;
|
||||
} else {
|
||||
return this.ReadJson(reader, existingValue as AnyUnion, serializer);
|
||||
}
|
||||
}
|
||||
public AnyUnion ReadJson(Newtonsoft.Json.JsonReader reader, AnyUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return null;
|
||||
switch (_o.Type) {
|
||||
default: break;
|
||||
case Any.Monster: _o.Value = serializer.Deserialize<MyGame.Example.MonsterT>(reader); break;
|
||||
case Any.TestSimpleTableWithEnum: _o.Value = serializer.Deserialize<MyGame.Example.TestSimpleTableWithEnumT>(reader); break;
|
||||
case Any.MyGame_Example2_Monster: _o.Value = serializer.Deserialize<MyGame.Example2.MonsterT>(reader); break;
|
||||
}
|
||||
return _o;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static public class AnyVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, byte typeId, uint tablePos)
|
||||
{
|
||||
bool result = true;
|
||||
switch((Any)typeId)
|
||||
{
|
||||
case Any.Monster:
|
||||
result = MyGame.Example.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case Any.TestSimpleTableWithEnum:
|
||||
result = MyGame.Example.TestSimpleTableWithEnumVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case Any.MyGame_Example2_Monster:
|
||||
result = MyGame.Example2.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
default: result = true;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Example
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
|
||||
MyGame__Example2 "MyGame/Example2"
|
||||
)
|
||||
|
||||
type Any byte
|
||||
|
||||
const (
|
||||
AnyNONE Any = 0
|
||||
AnyMonster Any = 1
|
||||
AnyTestSimpleTableWithEnum Any = 2
|
||||
AnyMyGame_Example2_Monster Any = 3
|
||||
)
|
||||
|
||||
var EnumNamesAny = map[Any]string{
|
||||
AnyNONE: "NONE",
|
||||
AnyMonster: "Monster",
|
||||
AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
|
||||
AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
|
||||
}
|
||||
|
||||
var EnumValuesAny = map[string]Any{
|
||||
"NONE": AnyNONE,
|
||||
"Monster": AnyMonster,
|
||||
"TestSimpleTableWithEnum": AnyTestSimpleTableWithEnum,
|
||||
"MyGame_Example2_Monster": AnyMyGame_Example2_Monster,
|
||||
}
|
||||
|
||||
func (v Any) String() string {
|
||||
if s, ok := EnumNamesAny[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "Any(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
||||
type AnyT struct {
|
||||
Type Any
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (t *AnyT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
switch t.Type {
|
||||
case AnyMonster:
|
||||
return t.Value.(*MonsterT).Pack(builder)
|
||||
case AnyTestSimpleTableWithEnum:
|
||||
return t.Value.(*TestSimpleTableWithEnumT).Pack(builder)
|
||||
case AnyMyGame_Example2_Monster:
|
||||
return t.Value.(*MyGame__Example2.MonsterT).Pack(builder)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv Any) UnPack(table flatbuffers.Table) *AnyT {
|
||||
switch rcv {
|
||||
case AnyMonster:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyT{Type: AnyMonster, Value: x.UnPack()}
|
||||
case AnyTestSimpleTableWithEnum:
|
||||
var x TestSimpleTableWithEnum
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyT{Type: AnyTestSimpleTableWithEnum, Value: x.UnPack()}
|
||||
case AnyMyGame_Example2_Monster:
|
||||
var x MyGame__Example2.Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyT{Type: AnyMyGame_Example2_Monster, Value: x.UnPack()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Any {
|
||||
private Any() { }
|
||||
public static final byte NONE = 0;
|
||||
public static final byte Monster = 1;
|
||||
public static final byte TestSimpleTableWithEnum = 2;
|
||||
public static final byte MyGame_Example2_Monster = 3;
|
||||
|
||||
public static final String[] names = { "NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example
|
||||
|
||||
@Suppress("unused")
|
||||
class Any_ private constructor() {
|
||||
companion object {
|
||||
const val NONE: UByte = 0u
|
||||
const val Monster: UByte = 1u
|
||||
const val TestSimpleTableWithEnum: UByte = 2u
|
||||
const val MyGame_Example2_Monster: UByte = 3u
|
||||
val names : Array<String> = arrayOf("NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster")
|
||||
fun name(e: Int) : String = names[e]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
--[[ MyGame.Example.Any
|
||||
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by : //monster_test.fbs
|
||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||
|
||||
--]]
|
||||
|
||||
local Any = {
|
||||
NONE = 0,
|
||||
Monster = 1,
|
||||
TestSimpleTableWithEnum = 2,
|
||||
MyGame_Example2_Monster = 3,
|
||||
}
|
||||
|
||||
return Any
|
||||
@@ -0,0 +1,15 @@
|
||||
#[ MyGame.Example.Any
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by :
|
||||
Rooting type : MyGame.Example.Monster ()
|
||||
]#
|
||||
|
||||
type Any*{.pure.} = enum
|
||||
None = 0.uint8,
|
||||
Monster = 1.uint8,
|
||||
TestSimpleTableWithEnum = 2.uint8,
|
||||
MyGameExample2Monster = 3.uint8,
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame\Example;
|
||||
|
||||
class Any
|
||||
{
|
||||
const NONE = 0;
|
||||
const Monster = 1;
|
||||
const TestSimpleTableWithEnum = 2;
|
||||
const MyGame_Example2_Monster = 3;
|
||||
|
||||
private static $names = array(
|
||||
Any::NONE=>"NONE",
|
||||
Any::Monster=>"Monster",
|
||||
Any::TestSimpleTableWithEnum=>"TestSimpleTableWithEnum",
|
||||
Any::MyGame_Example2_Monster=>"MyGame_Example2_Monster",
|
||||
);
|
||||
|
||||
public static function Name($e)
|
||||
{
|
||||
if (!isset(self::$names[$e])) {
|
||||
throw new \Exception();
|
||||
}
|
||||
return self::$names[$e];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
class Any(object):
|
||||
NONE = 0
|
||||
Monster = 1
|
||||
TestSimpleTableWithEnum = 2
|
||||
MyGame_Example2_Monster = 3
|
||||
|
||||
def AnyCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == Any().Monster:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == Any().TestSimpleTableWithEnum:
|
||||
import MyGame.Example.TestSimpleTableWithEnum
|
||||
return MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == Any().MyGame_Example2_Monster:
|
||||
import MyGame.Example2.Monster
|
||||
return MyGame.Example2.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
@@ -0,0 +1,113 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public enum AnyAmbiguousAliases : byte
|
||||
{
|
||||
NONE = 0,
|
||||
M1 = 1,
|
||||
M2 = 2,
|
||||
M3 = 3,
|
||||
};
|
||||
|
||||
public class AnyAmbiguousAliasesUnion {
|
||||
public AnyAmbiguousAliases Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public AnyAmbiguousAliasesUnion() {
|
||||
this.Type = AnyAmbiguousAliases.NONE;
|
||||
this.Value = null;
|
||||
}
|
||||
|
||||
public T As<T>() where T : class { return this.Value as T; }
|
||||
public MyGame.Example.MonsterT AsM1() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public static AnyAmbiguousAliasesUnion FromM1(MyGame.Example.MonsterT _m1) { return new AnyAmbiguousAliasesUnion{ Type = AnyAmbiguousAliases.M1, Value = _m1 }; }
|
||||
public MyGame.Example.MonsterT AsM2() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public static AnyAmbiguousAliasesUnion FromM2(MyGame.Example.MonsterT _m2) { return new AnyAmbiguousAliasesUnion{ Type = AnyAmbiguousAliases.M2, Value = _m2 }; }
|
||||
public MyGame.Example.MonsterT AsM3() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public static AnyAmbiguousAliasesUnion FromM3(MyGame.Example.MonsterT _m3) { return new AnyAmbiguousAliasesUnion{ Type = AnyAmbiguousAliases.M3, Value = _m3 }; }
|
||||
|
||||
public static int Pack(Google.FlatBuffers.FlatBufferBuilder builder, AnyAmbiguousAliasesUnion _o) {
|
||||
switch (_o.Type) {
|
||||
default: return 0;
|
||||
case AnyAmbiguousAliases.M1: return MyGame.Example.Monster.Pack(builder, _o.AsM1()).Value;
|
||||
case AnyAmbiguousAliases.M2: return MyGame.Example.Monster.Pack(builder, _o.AsM2()).Value;
|
||||
case AnyAmbiguousAliases.M3: return MyGame.Example.Monster.Pack(builder, _o.AsM3()).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnyAmbiguousAliasesUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
|
||||
public override bool CanConvert(System.Type objectType) {
|
||||
return objectType == typeof(AnyAmbiguousAliasesUnion) || objectType == typeof(System.Collections.Generic.List<AnyAmbiguousAliasesUnion>);
|
||||
}
|
||||
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = value as System.Collections.Generic.List<AnyAmbiguousAliasesUnion>;
|
||||
if (_olist != null) {
|
||||
writer.WriteStartArray();
|
||||
foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
|
||||
writer.WriteEndArray();
|
||||
} else {
|
||||
this.WriteJson(writer, value as AnyAmbiguousAliasesUnion, serializer);
|
||||
}
|
||||
}
|
||||
public void WriteJson(Newtonsoft.Json.JsonWriter writer, AnyAmbiguousAliasesUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return;
|
||||
serializer.Serialize(writer, _o.Value);
|
||||
}
|
||||
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = existingValue as System.Collections.Generic.List<AnyAmbiguousAliasesUnion>;
|
||||
if (_olist != null) {
|
||||
for (var _j = 0; _j < _olist.Count; ++_j) {
|
||||
reader.Read();
|
||||
_olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
|
||||
}
|
||||
reader.Read();
|
||||
return _olist;
|
||||
} else {
|
||||
return this.ReadJson(reader, existingValue as AnyAmbiguousAliasesUnion, serializer);
|
||||
}
|
||||
}
|
||||
public AnyAmbiguousAliasesUnion ReadJson(Newtonsoft.Json.JsonReader reader, AnyAmbiguousAliasesUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return null;
|
||||
switch (_o.Type) {
|
||||
default: break;
|
||||
case AnyAmbiguousAliases.M1: _o.Value = serializer.Deserialize<MyGame.Example.MonsterT>(reader); break;
|
||||
case AnyAmbiguousAliases.M2: _o.Value = serializer.Deserialize<MyGame.Example.MonsterT>(reader); break;
|
||||
case AnyAmbiguousAliases.M3: _o.Value = serializer.Deserialize<MyGame.Example.MonsterT>(reader); break;
|
||||
}
|
||||
return _o;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static public class AnyAmbiguousAliasesVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, byte typeId, uint tablePos)
|
||||
{
|
||||
bool result = true;
|
||||
switch((AnyAmbiguousAliases)typeId)
|
||||
{
|
||||
case AnyAmbiguousAliases.M1:
|
||||
result = MyGame.Example.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case AnyAmbiguousAliases.M2:
|
||||
result = MyGame.Example.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case AnyAmbiguousAliases.M3:
|
||||
result = MyGame.Example.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
default: result = true;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Example
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type AnyAmbiguousAliases byte
|
||||
|
||||
const (
|
||||
AnyAmbiguousAliasesNONE AnyAmbiguousAliases = 0
|
||||
AnyAmbiguousAliasesM1 AnyAmbiguousAliases = 1
|
||||
AnyAmbiguousAliasesM2 AnyAmbiguousAliases = 2
|
||||
AnyAmbiguousAliasesM3 AnyAmbiguousAliases = 3
|
||||
)
|
||||
|
||||
var EnumNamesAnyAmbiguousAliases = map[AnyAmbiguousAliases]string{
|
||||
AnyAmbiguousAliasesNONE: "NONE",
|
||||
AnyAmbiguousAliasesM1: "M1",
|
||||
AnyAmbiguousAliasesM2: "M2",
|
||||
AnyAmbiguousAliasesM3: "M3",
|
||||
}
|
||||
|
||||
var EnumValuesAnyAmbiguousAliases = map[string]AnyAmbiguousAliases{
|
||||
"NONE": AnyAmbiguousAliasesNONE,
|
||||
"M1": AnyAmbiguousAliasesM1,
|
||||
"M2": AnyAmbiguousAliasesM2,
|
||||
"M3": AnyAmbiguousAliasesM3,
|
||||
}
|
||||
|
||||
func (v AnyAmbiguousAliases) String() string {
|
||||
if s, ok := EnumNamesAnyAmbiguousAliases[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "AnyAmbiguousAliases(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
||||
type AnyAmbiguousAliasesT struct {
|
||||
Type AnyAmbiguousAliases
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (t *AnyAmbiguousAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
switch t.Type {
|
||||
case AnyAmbiguousAliasesM1:
|
||||
return t.Value.(*MonsterT).Pack(builder)
|
||||
case AnyAmbiguousAliasesM2:
|
||||
return t.Value.(*MonsterT).Pack(builder)
|
||||
case AnyAmbiguousAliasesM3:
|
||||
return t.Value.(*MonsterT).Pack(builder)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv AnyAmbiguousAliases) UnPack(table flatbuffers.Table) *AnyAmbiguousAliasesT {
|
||||
switch rcv {
|
||||
case AnyAmbiguousAliasesM1:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyAmbiguousAliasesT{Type: AnyAmbiguousAliasesM1, Value: x.UnPack()}
|
||||
case AnyAmbiguousAliasesM2:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyAmbiguousAliasesT{Type: AnyAmbiguousAliasesM2, Value: x.UnPack()}
|
||||
case AnyAmbiguousAliasesM3:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyAmbiguousAliasesT{Type: AnyAmbiguousAliasesM3, Value: x.UnPack()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class AnyAmbiguousAliases {
|
||||
private AnyAmbiguousAliases() { }
|
||||
public static final byte NONE = 0;
|
||||
public static final byte M1 = 1;
|
||||
public static final byte M2 = 2;
|
||||
public static final byte M3 = 3;
|
||||
|
||||
public static final String[] names = { "NONE", "M1", "M2", "M3", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example
|
||||
|
||||
@Suppress("unused")
|
||||
class AnyAmbiguousAliases private constructor() {
|
||||
companion object {
|
||||
const val NONE: UByte = 0u
|
||||
const val M1: UByte = 1u
|
||||
const val M2: UByte = 2u
|
||||
const val M3: UByte = 3u
|
||||
val names : Array<String> = arrayOf("NONE", "M1", "M2", "M3")
|
||||
fun name(e: Int) : String = names[e]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
--[[ MyGame.Example.AnyAmbiguousAliases
|
||||
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by : //monster_test.fbs
|
||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||
|
||||
--]]
|
||||
|
||||
local AnyAmbiguousAliases = {
|
||||
NONE = 0,
|
||||
M1 = 1,
|
||||
M2 = 2,
|
||||
M3 = 3,
|
||||
}
|
||||
|
||||
return AnyAmbiguousAliases
|
||||
@@ -0,0 +1,15 @@
|
||||
#[ MyGame.Example.AnyAmbiguousAliases
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by :
|
||||
Rooting type : MyGame.Example.Monster ()
|
||||
]#
|
||||
|
||||
type AnyAmbiguousAliases*{.pure.} = enum
|
||||
None = 0.uint8,
|
||||
M1 = 1.uint8,
|
||||
M2 = 2.uint8,
|
||||
M3 = 3.uint8,
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame\Example;
|
||||
|
||||
class AnyAmbiguousAliases
|
||||
{
|
||||
const NONE = 0;
|
||||
const M1 = 1;
|
||||
const M2 = 2;
|
||||
const M3 = 3;
|
||||
|
||||
private static $names = array(
|
||||
AnyAmbiguousAliases::NONE=>"NONE",
|
||||
AnyAmbiguousAliases::M1=>"M1",
|
||||
AnyAmbiguousAliases::M2=>"M2",
|
||||
AnyAmbiguousAliases::M3=>"M3",
|
||||
);
|
||||
|
||||
public static function Name($e)
|
||||
{
|
||||
if (!isset(self::$names[$e])) {
|
||||
throw new \Exception();
|
||||
}
|
||||
return self::$names[$e];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
class AnyAmbiguousAliases(object):
|
||||
NONE = 0
|
||||
M1 = 1
|
||||
M2 = 2
|
||||
M3 = 3
|
||||
|
||||
def AnyAmbiguousAliasesCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == AnyAmbiguousAliases().M1:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyAmbiguousAliases().M2:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyAmbiguousAliases().M3:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
@@ -0,0 +1,37 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
|
||||
public class AnyAmbiguousAliasesUnion {
|
||||
private byte type;
|
||||
private Object value;
|
||||
|
||||
public byte getType() { return type; }
|
||||
|
||||
public void setType(byte type) { this.type = type; }
|
||||
|
||||
public Object getValue() { return value; }
|
||||
|
||||
public void setValue(Object value) { this.value = value; }
|
||||
|
||||
public AnyAmbiguousAliasesUnion() {
|
||||
this.type = AnyAmbiguousAliases.NONE;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public MyGame.Example.MonsterT asM1() { return (MyGame.Example.MonsterT) value; }
|
||||
public MyGame.Example.MonsterT asM2() { return (MyGame.Example.MonsterT) value; }
|
||||
public MyGame.Example.MonsterT asM3() { return (MyGame.Example.MonsterT) value; }
|
||||
|
||||
public static int pack(FlatBufferBuilder builder, AnyAmbiguousAliasesUnion _o) {
|
||||
switch (_o.type) {
|
||||
case AnyAmbiguousAliases.M1: return MyGame.Example.Monster.pack(builder, _o.asM1());
|
||||
case AnyAmbiguousAliases.M2: return MyGame.Example.Monster.pack(builder, _o.asM2());
|
||||
case AnyAmbiguousAliases.M3: return MyGame.Example.Monster.pack(builder, _o.asM3());
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
|
||||
public class AnyUnion {
|
||||
private byte type;
|
||||
private Object value;
|
||||
|
||||
public byte getType() { return type; }
|
||||
|
||||
public void setType(byte type) { this.type = type; }
|
||||
|
||||
public Object getValue() { return value; }
|
||||
|
||||
public void setValue(Object value) { this.value = value; }
|
||||
|
||||
public AnyUnion() {
|
||||
this.type = Any.NONE;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public MyGame.Example.MonsterT asMonster() { return (MyGame.Example.MonsterT) value; }
|
||||
MyGame.Example.TestSimpleTableWithEnumT asTestSimpleTableWithEnum() { return (MyGame.Example.TestSimpleTableWithEnumT) value; }
|
||||
public MyGame.Example2.MonsterT asMyGame_Example2_Monster() { return (MyGame.Example2.MonsterT) value; }
|
||||
|
||||
public static int pack(FlatBufferBuilder builder, AnyUnion _o) {
|
||||
switch (_o.type) {
|
||||
case Any.Monster: return MyGame.Example.Monster.pack(builder, _o.asMonster());
|
||||
case Any.TestSimpleTableWithEnum: return MyGame.Example.TestSimpleTableWithEnum.pack(builder, _o.asTestSimpleTableWithEnum());
|
||||
case Any.MyGame_Example2_Monster: return MyGame.Example2.Monster.pack(builder, _o.asMyGame_Example2_Monster());
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public enum AnyUniqueAliases : byte
|
||||
{
|
||||
NONE = 0,
|
||||
M = 1,
|
||||
TS = 2,
|
||||
M2 = 3,
|
||||
};
|
||||
|
||||
public class AnyUniqueAliasesUnion {
|
||||
public AnyUniqueAliases Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public AnyUniqueAliasesUnion() {
|
||||
this.Type = AnyUniqueAliases.NONE;
|
||||
this.Value = null;
|
||||
}
|
||||
|
||||
public T As<T>() where T : class { return this.Value as T; }
|
||||
public MyGame.Example.MonsterT AsM() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public static AnyUniqueAliasesUnion FromM(MyGame.Example.MonsterT _m) { return new AnyUniqueAliasesUnion{ Type = AnyUniqueAliases.M, Value = _m }; }
|
||||
internal MyGame.Example.TestSimpleTableWithEnumT AsTS() { return this.As<MyGame.Example.TestSimpleTableWithEnumT>(); }
|
||||
internal static AnyUniqueAliasesUnion FromTS(MyGame.Example.TestSimpleTableWithEnumT _ts) { return new AnyUniqueAliasesUnion{ Type = AnyUniqueAliases.TS, Value = _ts }; }
|
||||
public MyGame.Example2.MonsterT AsM2() { return this.As<MyGame.Example2.MonsterT>(); }
|
||||
public static AnyUniqueAliasesUnion FromM2(MyGame.Example2.MonsterT _m2) { return new AnyUniqueAliasesUnion{ Type = AnyUniqueAliases.M2, Value = _m2 }; }
|
||||
|
||||
public static int Pack(Google.FlatBuffers.FlatBufferBuilder builder, AnyUniqueAliasesUnion _o) {
|
||||
switch (_o.Type) {
|
||||
default: return 0;
|
||||
case AnyUniqueAliases.M: return MyGame.Example.Monster.Pack(builder, _o.AsM()).Value;
|
||||
case AnyUniqueAliases.TS: return MyGame.Example.TestSimpleTableWithEnum.Pack(builder, _o.AsTS()).Value;
|
||||
case AnyUniqueAliases.M2: return MyGame.Example2.Monster.Pack(builder, _o.AsM2()).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnyUniqueAliasesUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
|
||||
public override bool CanConvert(System.Type objectType) {
|
||||
return objectType == typeof(AnyUniqueAliasesUnion) || objectType == typeof(System.Collections.Generic.List<AnyUniqueAliasesUnion>);
|
||||
}
|
||||
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = value as System.Collections.Generic.List<AnyUniqueAliasesUnion>;
|
||||
if (_olist != null) {
|
||||
writer.WriteStartArray();
|
||||
foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
|
||||
writer.WriteEndArray();
|
||||
} else {
|
||||
this.WriteJson(writer, value as AnyUniqueAliasesUnion, serializer);
|
||||
}
|
||||
}
|
||||
public void WriteJson(Newtonsoft.Json.JsonWriter writer, AnyUniqueAliasesUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return;
|
||||
serializer.Serialize(writer, _o.Value);
|
||||
}
|
||||
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = existingValue as System.Collections.Generic.List<AnyUniqueAliasesUnion>;
|
||||
if (_olist != null) {
|
||||
for (var _j = 0; _j < _olist.Count; ++_j) {
|
||||
reader.Read();
|
||||
_olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
|
||||
}
|
||||
reader.Read();
|
||||
return _olist;
|
||||
} else {
|
||||
return this.ReadJson(reader, existingValue as AnyUniqueAliasesUnion, serializer);
|
||||
}
|
||||
}
|
||||
public AnyUniqueAliasesUnion ReadJson(Newtonsoft.Json.JsonReader reader, AnyUniqueAliasesUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return null;
|
||||
switch (_o.Type) {
|
||||
default: break;
|
||||
case AnyUniqueAliases.M: _o.Value = serializer.Deserialize<MyGame.Example.MonsterT>(reader); break;
|
||||
case AnyUniqueAliases.TS: _o.Value = serializer.Deserialize<MyGame.Example.TestSimpleTableWithEnumT>(reader); break;
|
||||
case AnyUniqueAliases.M2: _o.Value = serializer.Deserialize<MyGame.Example2.MonsterT>(reader); break;
|
||||
}
|
||||
return _o;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static public class AnyUniqueAliasesVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, byte typeId, uint tablePos)
|
||||
{
|
||||
bool result = true;
|
||||
switch((AnyUniqueAliases)typeId)
|
||||
{
|
||||
case AnyUniqueAliases.M:
|
||||
result = MyGame.Example.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case AnyUniqueAliases.TS:
|
||||
result = MyGame.Example.TestSimpleTableWithEnumVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
case AnyUniqueAliases.M2:
|
||||
result = MyGame.Example2.MonsterVerify.Verify(verifier, tablePos);
|
||||
break;
|
||||
default: result = true;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Example
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
|
||||
MyGame__Example2 "MyGame/Example2"
|
||||
)
|
||||
|
||||
type AnyUniqueAliases byte
|
||||
|
||||
const (
|
||||
AnyUniqueAliasesNONE AnyUniqueAliases = 0
|
||||
AnyUniqueAliasesM AnyUniqueAliases = 1
|
||||
AnyUniqueAliasesTS AnyUniqueAliases = 2
|
||||
AnyUniqueAliasesM2 AnyUniqueAliases = 3
|
||||
)
|
||||
|
||||
var EnumNamesAnyUniqueAliases = map[AnyUniqueAliases]string{
|
||||
AnyUniqueAliasesNONE: "NONE",
|
||||
AnyUniqueAliasesM: "M",
|
||||
AnyUniqueAliasesTS: "TS",
|
||||
AnyUniqueAliasesM2: "M2",
|
||||
}
|
||||
|
||||
var EnumValuesAnyUniqueAliases = map[string]AnyUniqueAliases{
|
||||
"NONE": AnyUniqueAliasesNONE,
|
||||
"M": AnyUniqueAliasesM,
|
||||
"TS": AnyUniqueAliasesTS,
|
||||
"M2": AnyUniqueAliasesM2,
|
||||
}
|
||||
|
||||
func (v AnyUniqueAliases) String() string {
|
||||
if s, ok := EnumNamesAnyUniqueAliases[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "AnyUniqueAliases(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
||||
type AnyUniqueAliasesT struct {
|
||||
Type AnyUniqueAliases
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (t *AnyUniqueAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
switch t.Type {
|
||||
case AnyUniqueAliasesM:
|
||||
return t.Value.(*MonsterT).Pack(builder)
|
||||
case AnyUniqueAliasesTS:
|
||||
return t.Value.(*TestSimpleTableWithEnumT).Pack(builder)
|
||||
case AnyUniqueAliasesM2:
|
||||
return t.Value.(*MyGame__Example2.MonsterT).Pack(builder)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv AnyUniqueAliases) UnPack(table flatbuffers.Table) *AnyUniqueAliasesT {
|
||||
switch rcv {
|
||||
case AnyUniqueAliasesM:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyUniqueAliasesT{Type: AnyUniqueAliasesM, Value: x.UnPack()}
|
||||
case AnyUniqueAliasesTS:
|
||||
var x TestSimpleTableWithEnum
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyUniqueAliasesT{Type: AnyUniqueAliasesTS, Value: x.UnPack()}
|
||||
case AnyUniqueAliasesM2:
|
||||
var x MyGame__Example2.Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyUniqueAliasesT{Type: AnyUniqueAliasesM2, Value: x.UnPack()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class AnyUniqueAliases {
|
||||
private AnyUniqueAliases() { }
|
||||
public static final byte NONE = 0;
|
||||
public static final byte M = 1;
|
||||
public static final byte TS = 2;
|
||||
public static final byte M2 = 3;
|
||||
|
||||
public static final String[] names = { "NONE", "M", "TS", "M2", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example
|
||||
|
||||
@Suppress("unused")
|
||||
class AnyUniqueAliases private constructor() {
|
||||
companion object {
|
||||
const val NONE: UByte = 0u
|
||||
const val M: UByte = 1u
|
||||
const val TS: UByte = 2u
|
||||
const val M2: UByte = 3u
|
||||
val names : Array<String> = arrayOf("NONE", "M", "TS", "M2")
|
||||
fun name(e: Int) : String = names[e]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
--[[ MyGame.Example.AnyUniqueAliases
|
||||
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by : //monster_test.fbs
|
||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||
|
||||
--]]
|
||||
|
||||
local AnyUniqueAliases = {
|
||||
NONE = 0,
|
||||
M = 1,
|
||||
TS = 2,
|
||||
M2 = 3,
|
||||
}
|
||||
|
||||
return AnyUniqueAliases
|
||||
@@ -0,0 +1,15 @@
|
||||
#[ MyGame.Example.AnyUniqueAliases
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 24.3.25
|
||||
|
||||
Declared by :
|
||||
Rooting type : MyGame.Example.Monster ()
|
||||
]#
|
||||
|
||||
type AnyUniqueAliases*{.pure.} = enum
|
||||
None = 0.uint8,
|
||||
M = 1.uint8,
|
||||
Ts = 2.uint8,
|
||||
M2 = 3.uint8,
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame\Example;
|
||||
|
||||
class AnyUniqueAliases
|
||||
{
|
||||
const NONE = 0;
|
||||
const M = 1;
|
||||
const TS = 2;
|
||||
const M2 = 3;
|
||||
|
||||
private static $names = array(
|
||||
AnyUniqueAliases::NONE=>"NONE",
|
||||
AnyUniqueAliases::M=>"M",
|
||||
AnyUniqueAliases::TS=>"TS",
|
||||
AnyUniqueAliases::M2=>"M2",
|
||||
);
|
||||
|
||||
public static function Name($e)
|
||||
{
|
||||
if (!isset(self::$names[$e])) {
|
||||
throw new \Exception();
|
||||
}
|
||||
return self::$names[$e];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
class AnyUniqueAliases(object):
|
||||
NONE = 0
|
||||
M = 1
|
||||
TS = 2
|
||||
M2 = 3
|
||||
|
||||
def AnyUniqueAliasesCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == AnyUniqueAliases().M:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyUniqueAliases().TS:
|
||||
import MyGame.Example.TestSimpleTableWithEnum
|
||||
return MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyUniqueAliases().M2:
|
||||
import MyGame.Example2.Monster
|
||||
return MyGame.Example2.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
@@ -0,0 +1,37 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
|
||||
public class AnyUniqueAliasesUnion {
|
||||
private byte type;
|
||||
private Object value;
|
||||
|
||||
public byte getType() { return type; }
|
||||
|
||||
public void setType(byte type) { this.type = type; }
|
||||
|
||||
public Object getValue() { return value; }
|
||||
|
||||
public void setValue(Object value) { this.value = value; }
|
||||
|
||||
public AnyUniqueAliasesUnion() {
|
||||
this.type = AnyUniqueAliases.NONE;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public MyGame.Example.MonsterT asM() { return (MyGame.Example.MonsterT) value; }
|
||||
MyGame.Example.TestSimpleTableWithEnumT asTS() { return (MyGame.Example.TestSimpleTableWithEnumT) value; }
|
||||
public MyGame.Example2.MonsterT asM2() { return (MyGame.Example2.MonsterT) value; }
|
||||
|
||||
public static int pack(FlatBufferBuilder builder, AnyUniqueAliasesUnion _o) {
|
||||
switch (_o.type) {
|
||||
case AnyUniqueAliases.M: return MyGame.Example.Monster.pack(builder, _o.asM());
|
||||
case AnyUniqueAliases.TS: return MyGame.Example.TestSimpleTableWithEnum.pack(builder, _o.asTS());
|
||||
case AnyUniqueAliases.M2: return MyGame.Example2.Monster.pack(builder, _o.asM2());
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct ArrayStruct : IFlatbufferObject
|
||||
{
|
||||
private Struct __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
|
||||
public ArrayStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public float A { get { return __p.bb.GetFloat(__p.bb_pos + 0); } }
|
||||
public void MutateA(float a) { __p.bb.PutFloat(__p.bb_pos + 0, a); }
|
||||
public int B(int j) { return __p.bb.GetInt(__p.bb_pos + 4 + j * 4); }
|
||||
public void MutateB(int j, int b) { __p.bb.PutInt(__p.bb_pos + 4 + j * 4, b); }
|
||||
public sbyte C { get { return __p.bb.GetSbyte(__p.bb_pos + 64); } }
|
||||
public void MutateC(sbyte c) { __p.bb.PutSbyte(__p.bb_pos + 64, c); }
|
||||
public MyGame.Example.NestedStruct D(int j) { return (new MyGame.Example.NestedStruct()).__assign(__p.bb_pos + 72 + j * 32, __p.bb); }
|
||||
public int E { get { return __p.bb.GetInt(__p.bb_pos + 136); } }
|
||||
public void MutateE(int e) { __p.bb.PutInt(__p.bb_pos + 136, e); }
|
||||
public long F(int j) { return __p.bb.GetLong(__p.bb_pos + 144 + j * 8); }
|
||||
public void MutateF(int j, long f) { __p.bb.PutLong(__p.bb_pos + 144 + j * 8, f); }
|
||||
|
||||
public static Offset<MyGame.Example.ArrayStruct> CreateArrayStruct(FlatBufferBuilder builder, float A, int[] B, sbyte C, int[,] d_A, MyGame.Example.TestEnum[] d_B, MyGame.Example.TestEnum[,] d_C, long[,] d_D, int E, long[] F) {
|
||||
builder.Prep(8, 160);
|
||||
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
|
||||
builder.PutLong(F[_idx0-1]);
|
||||
}
|
||||
builder.Pad(4);
|
||||
builder.PutInt(E);
|
||||
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
|
||||
builder.Prep(8, 32);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.PutLong(d_D[_idx0-1,_idx1-1]);
|
||||
}
|
||||
builder.Pad(5);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.PutSbyte((sbyte)d_C[_idx0-1,_idx1-1]);
|
||||
}
|
||||
builder.PutSbyte((sbyte)d_B[_idx0-1]);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.PutInt(d_A[_idx0-1,_idx1-1]);
|
||||
}
|
||||
}
|
||||
builder.Pad(7);
|
||||
builder.PutSbyte(C);
|
||||
for (int _idx0 = 15; _idx0 > 0; _idx0--) {
|
||||
builder.PutInt(B[_idx0-1]);
|
||||
}
|
||||
builder.PutFloat(A);
|
||||
return new Offset<MyGame.Example.ArrayStruct>(builder.Offset);
|
||||
}
|
||||
public ArrayStructT UnPack() {
|
||||
var _o = new ArrayStructT();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(ArrayStructT _o) {
|
||||
_o.A = this.A;
|
||||
_o.B = new int[15];
|
||||
for (var _j = 0; _j < 15; ++_j) { _o.B[_j] = this.B(_j); }
|
||||
_o.C = this.C;
|
||||
_o.D = new MyGame.Example.NestedStructT[2];
|
||||
for (var _j = 0; _j < 2; ++_j) { _o.D[_j] = this.D(_j).UnPack(); }
|
||||
_o.E = this.E;
|
||||
_o.F = new long[2];
|
||||
for (var _j = 0; _j < 2; ++_j) { _o.F[_j] = this.F(_j); }
|
||||
}
|
||||
public static Offset<MyGame.Example.ArrayStruct> Pack(FlatBufferBuilder builder, ArrayStructT _o) {
|
||||
if (_o == null) return default(Offset<MyGame.Example.ArrayStruct>);
|
||||
var _b = _o.B;
|
||||
var _d_a = new int[2,2];
|
||||
for (var idx0 = 0; idx0 < 2; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_d_a[idx0,idx1] = _o.D[idx0].A[idx1];}}
|
||||
var _d_b = new MyGame.Example.TestEnum[2];
|
||||
for (var idx0 = 0; idx0 < 2; ++idx0) {_d_b[idx0] = _o.D[idx0].B;}
|
||||
var _d_c = new MyGame.Example.TestEnum[2,2];
|
||||
for (var idx0 = 0; idx0 < 2; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_d_c[idx0,idx1] = _o.D[idx0].C[idx1];}}
|
||||
var _d_d = new long[2,2];
|
||||
for (var idx0 = 0; idx0 < 2; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_d_d[idx0,idx1] = _o.D[idx0].D[idx1];}}
|
||||
var _f = _o.F;
|
||||
return CreateArrayStruct(
|
||||
builder,
|
||||
_o.A,
|
||||
_b,
|
||||
_o.C,
|
||||
_d_a,
|
||||
_d_b,
|
||||
_d_c,
|
||||
_d_d,
|
||||
_o.E,
|
||||
_f);
|
||||
}
|
||||
}
|
||||
|
||||
public class ArrayStructT
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("a")]
|
||||
public float A { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("b")]
|
||||
public int[] B { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("c")]
|
||||
public sbyte C { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("d")]
|
||||
public MyGame.Example.NestedStructT[] D { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("e")]
|
||||
public int E { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("f")]
|
||||
public long[] F { get; set; }
|
||||
|
||||
public ArrayStructT() {
|
||||
this.A = 0.0f;
|
||||
this.B = new int[15];
|
||||
this.C = 0;
|
||||
this.D = new MyGame.Example.NestedStructT[2];
|
||||
this.E = 0;
|
||||
this.F = new long[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class ArrayStruct extends Struct {
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public ArrayStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public float a() { return bb.getFloat(bb_pos + 0); }
|
||||
public void mutateA(float a) { bb.putFloat(bb_pos + 0, a); }
|
||||
public int b(int j) { return bb.getInt(bb_pos + 4 + j * 4); }
|
||||
public void mutateB(int j, int b) { bb.putInt(bb_pos + 4 + j * 4, b); }
|
||||
public byte c() { return bb.get(bb_pos + 64); }
|
||||
public void mutateC(byte c) { bb.put(bb_pos + 64, c); }
|
||||
public MyGame.Example.NestedStruct d(int j) { return d(new MyGame.Example.NestedStruct(), j); }
|
||||
public MyGame.Example.NestedStruct d(MyGame.Example.NestedStruct obj, int j) { return obj.__assign(bb_pos + 72 + j * 32, bb); }
|
||||
public int e() { return bb.getInt(bb_pos + 136); }
|
||||
public void mutateE(int e) { bb.putInt(bb_pos + 136, e); }
|
||||
public long f(int j) { return bb.getLong(bb_pos + 144 + j * 8); }
|
||||
public void mutateF(int j, long f) { bb.putLong(bb_pos + 144 + j * 8, f); }
|
||||
|
||||
public static int createArrayStruct(FlatBufferBuilder builder, float a, int[] b, byte c, int[][] d_a, byte[] d_b, byte[][] d_c, long[][] d_d, int e, long[] f) {
|
||||
builder.prep(8, 160);
|
||||
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
|
||||
builder.putLong(f[_idx0-1]);
|
||||
}
|
||||
builder.pad(4);
|
||||
builder.putInt(e);
|
||||
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
|
||||
builder.prep(8, 32);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.putLong(d_d[_idx0-1][_idx1-1]);
|
||||
}
|
||||
builder.pad(5);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.putByte(d_c[_idx0-1][_idx1-1]);
|
||||
}
|
||||
builder.putByte(d_b[_idx0-1]);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.putInt(d_a[_idx0-1][_idx1-1]);
|
||||
}
|
||||
}
|
||||
builder.pad(7);
|
||||
builder.putByte(c);
|
||||
for (int _idx0 = 15; _idx0 > 0; _idx0--) {
|
||||
builder.putInt(b[_idx0-1]);
|
||||
}
|
||||
builder.putFloat(a);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public ArrayStruct get(int j) { return get(new ArrayStruct(), j); }
|
||||
public ArrayStruct get(ArrayStruct obj, int j) { return obj.__assign(__element(j), bb); }
|
||||
}
|
||||
public ArrayStructT unpack() {
|
||||
ArrayStructT _o = new ArrayStructT();
|
||||
unpackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void unpackTo(ArrayStructT _o) {
|
||||
float _oA = a();
|
||||
_o.setA(_oA);
|
||||
int[] _oB = _o.getB();
|
||||
for (int _j = 0; _j < 15; ++_j) { _oB[_j] = b(_j); }
|
||||
byte _oC = c();
|
||||
_o.setC(_oC);
|
||||
MyGame.Example.NestedStructT[] _oD = _o.getD();
|
||||
for (int _j = 0; _j < 2; ++_j) { _oD[_j] = d(_j).unpack(); }
|
||||
int _oE = e();
|
||||
_o.setE(_oE);
|
||||
long[] _oF = _o.getF();
|
||||
for (int _j = 0; _j < 2; ++_j) { _oF[_j] = f(_j); }
|
||||
}
|
||||
public static int pack(FlatBufferBuilder builder, ArrayStructT _o) {
|
||||
if (_o == null) return 0;
|
||||
int[] _b = _o.getB();
|
||||
int[][] _d_a = new int[2][2];
|
||||
for (int idx0 = 0; idx0 < 2; ++idx0) {for (int idx1 = 0; idx1 < 2; ++idx1) {_d_a[idx0][idx1] = _o.getD()[idx0].getA()[idx1];}}
|
||||
byte[] _d_b = new byte[2];
|
||||
for (int idx0 = 0; idx0 < 2; ++idx0) {_d_b[idx0] = _o.getD()[idx0].getB();}
|
||||
byte[][] _d_c = new byte[2][2];
|
||||
for (int idx0 = 0; idx0 < 2; ++idx0) {for (int idx1 = 0; idx1 < 2; ++idx1) {_d_c[idx0][idx1] = _o.getD()[idx0].getC()[idx1];}}
|
||||
long[][] _d_d = new long[2][2];
|
||||
for (int idx0 = 0; idx0 < 2; ++idx0) {for (int idx1 = 0; idx1 < 2; ++idx1) {_d_d[idx0][idx1] = _o.getD()[idx0].getD()[idx1];}}
|
||||
long[] _f = _o.getF();
|
||||
return createArrayStruct(
|
||||
builder,
|
||||
_o.getA(),
|
||||
_b,
|
||||
_o.getC(),
|
||||
_d_a,
|
||||
_d_b,
|
||||
_d_c,
|
||||
_d_d,
|
||||
_o.getE(),
|
||||
_f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
from typing import Any
|
||||
from MyGame.Example.NestedStruct import NestedStruct
|
||||
np = import_numpy()
|
||||
|
||||
class ArrayStruct(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def SizeOf(cls) -> int:
|
||||
return 160
|
||||
|
||||
# ArrayStruct
|
||||
def Init(self, buf: bytes, pos: int):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# ArrayStruct
|
||||
def A(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0))
|
||||
# ArrayStruct
|
||||
def B(self, j = None):
|
||||
if j is None:
|
||||
return [self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4 + i * 4)) for i in range(self.BLength())]
|
||||
elif j >= 0 and j < self.BLength():
|
||||
return self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4 + j * 4))
|
||||
else:
|
||||
return None
|
||||
|
||||
# ArrayStruct
|
||||
def BAsNumpy(self):
|
||||
return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int32Flags, self._tab.Pos + 4, self.BLength())
|
||||
|
||||
# ArrayStruct
|
||||
def BLength(self) -> int:
|
||||
return 15
|
||||
|
||||
# ArrayStruct
|
||||
def BIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
# ArrayStruct
|
||||
def C(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(64))
|
||||
# ArrayStruct
|
||||
def D(self, i: int) -> NestedStruct:
|
||||
obj = NestedStruct()
|
||||
obj.Init(self._tab.Bytes, self._tab.Pos + 72 + i * 32)
|
||||
return obj
|
||||
|
||||
# ArrayStruct
|
||||
def DLength(self) -> int:
|
||||
return 2
|
||||
|
||||
# ArrayStruct
|
||||
def DIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
# ArrayStruct
|
||||
def E(self): return self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(136))
|
||||
# ArrayStruct
|
||||
def F(self, j = None):
|
||||
if j is None:
|
||||
return [self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(144 + i * 8)) for i in range(self.FLength())]
|
||||
elif j >= 0 and j < self.FLength():
|
||||
return self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(144 + j * 8))
|
||||
else:
|
||||
return None
|
||||
|
||||
# ArrayStruct
|
||||
def FAsNumpy(self):
|
||||
return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int64Flags, self._tab.Pos + 144, self.FLength())
|
||||
|
||||
# ArrayStruct
|
||||
def FLength(self) -> int:
|
||||
return 2
|
||||
|
||||
# ArrayStruct
|
||||
def FIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def CreateArrayStruct(builder, a, b, c, d_a, d_b, d_c, d_d, e, f):
|
||||
builder.Prep(8, 160)
|
||||
for _idx0 in range(2 , 0, -1):
|
||||
builder.PrependInt64(f[_idx0-1])
|
||||
builder.Pad(4)
|
||||
builder.PrependInt32(e)
|
||||
for _idx0 in range(2 , 0, -1):
|
||||
builder.Prep(8, 32)
|
||||
for _idx1 in range(2 , 0, -1):
|
||||
builder.PrependInt64(d_d[_idx0-1][_idx1-1])
|
||||
builder.Pad(5)
|
||||
for _idx1 in range(2 , 0, -1):
|
||||
builder.PrependInt8(d_c[_idx0-1][_idx1-1])
|
||||
builder.PrependInt8(d_b[_idx0-1])
|
||||
for _idx1 in range(2 , 0, -1):
|
||||
builder.PrependInt32(d_a[_idx0-1][_idx1-1])
|
||||
builder.Pad(7)
|
||||
builder.PrependInt8(c)
|
||||
for _idx0 in range(15 , 0, -1):
|
||||
builder.PrependInt32(b[_idx0-1])
|
||||
builder.PrependFloat32(a)
|
||||
return builder.Offset()
|
||||
|
||||
import MyGame.Example.NestedStruct
|
||||
try:
|
||||
from typing import List
|
||||
except:
|
||||
pass
|
||||
|
||||
class ArrayStructT(object):
|
||||
|
||||
# ArrayStructT
|
||||
def __init__(self):
|
||||
self.a = 0.0 # type: float
|
||||
self.b = None # type: List[int]
|
||||
self.c = 0 # type: int
|
||||
self.d = None # type: List[MyGame.Example.NestedStruct.NestedStructT]
|
||||
self.e = 0 # type: int
|
||||
self.f = None # type: List[int]
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
arrayStruct = ArrayStruct()
|
||||
arrayStruct.Init(buf, pos)
|
||||
return cls.InitFromObj(arrayStruct)
|
||||
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf, pos=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||
return cls.InitFromBuf(buf, pos+n)
|
||||
|
||||
@classmethod
|
||||
def InitFromObj(cls, arrayStruct):
|
||||
x = ArrayStructT()
|
||||
x._UnPack(arrayStruct)
|
||||
return x
|
||||
|
||||
# ArrayStructT
|
||||
def _UnPack(self, arrayStruct):
|
||||
if arrayStruct is None:
|
||||
return
|
||||
self.a = arrayStruct.A()
|
||||
if not arrayStruct.BIsNone():
|
||||
if np is None:
|
||||
self.b = []
|
||||
for i in range(arrayStruct.BLength()):
|
||||
self.b.append(arrayStruct.B(i))
|
||||
else:
|
||||
self.b = arrayStruct.BAsNumpy()
|
||||
self.c = arrayStruct.C()
|
||||
if not arrayStruct.DIsNone():
|
||||
self.d = []
|
||||
for i in range(arrayStruct.DLength()):
|
||||
if arrayStruct.D(i) is None:
|
||||
self.d.append(None)
|
||||
else:
|
||||
nestedStruct_ = MyGame.Example.NestedStruct.NestedStructT.InitFromObj(arrayStruct.D(i))
|
||||
self.d.append(nestedStruct_)
|
||||
self.e = arrayStruct.E()
|
||||
if not arrayStruct.FIsNone():
|
||||
if np is None:
|
||||
self.f = []
|
||||
for i in range(arrayStruct.FLength()):
|
||||
self.f.append(arrayStruct.F(i))
|
||||
else:
|
||||
self.f = arrayStruct.FAsNumpy()
|
||||
|
||||
# ArrayStructT
|
||||
def Pack(self, builder):
|
||||
return CreateArrayStruct(builder, self.a, self.b, self.c, self.d.a, self.d.b, self.d.c, self.d.d, self.e, self.f)
|
||||
@@ -0,0 +1,64 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class ArrayStructT {
|
||||
private float a;
|
||||
private int[] b;
|
||||
private byte c;
|
||||
private MyGame.Example.NestedStructT[] d;
|
||||
private int e;
|
||||
private long[] f;
|
||||
|
||||
public float getA() { return a; }
|
||||
|
||||
public void setA(float a) { this.a = a; }
|
||||
|
||||
public int[] getB() { return b; }
|
||||
|
||||
public void setB(int[] b) { if (b != null && b.length == 15) this.b = b; }
|
||||
|
||||
public byte getC() { return c; }
|
||||
|
||||
public void setC(byte c) { this.c = c; }
|
||||
|
||||
public MyGame.Example.NestedStructT[] getD() { return d; }
|
||||
|
||||
public void setD(MyGame.Example.NestedStructT[] d) { if (d != null && d.length == 2) this.d = d; }
|
||||
|
||||
public int getE() { return e; }
|
||||
|
||||
public void setE(int e) { this.e = e; }
|
||||
|
||||
public long[] getF() { return f; }
|
||||
|
||||
public void setF(long[] f) { if (f != null && f.length == 2) this.f = f; }
|
||||
|
||||
|
||||
public ArrayStructT() {
|
||||
this.a = 0.0f;
|
||||
this.b = new int[15];
|
||||
this.c = 0;
|
||||
this.d = new MyGame.Example.NestedStructT[2];
|
||||
this.e = 0;
|
||||
this.f = new long[2];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct ArrayTable : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_25(); }
|
||||
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb) { return GetRootAsArrayTable(_bb, new ArrayTable()); }
|
||||
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public static bool ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "ARRT"); }
|
||||
public static bool VerifyArrayTable(ByteBuffer _bb) {Google.FlatBuffers.Verifier verifier = new Google.FlatBuffers.Verifier(_bb); return verifier.VerifyBuffer("ARRT", false, ArrayTableVerify.Verify); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
public ArrayTable __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public MyGame.Example.ArrayStruct? A { get { int o = __p.__offset(4); return o != 0 ? (MyGame.Example.ArrayStruct?)(new MyGame.Example.ArrayStruct()).__assign(o + __p.bb_pos, __p.bb) : null; } }
|
||||
|
||||
public static void StartArrayTable(FlatBufferBuilder builder) { builder.StartTable(1); }
|
||||
public static void AddA(FlatBufferBuilder builder, Offset<MyGame.Example.ArrayStruct> aOffset) { builder.AddStruct(0, aOffset.Value, 0); }
|
||||
public static Offset<MyGame.Example.ArrayTable> EndArrayTable(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<MyGame.Example.ArrayTable>(o);
|
||||
}
|
||||
public static void FinishArrayTableBuffer(FlatBufferBuilder builder, Offset<MyGame.Example.ArrayTable> offset) { builder.Finish(offset.Value, "ARRT"); }
|
||||
public static void FinishSizePrefixedArrayTableBuffer(FlatBufferBuilder builder, Offset<MyGame.Example.ArrayTable> offset) { builder.FinishSizePrefixed(offset.Value, "ARRT"); }
|
||||
public ArrayTableT UnPack() {
|
||||
var _o = new ArrayTableT();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(ArrayTableT _o) {
|
||||
_o.A = this.A.HasValue ? this.A.Value.UnPack() : null;
|
||||
}
|
||||
public static Offset<MyGame.Example.ArrayTable> Pack(FlatBufferBuilder builder, ArrayTableT _o) {
|
||||
if (_o == null) return default(Offset<MyGame.Example.ArrayTable>);
|
||||
StartArrayTable(builder);
|
||||
AddA(builder, MyGame.Example.ArrayStruct.Pack(builder, _o.A));
|
||||
return EndArrayTable(builder);
|
||||
}
|
||||
}
|
||||
|
||||
public class ArrayTableT
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("a")]
|
||||
public MyGame.Example.ArrayStructT A { get; set; }
|
||||
|
||||
public ArrayTableT() {
|
||||
this.A = new MyGame.Example.ArrayStructT();
|
||||
}
|
||||
|
||||
public static ArrayTableT DeserializeFromJson(string jsonText) {
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<ArrayTableT>(jsonText);
|
||||
}
|
||||
public string SerializeToJson() {
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
public static ArrayTableT DeserializeFromBinary(byte[] fbBuffer) {
|
||||
return ArrayTable.GetRootAsArrayTable(new ByteBuffer(fbBuffer)).UnPack();
|
||||
}
|
||||
public byte[] SerializeToBinary() {
|
||||
var fbb = new FlatBufferBuilder(0x10000);
|
||||
ArrayTable.FinishArrayTableBuffer(fbb, ArrayTable.Pack(fbb, this));
|
||||
return fbb.DataBuffer.ToSizedArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public class ArrayTableVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, uint tablePos)
|
||||
{
|
||||
return verifier.VerifyTableStart(tablePos)
|
||||
&& verifier.VerifyField(tablePos, 4 /*A*/, 160 /*MyGame.Example.ArrayStruct*/, 8, false)
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class ArrayTable extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); }
|
||||
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb) { return getRootAsArrayTable(_bb, new ArrayTable()); }
|
||||
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public static boolean ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "ARRT"); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public ArrayTable __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public MyGame.Example.ArrayStruct a() { return a(new MyGame.Example.ArrayStruct()); }
|
||||
public MyGame.Example.ArrayStruct a(MyGame.Example.ArrayStruct obj) { int o = __offset(4); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
|
||||
|
||||
public static void startArrayTable(FlatBufferBuilder builder) { builder.startTable(1); }
|
||||
public static void addA(FlatBufferBuilder builder, int aOffset) { builder.addStruct(0, aOffset, 0); }
|
||||
public static int endArrayTable(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
public static void finishArrayTableBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset, "ARRT"); }
|
||||
public static void finishSizePrefixedArrayTableBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset, "ARRT"); }
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public ArrayTable get(int j) { return get(new ArrayTable(), j); }
|
||||
public ArrayTable get(ArrayTable obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
public ArrayTableT unpack() {
|
||||
ArrayTableT _o = new ArrayTableT();
|
||||
unpackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void unpackTo(ArrayTableT _o) {
|
||||
if (a() != null) a().unpackTo(_o.getA());
|
||||
else _o.setA(null);
|
||||
}
|
||||
public static int pack(FlatBufferBuilder builder, ArrayTableT _o) {
|
||||
if (_o == null) return 0;
|
||||
startArrayTable(builder);
|
||||
addA(builder, MyGame.Example.ArrayStruct.pack(builder, _o.getA()));
|
||||
return endArrayTable(builder);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user