From 8329c81e193c6b74c4f05a5cfac2153d2179ac2f Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Fri, 30 Oct 2020 12:26:29 +0100 Subject: [PATCH 01/16] serialization: remove flatbuffers usage Change-Id: Ic334d20bf00cd50854af767efa9c9e0bce6111b8 --- Makefile.am | 2 - doc/design.txt | 4 +- doc/documentation.rst | 2 + src/dbuspolicy_finder.cpp | 1 + src/internal/include/fb.fbs | 121 - src/internal/include/fb_generated.h | 1567 ------------ src/internal/include/flatbuffers/base.h | 373 --- src/internal/include/flatbuffers/code_generators.h | 203 -- src/internal/include/flatbuffers/flatbuffers.h | 2616 -------------------- src/internal/include/flatbuffers/flatc.h | 96 - src/internal/include/flatbuffers/flexbuffers.h | 1538 ------------ src/internal/include/flatbuffers/grpc.h | 328 --- src/internal/include/flatbuffers/hash.h | 127 - src/internal/include/flatbuffers/idl.h | 973 -------- src/internal/include/flatbuffers/minireflect.h | 383 --- src/internal/include/flatbuffers/reflection.h | 477 ---- .../include/flatbuffers/reflection_generated.h | 1182 --------- src/internal/include/flatbuffers/registry.h | 127 - src/internal/include/flatbuffers/stl_emulation.h | 275 -- src/internal/include/flatbuffers/util.h | 651 ----- src/internal/print_content.hpp | 1 - src/internal/serialization_backend.hpp | 8 - src/internal/serializer_flatbuffers.cpp | 286 --- src/internal/serializer_flatbuffers.hpp | 83 - src/internal/storage_backend_flatbuffers.cpp | 58 - src/internal/storage_backend_flatbuffers.hpp | 224 -- src/stest_load_perf.cpp | 19 +- src/stest_performance.cpp | 11 +- src/test-libdbuspolicy1-access-deny-gdi.cpp | 1 - src/test-libdbuspolicy1-method-gdi.cpp | 1 - src/test-libdbuspolicy1-ownership-deny-gdi.cpp | 1 - ...buspolicy1-send_destination_prefix-deny-gdi.cpp | 1 - src/test-libdbuspolicy1-signal-gdi.cpp | 1 - 33 files changed, 15 insertions(+), 11726 deletions(-) delete mode 100644 src/internal/include/fb.fbs delete mode 100644 src/internal/include/fb_generated.h delete mode 100644 src/internal/include/flatbuffers/base.h delete mode 100644 src/internal/include/flatbuffers/code_generators.h delete mode 100644 src/internal/include/flatbuffers/flatbuffers.h delete mode 100644 src/internal/include/flatbuffers/flatc.h delete mode 100644 src/internal/include/flatbuffers/flexbuffers.h delete mode 100644 src/internal/include/flatbuffers/grpc.h delete mode 100644 src/internal/include/flatbuffers/hash.h delete mode 100644 src/internal/include/flatbuffers/idl.h delete mode 100644 src/internal/include/flatbuffers/minireflect.h delete mode 100644 src/internal/include/flatbuffers/reflection.h delete mode 100644 src/internal/include/flatbuffers/reflection_generated.h delete mode 100644 src/internal/include/flatbuffers/registry.h delete mode 100644 src/internal/include/flatbuffers/stl_emulation.h delete mode 100644 src/internal/include/flatbuffers/util.h delete mode 100644 src/internal/serializer_flatbuffers.cpp delete mode 100644 src/internal/serializer_flatbuffers.hpp delete mode 100644 src/internal/storage_backend_flatbuffers.cpp delete mode 100644 src/internal/storage_backend_flatbuffers.hpp diff --git a/Makefile.am b/Makefile.am index da4f145..e68e740 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,12 +63,10 @@ COMMON_SRC =\ src/internal/xml_parser.cpp \ src/internal/tslog.cpp \ src/internal/serializer.cpp \ - src/internal/serializer_flatbuffers.cpp \ src/internal/serializer_direct.cpp \ src/internal/policy_containers.cpp \ src/internal/print_content.cpp \ src/internal/storage_backend_direct.cpp \ - src/internal/storage_backend_flatbuffers.cpp \ src/internal/storage_backend_serialized.cpp \ src/internal/storage_backend_xml.cpp diff --git a/doc/design.txt b/doc/design.txt index 5361ca9..eca03f1 100644 --- a/doc/design.txt +++ b/doc/design.txt @@ -16,7 +16,7 @@ This is a short description of the diagrams: - Serializer - a translator between XML-based data and serialized data; used as an entry point for serializator tool; - Printer - an entry point for printer tool; - - FlatBuffers - a library used for management of serialized data. + - FlatBuffers - a library used for management of serialized data (deprecated). - Classes-use-only-serialized - a diagram of classes; this is improved Classes; the differences are: @@ -29,6 +29,6 @@ This is a short description of the diagrams: of Classes-use-only-serialized; the differences are: - There is no StorageBackendXML; - Serializer uses XmlParser to create FlatBuffers directly (in case of unavailable - serialized policy file); + serialized policy file) (deprecated); - we are not sure if this will improve initialization time, as all the objects have to be fully created before serialization anyway. diff --git a/doc/documentation.rst b/doc/documentation.rst index 00b4ade..7ee5c22 100644 --- a/doc/documentation.rst +++ b/doc/documentation.rst @@ -49,6 +49,8 @@ to code refactoring and introducing serialization. Google's FlatBuffers (https://google.github.io/flatbuffers/) were selected to implement serialization. In order to do that, the code was heavily refactored. +In 2020, we replaced FlatBuffers with locally implemented, direct serialization. + Layers ------ diff --git a/src/dbuspolicy_finder.cpp b/src/dbuspolicy_finder.cpp index a8edb68..7089ed0 100644 --- a/src/dbuspolicy_finder.cpp +++ b/src/dbuspolicy_finder.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/internal/include/fb.fbs b/src/internal/include/fb.fbs deleted file mode 100644 index efbf6b9..0000000 --- a/src/internal/include/fb.fbs +++ /dev/null @@ -1,121 +0,0 @@ -namespace FB; - -enum Decision : byte {ANY = 0, ALLOW, DENY, CHECK} -enum BusAccessType : byte {USER, GROUP, ALL_USERS, ALL_GROUPS} -enum MessageType : byte { ANY = 0, METHOD_CALL, METHOD_RETURN, ERROR, SIGNAL } - -table File { - m_own_set:OwnSet; - m_send_set:SendSet; - m_receive_set:ReceiveSet; - m_access_set:AccessSet; -} - -table OwnSet { - context_default: PolicyOwn; - context_mandatory: PolicyOwn; - user:[PolicyOwnPair]; - group:[PolicyOwnPair]; -} - -table PolicyOwn { - tree:PolicyOwnNode; -} - -table PolicyOwnPair { - id: long (key); - policy: PolicyOwn; -} - -table PolicySendPair { - id: long (key); - policy: PolicySend; -} - -table PolicyReceivePair { - id: long (key); - policy: PolicyReceive; -} - -table PolicyOwnNode { - token:string (key); - prefix_decision_item:DecisionItem; - decision_item:DecisionItem; - children:[PolicyOwnNode]; -} - -table SendSet { - context_default: PolicySend; - context_mandatory: PolicySend; - user:[PolicySendPair]; - group:[PolicySendPair]; -} - -table PolicySend { - items:[ItemSend]; - index:[NameScoresPair]; // version "LDP2" extension - prefix_index:[uint]; // version "LDP2" extension -} - -table ItemSend { - decision:DecisionItem; - name:string; - interface:string; - member:string; - path:string; - type:MessageType; - is_name_prefix:bool; -} - -table ItemReceive { - decision:DecisionItem; - name:string; - interface:string; - member:string; - path:string; - type:MessageType; - is_name_prefix:bool; -} - -table ReceiveSet { - context_default: PolicyReceive; - context_mandatory: PolicyReceive; - user:[PolicyReceivePair]; - group:[PolicyReceivePair]; -} - -table PolicyReceive { - items:[ItemReceive]; -} - -table AccessSet { - context_default: PolicyAccess; - context_mandatory: PolicyAccess; -} - -table PolicyAccess { - items:[ItemAccess]; -} - -table ItemAccess { - uid:uint; - gid:uint; - decision:DecisionItem; - type:BusAccessType; -} - -table DecisionItem { - decision:Decision; - privilege:string; -} - -/* version LDP2 extension starts here - sendIndex added */ -table NameScoresPair { - name: string (key); - best_score: uint; - item_refs:[uint]; -} - -root_type File; - -file_identifier "LDP2"; diff --git a/src/internal/include/fb_generated.h b/src/internal/include/fb_generated.h deleted file mode 100644 index 335b3d9..0000000 --- a/src/internal/include/fb_generated.h +++ /dev/null @@ -1,1567 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - - -#ifndef FLATBUFFERS_GENERATED_FB_FB_H_ -#define FLATBUFFERS_GENERATED_FB_FB_H_ - -#include "flatbuffers/flatbuffers.h" - -namespace FB { - -struct File; - -struct OwnSet; - -struct PolicyOwn; - -struct PolicyOwnPair; - -struct PolicySendPair; - -struct PolicyReceivePair; - -struct PolicyOwnNode; - -struct SendSet; - -struct PolicySend; - -struct ItemSend; - -struct ItemReceive; - -struct ReceiveSet; - -struct PolicyReceive; - -struct AccessSet; - -struct PolicyAccess; - -struct ItemAccess; - -struct DecisionItem; - -struct NameScoresPair; - -enum Decision { - Decision_ANY = 0, - Decision_ALLOW = 1, - Decision_DENY = 2, - Decision_CHECK = 3, - Decision_MIN = Decision_ANY, - Decision_MAX = Decision_CHECK -}; - -inline const Decision (&EnumValuesDecision())[4] { - static const Decision values[] = { - Decision_ANY, - Decision_ALLOW, - Decision_DENY, - Decision_CHECK - }; - return values; -} - -inline const char * const *EnumNamesDecision() { - static const char * const names[] = { - "ANY", - "ALLOW", - "DENY", - "CHECK", - nullptr - }; - return names; -} - -inline const char *EnumNameDecision(Decision e) { - if (e < Decision_ANY || e > Decision_CHECK) return ""; - const size_t index = static_cast(e); - return EnumNamesDecision()[index]; -} - -enum BusAccessType { - BusAccessType_USER = 0, - BusAccessType_GROUP = 1, - BusAccessType_ALL_USERS = 2, - BusAccessType_ALL_GROUPS = 3, - BusAccessType_MIN = BusAccessType_USER, - BusAccessType_MAX = BusAccessType_ALL_GROUPS -}; - -inline const BusAccessType (&EnumValuesBusAccessType())[4] { - static const BusAccessType values[] = { - BusAccessType_USER, - BusAccessType_GROUP, - BusAccessType_ALL_USERS, - BusAccessType_ALL_GROUPS - }; - return values; -} - -inline const char * const *EnumNamesBusAccessType() { - static const char * const names[] = { - "USER", - "GROUP", - "ALL_USERS", - "ALL_GROUPS", - nullptr - }; - return names; -} - -inline const char *EnumNameBusAccessType(BusAccessType e) { - if (e < BusAccessType_USER || e > BusAccessType_ALL_GROUPS) return ""; - const size_t index = static_cast(e); - return EnumNamesBusAccessType()[index]; -} - -enum MessageType { - MessageType_ANY = 0, - MessageType_METHOD_CALL = 1, - MessageType_METHOD_RETURN = 2, - MessageType_ERROR = 3, - MessageType_SIGNAL = 4, - MessageType_MIN = MessageType_ANY, - MessageType_MAX = MessageType_SIGNAL -}; - -inline const MessageType (&EnumValuesMessageType())[5] { - static const MessageType values[] = { - MessageType_ANY, - MessageType_METHOD_CALL, - MessageType_METHOD_RETURN, - MessageType_ERROR, - MessageType_SIGNAL - }; - return values; -} - -inline const char * const *EnumNamesMessageType() { - static const char * const names[] = { - "ANY", - "METHOD_CALL", - "METHOD_RETURN", - "ERROR", - "SIGNAL", - nullptr - }; - return names; -} - -inline const char *EnumNameMessageType(MessageType e) { - if (e < MessageType_ANY || e > MessageType_SIGNAL) return ""; - const size_t index = static_cast(e); - return EnumNamesMessageType()[index]; -} - -struct File FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_M_OWN_SET = 4, - VT_M_SEND_SET = 6, - VT_M_RECEIVE_SET = 8, - VT_M_ACCESS_SET = 10 - }; - const OwnSet *m_own_set() const { - return GetPointer(VT_M_OWN_SET); - } - const SendSet *m_send_set() const { - return GetPointer(VT_M_SEND_SET); - } - const ReceiveSet *m_receive_set() const { - return GetPointer(VT_M_RECEIVE_SET); - } - const AccessSet *m_access_set() const { - return GetPointer(VT_M_ACCESS_SET); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_M_OWN_SET) && - verifier.VerifyTable(m_own_set()) && - VerifyOffset(verifier, VT_M_SEND_SET) && - verifier.VerifyTable(m_send_set()) && - VerifyOffset(verifier, VT_M_RECEIVE_SET) && - verifier.VerifyTable(m_receive_set()) && - VerifyOffset(verifier, VT_M_ACCESS_SET) && - verifier.VerifyTable(m_access_set()) && - verifier.EndTable(); - } -}; - -struct FileBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_m_own_set(flatbuffers::Offset m_own_set) { - fbb_.AddOffset(File::VT_M_OWN_SET, m_own_set); - } - void add_m_send_set(flatbuffers::Offset m_send_set) { - fbb_.AddOffset(File::VT_M_SEND_SET, m_send_set); - } - void add_m_receive_set(flatbuffers::Offset m_receive_set) { - fbb_.AddOffset(File::VT_M_RECEIVE_SET, m_receive_set); - } - void add_m_access_set(flatbuffers::Offset m_access_set) { - fbb_.AddOffset(File::VT_M_ACCESS_SET, m_access_set); - } - explicit FileBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - FileBuilder &operator=(const FileBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateFile( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset m_own_set = 0, - flatbuffers::Offset m_send_set = 0, - flatbuffers::Offset m_receive_set = 0, - flatbuffers::Offset m_access_set = 0) { - FileBuilder builder_(_fbb); - builder_.add_m_access_set(m_access_set); - builder_.add_m_receive_set(m_receive_set); - builder_.add_m_send_set(m_send_set); - builder_.add_m_own_set(m_own_set); - return builder_.Finish(); -} - -struct OwnSet FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_CONTEXT_DEFAULT = 4, - VT_CONTEXT_MANDATORY = 6, - VT_USER = 8, - VT_GROUP = 10 - }; - const PolicyOwn *context_default() const { - return GetPointer(VT_CONTEXT_DEFAULT); - } - const PolicyOwn *context_mandatory() const { - return GetPointer(VT_CONTEXT_MANDATORY); - } - const flatbuffers::Vector> *user() const { - return GetPointer> *>(VT_USER); - } - const flatbuffers::Vector> *group() const { - return GetPointer> *>(VT_GROUP); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_CONTEXT_DEFAULT) && - verifier.VerifyTable(context_default()) && - VerifyOffset(verifier, VT_CONTEXT_MANDATORY) && - verifier.VerifyTable(context_mandatory()) && - VerifyOffset(verifier, VT_USER) && - verifier.VerifyVector(user()) && - verifier.VerifyVectorOfTables(user()) && - VerifyOffset(verifier, VT_GROUP) && - verifier.VerifyVector(group()) && - verifier.VerifyVectorOfTables(group()) && - verifier.EndTable(); - } -}; - -struct OwnSetBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_context_default(flatbuffers::Offset context_default) { - fbb_.AddOffset(OwnSet::VT_CONTEXT_DEFAULT, context_default); - } - void add_context_mandatory(flatbuffers::Offset context_mandatory) { - fbb_.AddOffset(OwnSet::VT_CONTEXT_MANDATORY, context_mandatory); - } - void add_user(flatbuffers::Offset>> user) { - fbb_.AddOffset(OwnSet::VT_USER, user); - } - void add_group(flatbuffers::Offset>> group) { - fbb_.AddOffset(OwnSet::VT_GROUP, group); - } - explicit OwnSetBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - OwnSetBuilder &operator=(const OwnSetBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateOwnSet( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0, - flatbuffers::Offset>> user = 0, - flatbuffers::Offset>> group = 0) { - OwnSetBuilder builder_(_fbb); - builder_.add_group(group); - builder_.add_user(user); - builder_.add_context_mandatory(context_mandatory); - builder_.add_context_default(context_default); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateOwnSetDirect( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0, - const std::vector> *user = nullptr, - const std::vector> *group = nullptr) { - auto user__ = user ? _fbb.CreateVector>(*user) : 0; - auto group__ = group ? _fbb.CreateVector>(*group) : 0; - return FB::CreateOwnSet( - _fbb, - context_default, - context_mandatory, - user__, - group__); -} - -struct PolicyOwn FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_TREE = 4 - }; - const PolicyOwnNode *tree() const { - return GetPointer(VT_TREE); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_TREE) && - verifier.VerifyTable(tree()) && - verifier.EndTable(); - } -}; - -struct PolicyOwnBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_tree(flatbuffers::Offset tree) { - fbb_.AddOffset(PolicyOwn::VT_TREE, tree); - } - explicit PolicyOwnBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicyOwnBuilder &operator=(const PolicyOwnBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicyOwn( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset tree = 0) { - PolicyOwnBuilder builder_(_fbb); - builder_.add_tree(tree); - return builder_.Finish(); -} - -struct PolicyOwnPair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_ID = 4, - VT_POLICY = 6 - }; - int64_t id() const { - return GetField(VT_ID, 0); - } - bool KeyCompareLessThan(const PolicyOwnPair *o) const { - return id() < o->id(); - } - int KeyCompareWithValue(int64_t val) const { - return static_cast(id() > val) - static_cast(id() < val); - } - const PolicyOwn *policy() const { - return GetPointer(VT_POLICY); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_ID) && - VerifyOffset(verifier, VT_POLICY) && - verifier.VerifyTable(policy()) && - verifier.EndTable(); - } -}; - -struct PolicyOwnPairBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_id(int64_t id) { - fbb_.AddElement(PolicyOwnPair::VT_ID, id, 0); - } - void add_policy(flatbuffers::Offset policy) { - fbb_.AddOffset(PolicyOwnPair::VT_POLICY, policy); - } - explicit PolicyOwnPairBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicyOwnPairBuilder &operator=(const PolicyOwnPairBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicyOwnPair( - flatbuffers::FlatBufferBuilder &_fbb, - int64_t id = 0, - flatbuffers::Offset policy = 0) { - PolicyOwnPairBuilder builder_(_fbb); - builder_.add_id(id); - builder_.add_policy(policy); - return builder_.Finish(); -} - -struct PolicySendPair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_ID = 4, - VT_POLICY = 6 - }; - int64_t id() const { - return GetField(VT_ID, 0); - } - bool KeyCompareLessThan(const PolicySendPair *o) const { - return id() < o->id(); - } - int KeyCompareWithValue(int64_t val) const { - return static_cast(id() > val) - static_cast(id() < val); - } - const PolicySend *policy() const { - return GetPointer(VT_POLICY); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_ID) && - VerifyOffset(verifier, VT_POLICY) && - verifier.VerifyTable(policy()) && - verifier.EndTable(); - } -}; - -struct PolicySendPairBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_id(int64_t id) { - fbb_.AddElement(PolicySendPair::VT_ID, id, 0); - } - void add_policy(flatbuffers::Offset policy) { - fbb_.AddOffset(PolicySendPair::VT_POLICY, policy); - } - explicit PolicySendPairBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicySendPairBuilder &operator=(const PolicySendPairBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicySendPair( - flatbuffers::FlatBufferBuilder &_fbb, - int64_t id = 0, - flatbuffers::Offset policy = 0) { - PolicySendPairBuilder builder_(_fbb); - builder_.add_id(id); - builder_.add_policy(policy); - return builder_.Finish(); -} - -struct PolicyReceivePair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_ID = 4, - VT_POLICY = 6 - }; - int64_t id() const { - return GetField(VT_ID, 0); - } - bool KeyCompareLessThan(const PolicyReceivePair *o) const { - return id() < o->id(); - } - int KeyCompareWithValue(int64_t val) const { - return static_cast(id() > val) - static_cast(id() < val); - } - const PolicyReceive *policy() const { - return GetPointer(VT_POLICY); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_ID) && - VerifyOffset(verifier, VT_POLICY) && - verifier.VerifyTable(policy()) && - verifier.EndTable(); - } -}; - -struct PolicyReceivePairBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_id(int64_t id) { - fbb_.AddElement(PolicyReceivePair::VT_ID, id, 0); - } - void add_policy(flatbuffers::Offset policy) { - fbb_.AddOffset(PolicyReceivePair::VT_POLICY, policy); - } - explicit PolicyReceivePairBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicyReceivePairBuilder &operator=(const PolicyReceivePairBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicyReceivePair( - flatbuffers::FlatBufferBuilder &_fbb, - int64_t id = 0, - flatbuffers::Offset policy = 0) { - PolicyReceivePairBuilder builder_(_fbb); - builder_.add_id(id); - builder_.add_policy(policy); - return builder_.Finish(); -} - -struct PolicyOwnNode FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_TOKEN = 4, - VT_PREFIX_DECISION_ITEM = 6, - VT_DECISION_ITEM = 8, - VT_CHILDREN = 10 - }; - const flatbuffers::String *token() const { - return GetPointer(VT_TOKEN); - } - bool KeyCompareLessThan(const PolicyOwnNode *o) const { - return *token() < *o->token(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(token()->c_str(), val); - } - const DecisionItem *prefix_decision_item() const { - return GetPointer(VT_PREFIX_DECISION_ITEM); - } - const DecisionItem *decision_item() const { - return GetPointer(VT_DECISION_ITEM); - } - const flatbuffers::Vector> *children() const { - return GetPointer> *>(VT_CHILDREN); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_TOKEN) && - verifier.VerifyString(token()) && - VerifyOffset(verifier, VT_PREFIX_DECISION_ITEM) && - verifier.VerifyTable(prefix_decision_item()) && - VerifyOffset(verifier, VT_DECISION_ITEM) && - verifier.VerifyTable(decision_item()) && - VerifyOffset(verifier, VT_CHILDREN) && - verifier.VerifyVector(children()) && - verifier.VerifyVectorOfTables(children()) && - verifier.EndTable(); - } -}; - -struct PolicyOwnNodeBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_token(flatbuffers::Offset token) { - fbb_.AddOffset(PolicyOwnNode::VT_TOKEN, token); - } - void add_prefix_decision_item(flatbuffers::Offset prefix_decision_item) { - fbb_.AddOffset(PolicyOwnNode::VT_PREFIX_DECISION_ITEM, prefix_decision_item); - } - void add_decision_item(flatbuffers::Offset decision_item) { - fbb_.AddOffset(PolicyOwnNode::VT_DECISION_ITEM, decision_item); - } - void add_children(flatbuffers::Offset>> children) { - fbb_.AddOffset(PolicyOwnNode::VT_CHILDREN, children); - } - explicit PolicyOwnNodeBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicyOwnNodeBuilder &operator=(const PolicyOwnNodeBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, PolicyOwnNode::VT_TOKEN); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicyOwnNode( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset token = 0, - flatbuffers::Offset prefix_decision_item = 0, - flatbuffers::Offset decision_item = 0, - flatbuffers::Offset>> children = 0) { - PolicyOwnNodeBuilder builder_(_fbb); - builder_.add_children(children); - builder_.add_decision_item(decision_item); - builder_.add_prefix_decision_item(prefix_decision_item); - builder_.add_token(token); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreatePolicyOwnNodeDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *token = nullptr, - flatbuffers::Offset prefix_decision_item = 0, - flatbuffers::Offset decision_item = 0, - const std::vector> *children = nullptr) { - auto token__ = token ? _fbb.CreateString(token) : 0; - auto children__ = children ? _fbb.CreateVector>(*children) : 0; - return FB::CreatePolicyOwnNode( - _fbb, - token__, - prefix_decision_item, - decision_item, - children__); -} - -struct SendSet FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_CONTEXT_DEFAULT = 4, - VT_CONTEXT_MANDATORY = 6, - VT_USER = 8, - VT_GROUP = 10 - }; - const PolicySend *context_default() const { - return GetPointer(VT_CONTEXT_DEFAULT); - } - const PolicySend *context_mandatory() const { - return GetPointer(VT_CONTEXT_MANDATORY); - } - const flatbuffers::Vector> *user() const { - return GetPointer> *>(VT_USER); - } - const flatbuffers::Vector> *group() const { - return GetPointer> *>(VT_GROUP); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_CONTEXT_DEFAULT) && - verifier.VerifyTable(context_default()) && - VerifyOffset(verifier, VT_CONTEXT_MANDATORY) && - verifier.VerifyTable(context_mandatory()) && - VerifyOffset(verifier, VT_USER) && - verifier.VerifyVector(user()) && - verifier.VerifyVectorOfTables(user()) && - VerifyOffset(verifier, VT_GROUP) && - verifier.VerifyVector(group()) && - verifier.VerifyVectorOfTables(group()) && - verifier.EndTable(); - } -}; - -struct SendSetBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_context_default(flatbuffers::Offset context_default) { - fbb_.AddOffset(SendSet::VT_CONTEXT_DEFAULT, context_default); - } - void add_context_mandatory(flatbuffers::Offset context_mandatory) { - fbb_.AddOffset(SendSet::VT_CONTEXT_MANDATORY, context_mandatory); - } - void add_user(flatbuffers::Offset>> user) { - fbb_.AddOffset(SendSet::VT_USER, user); - } - void add_group(flatbuffers::Offset>> group) { - fbb_.AddOffset(SendSet::VT_GROUP, group); - } - explicit SendSetBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - SendSetBuilder &operator=(const SendSetBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateSendSet( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0, - flatbuffers::Offset>> user = 0, - flatbuffers::Offset>> group = 0) { - SendSetBuilder builder_(_fbb); - builder_.add_group(group); - builder_.add_user(user); - builder_.add_context_mandatory(context_mandatory); - builder_.add_context_default(context_default); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateSendSetDirect( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0, - const std::vector> *user = nullptr, - const std::vector> *group = nullptr) { - auto user__ = user ? _fbb.CreateVector>(*user) : 0; - auto group__ = group ? _fbb.CreateVector>(*group) : 0; - return FB::CreateSendSet( - _fbb, - context_default, - context_mandatory, - user__, - group__); -} - -struct PolicySend FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_ITEMS = 4, - VT_INDEX = 6, - VT_PREFIX_INDEX = 8 - }; - const flatbuffers::Vector> *items() const { - return GetPointer> *>(VT_ITEMS); - } - const flatbuffers::Vector> *index() const { - return GetPointer> *>(VT_INDEX); - } - const flatbuffers::Vector *prefix_index() const { - return GetPointer *>(VT_PREFIX_INDEX); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_ITEMS) && - verifier.VerifyVector(items()) && - verifier.VerifyVectorOfTables(items()) && - VerifyOffset(verifier, VT_INDEX) && - verifier.VerifyVector(index()) && - verifier.VerifyVectorOfTables(index()) && - VerifyOffset(verifier, VT_PREFIX_INDEX) && - verifier.VerifyVector(prefix_index()) && - verifier.EndTable(); - } -}; - -struct PolicySendBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_items(flatbuffers::Offset>> items) { - fbb_.AddOffset(PolicySend::VT_ITEMS, items); - } - void add_index(flatbuffers::Offset>> index) { - fbb_.AddOffset(PolicySend::VT_INDEX, index); - } - void add_prefix_index(flatbuffers::Offset> prefix_index) { - fbb_.AddOffset(PolicySend::VT_PREFIX_INDEX, prefix_index); - } - explicit PolicySendBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicySendBuilder &operator=(const PolicySendBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicySend( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset>> items = 0, - flatbuffers::Offset>> index = 0, - flatbuffers::Offset> prefix_index = 0) { - PolicySendBuilder builder_(_fbb); - builder_.add_prefix_index(prefix_index); - builder_.add_index(index); - builder_.add_items(items); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreatePolicySendDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const std::vector> *items = nullptr, - const std::vector> *index = nullptr, - const std::vector *prefix_index = nullptr) { - auto items__ = items ? _fbb.CreateVector>(*items) : 0; - auto index__ = index ? _fbb.CreateVector>(*index) : 0; - auto prefix_index__ = prefix_index ? _fbb.CreateVector(*prefix_index) : 0; - return FB::CreatePolicySend( - _fbb, - items__, - index__, - prefix_index__); -} - -struct ItemSend FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_DECISION = 4, - VT_NAME = 6, - VT_INTERFACE = 8, - VT_MEMBER = 10, - VT_PATH = 12, - VT_TYPE = 14, - VT_IS_NAME_PREFIX = 16 - }; - const DecisionItem *decision() const { - return GetPointer(VT_DECISION); - } - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - const flatbuffers::String *interface() const { - return GetPointer(VT_INTERFACE); - } - const flatbuffers::String *member() const { - return GetPointer(VT_MEMBER); - } - const flatbuffers::String *path() const { - return GetPointer(VT_PATH); - } - MessageType type() const { - return static_cast(GetField(VT_TYPE, 0)); - } - bool is_name_prefix() const { - return GetField(VT_IS_NAME_PREFIX, 0) != 0; - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_DECISION) && - verifier.VerifyTable(decision()) && - VerifyOffset(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffset(verifier, VT_INTERFACE) && - verifier.VerifyString(interface()) && - VerifyOffset(verifier, VT_MEMBER) && - verifier.VerifyString(member()) && - VerifyOffset(verifier, VT_PATH) && - verifier.VerifyString(path()) && - VerifyField(verifier, VT_TYPE) && - VerifyField(verifier, VT_IS_NAME_PREFIX) && - verifier.EndTable(); - } -}; - -struct ItemSendBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_decision(flatbuffers::Offset decision) { - fbb_.AddOffset(ItemSend::VT_DECISION, decision); - } - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(ItemSend::VT_NAME, name); - } - void add_interface(flatbuffers::Offset interface) { - fbb_.AddOffset(ItemSend::VT_INTERFACE, interface); - } - void add_member(flatbuffers::Offset member) { - fbb_.AddOffset(ItemSend::VT_MEMBER, member); - } - void add_path(flatbuffers::Offset path) { - fbb_.AddOffset(ItemSend::VT_PATH, path); - } - void add_type(MessageType type) { - fbb_.AddElement(ItemSend::VT_TYPE, static_cast(type), 0); - } - void add_is_name_prefix(bool is_name_prefix) { - fbb_.AddElement(ItemSend::VT_IS_NAME_PREFIX, static_cast(is_name_prefix), 0); - } - explicit ItemSendBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ItemSendBuilder &operator=(const ItemSendBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateItemSend( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset decision = 0, - flatbuffers::Offset name = 0, - flatbuffers::Offset interface = 0, - flatbuffers::Offset member = 0, - flatbuffers::Offset path = 0, - MessageType type = MessageType_ANY, - bool is_name_prefix = false) { - ItemSendBuilder builder_(_fbb); - builder_.add_path(path); - builder_.add_member(member); - builder_.add_interface(interface); - builder_.add_name(name); - builder_.add_decision(decision); - builder_.add_is_name_prefix(is_name_prefix); - builder_.add_type(type); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateItemSendDirect( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset decision = 0, - const char *name = nullptr, - const char *interface = nullptr, - const char *member = nullptr, - const char *path = nullptr, - MessageType type = MessageType_ANY, - bool is_name_prefix = false) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto interface__ = interface ? _fbb.CreateString(interface) : 0; - auto member__ = member ? _fbb.CreateString(member) : 0; - auto path__ = path ? _fbb.CreateString(path) : 0; - return FB::CreateItemSend( - _fbb, - decision, - name__, - interface__, - member__, - path__, - type, - is_name_prefix); -} - -struct ItemReceive FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_DECISION = 4, - VT_NAME = 6, - VT_INTERFACE = 8, - VT_MEMBER = 10, - VT_PATH = 12, - VT_TYPE = 14, - VT_IS_NAME_PREFIX = 16 - }; - const DecisionItem *decision() const { - return GetPointer(VT_DECISION); - } - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - const flatbuffers::String *interface() const { - return GetPointer(VT_INTERFACE); - } - const flatbuffers::String *member() const { - return GetPointer(VT_MEMBER); - } - const flatbuffers::String *path() const { - return GetPointer(VT_PATH); - } - MessageType type() const { - return static_cast(GetField(VT_TYPE, 0)); - } - bool is_name_prefix() const { - return GetField(VT_IS_NAME_PREFIX, 0) != 0; - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_DECISION) && - verifier.VerifyTable(decision()) && - VerifyOffset(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffset(verifier, VT_INTERFACE) && - verifier.VerifyString(interface()) && - VerifyOffset(verifier, VT_MEMBER) && - verifier.VerifyString(member()) && - VerifyOffset(verifier, VT_PATH) && - verifier.VerifyString(path()) && - VerifyField(verifier, VT_TYPE) && - VerifyField(verifier, VT_IS_NAME_PREFIX) && - verifier.EndTable(); - } -}; - -struct ItemReceiveBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_decision(flatbuffers::Offset decision) { - fbb_.AddOffset(ItemReceive::VT_DECISION, decision); - } - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(ItemReceive::VT_NAME, name); - } - void add_interface(flatbuffers::Offset interface) { - fbb_.AddOffset(ItemReceive::VT_INTERFACE, interface); - } - void add_member(flatbuffers::Offset member) { - fbb_.AddOffset(ItemReceive::VT_MEMBER, member); - } - void add_path(flatbuffers::Offset path) { - fbb_.AddOffset(ItemReceive::VT_PATH, path); - } - void add_type(MessageType type) { - fbb_.AddElement(ItemReceive::VT_TYPE, static_cast(type), 0); - } - void add_is_name_prefix(bool is_name_prefix) { - fbb_.AddElement(ItemReceive::VT_IS_NAME_PREFIX, static_cast(is_name_prefix), 0); - } - explicit ItemReceiveBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ItemReceiveBuilder &operator=(const ItemReceiveBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateItemReceive( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset decision = 0, - flatbuffers::Offset name = 0, - flatbuffers::Offset interface = 0, - flatbuffers::Offset member = 0, - flatbuffers::Offset path = 0, - MessageType type = MessageType_ANY, - bool is_name_prefix = false) { - ItemReceiveBuilder builder_(_fbb); - builder_.add_path(path); - builder_.add_member(member); - builder_.add_interface(interface); - builder_.add_name(name); - builder_.add_decision(decision); - builder_.add_is_name_prefix(is_name_prefix); - builder_.add_type(type); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateItemReceiveDirect( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset decision = 0, - const char *name = nullptr, - const char *interface = nullptr, - const char *member = nullptr, - const char *path = nullptr, - MessageType type = MessageType_ANY, - bool is_name_prefix = false) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto interface__ = interface ? _fbb.CreateString(interface) : 0; - auto member__ = member ? _fbb.CreateString(member) : 0; - auto path__ = path ? _fbb.CreateString(path) : 0; - return FB::CreateItemReceive( - _fbb, - decision, - name__, - interface__, - member__, - path__, - type, - is_name_prefix); -} - -struct ReceiveSet FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_CONTEXT_DEFAULT = 4, - VT_CONTEXT_MANDATORY = 6, - VT_USER = 8, - VT_GROUP = 10 - }; - const PolicyReceive *context_default() const { - return GetPointer(VT_CONTEXT_DEFAULT); - } - const PolicyReceive *context_mandatory() const { - return GetPointer(VT_CONTEXT_MANDATORY); - } - const flatbuffers::Vector> *user() const { - return GetPointer> *>(VT_USER); - } - const flatbuffers::Vector> *group() const { - return GetPointer> *>(VT_GROUP); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_CONTEXT_DEFAULT) && - verifier.VerifyTable(context_default()) && - VerifyOffset(verifier, VT_CONTEXT_MANDATORY) && - verifier.VerifyTable(context_mandatory()) && - VerifyOffset(verifier, VT_USER) && - verifier.VerifyVector(user()) && - verifier.VerifyVectorOfTables(user()) && - VerifyOffset(verifier, VT_GROUP) && - verifier.VerifyVector(group()) && - verifier.VerifyVectorOfTables(group()) && - verifier.EndTable(); - } -}; - -struct ReceiveSetBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_context_default(flatbuffers::Offset context_default) { - fbb_.AddOffset(ReceiveSet::VT_CONTEXT_DEFAULT, context_default); - } - void add_context_mandatory(flatbuffers::Offset context_mandatory) { - fbb_.AddOffset(ReceiveSet::VT_CONTEXT_MANDATORY, context_mandatory); - } - void add_user(flatbuffers::Offset>> user) { - fbb_.AddOffset(ReceiveSet::VT_USER, user); - } - void add_group(flatbuffers::Offset>> group) { - fbb_.AddOffset(ReceiveSet::VT_GROUP, group); - } - explicit ReceiveSetBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ReceiveSetBuilder &operator=(const ReceiveSetBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateReceiveSet( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0, - flatbuffers::Offset>> user = 0, - flatbuffers::Offset>> group = 0) { - ReceiveSetBuilder builder_(_fbb); - builder_.add_group(group); - builder_.add_user(user); - builder_.add_context_mandatory(context_mandatory); - builder_.add_context_default(context_default); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateReceiveSetDirect( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0, - const std::vector> *user = nullptr, - const std::vector> *group = nullptr) { - auto user__ = user ? _fbb.CreateVector>(*user) : 0; - auto group__ = group ? _fbb.CreateVector>(*group) : 0; - return FB::CreateReceiveSet( - _fbb, - context_default, - context_mandatory, - user__, - group__); -} - -struct PolicyReceive FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_ITEMS = 4 - }; - const flatbuffers::Vector> *items() const { - return GetPointer> *>(VT_ITEMS); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_ITEMS) && - verifier.VerifyVector(items()) && - verifier.VerifyVectorOfTables(items()) && - verifier.EndTable(); - } -}; - -struct PolicyReceiveBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_items(flatbuffers::Offset>> items) { - fbb_.AddOffset(PolicyReceive::VT_ITEMS, items); - } - explicit PolicyReceiveBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicyReceiveBuilder &operator=(const PolicyReceiveBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicyReceive( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset>> items = 0) { - PolicyReceiveBuilder builder_(_fbb); - builder_.add_items(items); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreatePolicyReceiveDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const std::vector> *items = nullptr) { - auto items__ = items ? _fbb.CreateVector>(*items) : 0; - return FB::CreatePolicyReceive( - _fbb, - items__); -} - -struct AccessSet FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_CONTEXT_DEFAULT = 4, - VT_CONTEXT_MANDATORY = 6 - }; - const PolicyAccess *context_default() const { - return GetPointer(VT_CONTEXT_DEFAULT); - } - const PolicyAccess *context_mandatory() const { - return GetPointer(VT_CONTEXT_MANDATORY); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_CONTEXT_DEFAULT) && - verifier.VerifyTable(context_default()) && - VerifyOffset(verifier, VT_CONTEXT_MANDATORY) && - verifier.VerifyTable(context_mandatory()) && - verifier.EndTable(); - } -}; - -struct AccessSetBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_context_default(flatbuffers::Offset context_default) { - fbb_.AddOffset(AccessSet::VT_CONTEXT_DEFAULT, context_default); - } - void add_context_mandatory(flatbuffers::Offset context_mandatory) { - fbb_.AddOffset(AccessSet::VT_CONTEXT_MANDATORY, context_mandatory); - } - explicit AccessSetBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - AccessSetBuilder &operator=(const AccessSetBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateAccessSet( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset context_default = 0, - flatbuffers::Offset context_mandatory = 0) { - AccessSetBuilder builder_(_fbb); - builder_.add_context_mandatory(context_mandatory); - builder_.add_context_default(context_default); - return builder_.Finish(); -} - -struct PolicyAccess FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_ITEMS = 4 - }; - const flatbuffers::Vector> *items() const { - return GetPointer> *>(VT_ITEMS); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_ITEMS) && - verifier.VerifyVector(items()) && - verifier.VerifyVectorOfTables(items()) && - verifier.EndTable(); - } -}; - -struct PolicyAccessBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_items(flatbuffers::Offset>> items) { - fbb_.AddOffset(PolicyAccess::VT_ITEMS, items); - } - explicit PolicyAccessBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - PolicyAccessBuilder &operator=(const PolicyAccessBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreatePolicyAccess( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset>> items = 0) { - PolicyAccessBuilder builder_(_fbb); - builder_.add_items(items); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreatePolicyAccessDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const std::vector> *items = nullptr) { - auto items__ = items ? _fbb.CreateVector>(*items) : 0; - return FB::CreatePolicyAccess( - _fbb, - items__); -} - -struct ItemAccess FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_UID = 4, - VT_GID = 6, - VT_DECISION = 8, - VT_TYPE = 10 - }; - uint32_t uid() const { - return GetField(VT_UID, 0); - } - uint32_t gid() const { - return GetField(VT_GID, 0); - } - const DecisionItem *decision() const { - return GetPointer(VT_DECISION); - } - BusAccessType type() const { - return static_cast(GetField(VT_TYPE, 0)); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_UID) && - VerifyField(verifier, VT_GID) && - VerifyOffset(verifier, VT_DECISION) && - verifier.VerifyTable(decision()) && - VerifyField(verifier, VT_TYPE) && - verifier.EndTable(); - } -}; - -struct ItemAccessBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_uid(uint32_t uid) { - fbb_.AddElement(ItemAccess::VT_UID, uid, 0); - } - void add_gid(uint32_t gid) { - fbb_.AddElement(ItemAccess::VT_GID, gid, 0); - } - void add_decision(flatbuffers::Offset decision) { - fbb_.AddOffset(ItemAccess::VT_DECISION, decision); - } - void add_type(BusAccessType type) { - fbb_.AddElement(ItemAccess::VT_TYPE, static_cast(type), 0); - } - explicit ItemAccessBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ItemAccessBuilder &operator=(const ItemAccessBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateItemAccess( - flatbuffers::FlatBufferBuilder &_fbb, - uint32_t uid = 0, - uint32_t gid = 0, - flatbuffers::Offset decision = 0, - BusAccessType type = BusAccessType_USER) { - ItemAccessBuilder builder_(_fbb); - builder_.add_decision(decision); - builder_.add_gid(gid); - builder_.add_uid(uid); - builder_.add_type(type); - return builder_.Finish(); -} - -struct DecisionItem FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_DECISION = 4, - VT_PRIVILEGE = 6 - }; - Decision decision() const { - return static_cast(GetField(VT_DECISION, 0)); - } - const flatbuffers::String *privilege() const { - return GetPointer(VT_PRIVILEGE); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_DECISION) && - VerifyOffset(verifier, VT_PRIVILEGE) && - verifier.VerifyString(privilege()) && - verifier.EndTable(); - } -}; - -struct DecisionItemBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_decision(Decision decision) { - fbb_.AddElement(DecisionItem::VT_DECISION, static_cast(decision), 0); - } - void add_privilege(flatbuffers::Offset privilege) { - fbb_.AddOffset(DecisionItem::VT_PRIVILEGE, privilege); - } - explicit DecisionItemBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - DecisionItemBuilder &operator=(const DecisionItemBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateDecisionItem( - flatbuffers::FlatBufferBuilder &_fbb, - Decision decision = Decision_ANY, - flatbuffers::Offset privilege = 0) { - DecisionItemBuilder builder_(_fbb); - builder_.add_privilege(privilege); - builder_.add_decision(decision); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateDecisionItemDirect( - flatbuffers::FlatBufferBuilder &_fbb, - Decision decision = Decision_ANY, - const char *privilege = nullptr) { - auto privilege__ = privilege ? _fbb.CreateString(privilege) : 0; - return FB::CreateDecisionItem( - _fbb, - decision, - privilege__); -} - -struct NameScoresPair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_BEST_SCORE = 6, - VT_ITEM_REFS = 8 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - bool KeyCompareLessThan(const NameScoresPair *o) const { - return *name() < *o->name(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(name()->c_str(), val); - } - uint32_t best_score() const { - return GetField(VT_BEST_SCORE, 0); - } - const flatbuffers::Vector *item_refs() const { - return GetPointer *>(VT_ITEM_REFS); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyField(verifier, VT_BEST_SCORE) && - VerifyOffset(verifier, VT_ITEM_REFS) && - verifier.VerifyVector(item_refs()) && - verifier.EndTable(); - } -}; - -struct NameScoresPairBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(NameScoresPair::VT_NAME, name); - } - void add_best_score(uint32_t best_score) { - fbb_.AddElement(NameScoresPair::VT_BEST_SCORE, best_score, 0); - } - void add_item_refs(flatbuffers::Offset> item_refs) { - fbb_.AddOffset(NameScoresPair::VT_ITEM_REFS, item_refs); - } - explicit NameScoresPairBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - NameScoresPairBuilder &operator=(const NameScoresPairBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, NameScoresPair::VT_NAME); - return o; - } -}; - -inline flatbuffers::Offset CreateNameScoresPair( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - uint32_t best_score = 0, - flatbuffers::Offset> item_refs = 0) { - NameScoresPairBuilder builder_(_fbb); - builder_.add_item_refs(item_refs); - builder_.add_best_score(best_score); - builder_.add_name(name); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateNameScoresPairDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - uint32_t best_score = 0, - const std::vector *item_refs = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto item_refs__ = item_refs ? _fbb.CreateVector(*item_refs) : 0; - return FB::CreateNameScoresPair( - _fbb, - name__, - best_score, - item_refs__); -} - -inline const FB::File *GetFile(const void *buf) { - return flatbuffers::GetRoot(buf); -} - -inline const FB::File *GetSizePrefixedFile(const void *buf) { - return flatbuffers::GetSizePrefixedRoot(buf); -} - -inline const char *FileIdentifier() { - return "LDP2"; -} - -inline bool FileBufferHasIdentifier(const void *buf) { - return flatbuffers::BufferHasIdentifier( - buf, FileIdentifier()); -} - -inline bool VerifyFileBuffer( - flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(FileIdentifier()); -} - -inline bool VerifySizePrefixedFileBuffer( - flatbuffers::Verifier &verifier) { - return verifier.VerifySizePrefixedBuffer(FileIdentifier()); -} - -inline void FinishFileBuffer( - flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { - fbb.Finish(root, FileIdentifier()); -} - -inline void FinishSizePrefixedFileBuffer( - flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { - fbb.FinishSizePrefixed(root, FileIdentifier()); -} - -} // namespace FB - -#endif // FLATBUFFERS_GENERATED_FB_FB_H_ diff --git a/src/internal/include/flatbuffers/base.h b/src/internal/include/flatbuffers/base.h deleted file mode 100644 index 295c7f6..0000000 --- a/src/internal/include/flatbuffers/base.h +++ /dev/null @@ -1,373 +0,0 @@ -#ifndef FLATBUFFERS_BASE_H_ -#define FLATBUFFERS_BASE_H_ - -// clang-format off - -// If activate should be declared and included first. -#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \ - defined(_MSC_VER) && defined(_DEBUG) - // The _CRTDBG_MAP_ALLOC inside will replace - // calloc/free (etc) to its debug version using #define directives. - #define _CRTDBG_MAP_ALLOC - #include - #include - // Replace operator new by trace-enabled version. - #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) - #define new DEBUG_NEW -#endif - -#if !defined(FLATBUFFERS_ASSERT) -#include -#define FLATBUFFERS_ASSERT assert -#elif defined(FLATBUFFERS_ASSERT_INCLUDE) -// Include file with forward declaration -#include FLATBUFFERS_ASSERT_INCLUDE -#endif - -#ifndef ARDUINO -#include -#endif - -#include -#include -#include - -#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) - #include -#else - #include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _STLPORT_VERSION - #define FLATBUFFERS_CPP98_STL -#endif -#ifndef FLATBUFFERS_CPP98_STL - #include -#endif - -#include "flatbuffers/stl_emulation.h" - -// Note the __clang__ check is needed, because clang presents itself -// as an older GNUC compiler (4.2). -// Clang 3.3 and later implement all of the ISO C++ 2011 standard. -// Clang 3.4 and later implement all of the ISO C++ 2014 standard. -// http://clang.llvm.org/cxx_status.html - -// Note the MSVC value '__cplusplus' may be incorrect: -// The '__cplusplus' predefined macro in the MSVC stuck at the value 199711L, -// indicating (erroneously!) that the compiler conformed to the C++98 Standard. -// This value should be correct starting from MSVC2017-15.7-Preview-3. -// The '__cplusplus' will be valid only if MSVC2017-15.7-P3 and the `/Zc:__cplusplus` switch is set. -// Workaround (for details see MSDN): -// Use the _MSC_VER and _MSVC_LANG definition instead of the __cplusplus for compatibility. -// The _MSVC_LANG macro reports the Standard version regardless of the '/Zc:__cplusplus' switch. - -#if defined(__GNUC__) && !defined(__clang__) - #define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#else - #define FLATBUFFERS_GCC 0 -#endif - -#if defined(__clang__) - #define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) -#else - #define FLATBUFFERS_CLANG 0 -#endif - -/// @cond FLATBUFFERS_INTERNAL -#if __cplusplus <= 199711L && \ - (!defined(_MSC_VER) || _MSC_VER < 1600) && \ - (!defined(__GNUC__) || \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400)) - #error A C++11 compatible compiler with support for the auto typing is \ - required for FlatBuffers. - #error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ -#endif - -#if !defined(__clang__) && \ - defined(__GNUC__) && \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600) - // Backwards compatability for g++ 4.4, and 4.5 which don't have the nullptr - // and constexpr keywords. Note the __clang__ check is needed, because clang - // presents itself as an older GNUC compiler. - #ifndef nullptr_t - const class nullptr_t { - public: - template inline operator T*() const { return 0; } - private: - void operator&() const; - } nullptr = {}; - #endif - #ifndef constexpr - #define constexpr const - #endif -#endif - -// The wire format uses a little endian encoding (since that's efficient for -// the common platforms). -#if defined(__s390x__) - #define FLATBUFFERS_LITTLEENDIAN 0 -#endif // __s390x__ -#if !defined(FLATBUFFERS_LITTLEENDIAN) - #if defined(__GNUC__) || defined(__clang__) - #ifdef __BIG_ENDIAN__ - #define FLATBUFFERS_LITTLEENDIAN 0 - #else - #define FLATBUFFERS_LITTLEENDIAN 1 - #endif // __BIG_ENDIAN__ - #elif defined(_MSC_VER) - #if defined(_M_PPC) - #define FLATBUFFERS_LITTLEENDIAN 0 - #else - #define FLATBUFFERS_LITTLEENDIAN 1 - #endif - #else - #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN. - #endif -#endif // !defined(FLATBUFFERS_LITTLEENDIAN) - -#define FLATBUFFERS_VERSION_MAJOR 1 -#define FLATBUFFERS_VERSION_MINOR 10 -#define FLATBUFFERS_VERSION_REVISION 0 -#define FLATBUFFERS_STRING_EXPAND(X) #X -#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) - -#if (!defined(_MSC_VER) || _MSC_VER > 1600) && \ - (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \ - defined(__clang__) - #define FLATBUFFERS_FINAL_CLASS final - #define FLATBUFFERS_OVERRIDE override - #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t -#else - #define FLATBUFFERS_FINAL_CLASS - #define FLATBUFFERS_OVERRIDE - #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE -#endif - -#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \ - (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ - (defined(__cpp_constexpr) && __cpp_constexpr >= 200704) - #define FLATBUFFERS_CONSTEXPR constexpr -#else - #define FLATBUFFERS_CONSTEXPR const -#endif - -#if (defined(__cplusplus) && __cplusplus >= 201402L) || \ - (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) - #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR -#else - #define FLATBUFFERS_CONSTEXPR_CPP14 -#endif - -#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ - (defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \ - defined(__clang__) - #define FLATBUFFERS_NOEXCEPT noexcept -#else - #define FLATBUFFERS_NOEXCEPT -#endif - -// NOTE: the FLATBUFFERS_DELETE_FUNC macro may change the access mode to -// private, so be sure to put it at the end or reset access mode explicitly. -#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \ - (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \ - defined(__clang__) - #define FLATBUFFERS_DELETE_FUNC(func) func = delete; -#else - #define FLATBUFFERS_DELETE_FUNC(func) private: func; -#endif - -#ifndef FLATBUFFERS_HAS_STRING_VIEW - // Only provide flatbuffers::string_view if __has_include can be used - // to detect a header that provides an implementation - #if defined(__has_include) - // Check for std::string_view (in c++17) - #if __has_include() && (__cplusplus >= 201606 || _HAS_CXX17) - #include - namespace flatbuffers { - typedef std::string_view string_view; - } - #define FLATBUFFERS_HAS_STRING_VIEW 1 - // Check for std::experimental::string_view (in c++14, compiler-dependent) - #elif __has_include() && (__cplusplus >= 201411) - #include - namespace flatbuffers { - typedef std::experimental::string_view string_view; - } - #define FLATBUFFERS_HAS_STRING_VIEW 1 - #endif - #endif // __has_include -#endif // !FLATBUFFERS_HAS_STRING_VIEW - -#ifndef FLATBUFFERS_HAS_NEW_STRTOD - // Modern (C++11) strtod and strtof functions are available for use. - // 1) nan/inf strings as argument of strtod; - // 2) hex-float as argument of strtod/strtof. - #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \ - (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \ - (defined(__clang__)) - #define FLATBUFFERS_HAS_NEW_STRTOD 1 - #endif -#endif // !FLATBUFFERS_HAS_NEW_STRTOD - -#ifndef FLATBUFFERS_LOCALE_INDEPENDENT - // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}. - // They are part of the POSIX-2008 but not part of the C/C++ standard. - // GCC/Clang have definition (_XOPEN_SOURCE>=700) if POSIX-2008. - #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \ - (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE>=700))) - #define FLATBUFFERS_LOCALE_INDEPENDENT 1 - #else - #define FLATBUFFERS_LOCALE_INDEPENDENT 0 - #endif -#endif // !FLATBUFFERS_LOCALE_INDEPENDENT - -// Suppress Undefined Behavior Sanitizer (recoverable only). Usage: -// - __supress_ubsan__("undefined") -// - __supress_ubsan__("signed-integer-overflow") -#if defined(__clang__) - #define __supress_ubsan__(type) __attribute__((no_sanitize(type))) -#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409) - #define __supress_ubsan__(type) __attribute__((no_sanitize_undefined)) -#else - #define __supress_ubsan__(type) -#endif - -// This is constexpr function used for checking compile-time constants. -// Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`. -template FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) { - return !!t; -} - -// Enable C++ attribute [[]] if std:c++17 or higher. -#if ((__cplusplus >= 201703L) \ - || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) - // All attributes unknown to an implementation are ignored without causing an error. - #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]] - - #define FLATBUFFERS_FALLTHROUGH() [[fallthrough]] -#else - #define FLATBUFFERS_ATTRIBUTE(attr) - - #if FLATBUFFERS_CLANG >= 30800 - #define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]] - #elif FLATBUFFERS_GCC >= 70300 - #define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]] - #else - #define FLATBUFFERS_FALLTHROUGH() - #endif -#endif - -/// @endcond - -/// @file -namespace flatbuffers { - -/// @cond FLATBUFFERS_INTERNAL -// Our default offset / size type, 32bit on purpose on 64bit systems. -// Also, using a consistent offset type maintains compatibility of serialized -// offset values between 32bit and 64bit systems. -typedef uint32_t uoffset_t; - -// Signed offsets for references that can go in both directions. -typedef int32_t soffset_t; - -// Offset/index used in v-tables, can be changed to uint8_t in -// format forks to save a bit of space if desired. -typedef uint16_t voffset_t; - -typedef uintmax_t largest_scalar_t; - -// In 32bits, this evaluates to 2GB - 1 -#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(soffset_t) * 8 - 1)) - 1) - -// We support aligning the contents of buffers up to this size. -#define FLATBUFFERS_MAX_ALIGNMENT 16 - -#if defined(_MSC_VER) - #pragma warning(push) - #pragma warning(disable: 4127) // C4127: conditional expression is constant -#endif - -template T EndianSwap(T t) { - #if defined(_MSC_VER) - #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort - #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong - #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64 - #else - #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__) - // __builtin_bswap16 was missing prior to GCC 4.8. - #define FLATBUFFERS_BYTESWAP16(x) \ - static_cast(__builtin_bswap32(static_cast(x) << 16)) - #else - #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16 - #endif - #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32 - #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64 - #endif - if (sizeof(T) == 1) { // Compile-time if-then's. - return t; - } else if (sizeof(T) == 2) { - union { T t; uint16_t i; } u; - u.t = t; - u.i = FLATBUFFERS_BYTESWAP16(u.i); - return u.t; - } else if (sizeof(T) == 4) { - union { T t; uint32_t i; } u; - u.t = t; - u.i = FLATBUFFERS_BYTESWAP32(u.i); - return u.t; - } else if (sizeof(T) == 8) { - union { T t; uint64_t i; } u; - u.t = t; - u.i = FLATBUFFERS_BYTESWAP64(u.i); - return u.t; - } else { - FLATBUFFERS_ASSERT(0); - } -} - -#if defined(_MSC_VER) - #pragma warning(pop) -#endif - - -template T EndianScalar(T t) { - #if FLATBUFFERS_LITTLEENDIAN - return t; - #else - return EndianSwap(t); - #endif -} - -template -// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. -__supress_ubsan__("alignment") -T ReadScalar(const void *p) { - return EndianScalar(*reinterpret_cast(p)); -} - -template -// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. -__supress_ubsan__("alignment") -void WriteScalar(void *p, T t) { - *reinterpret_cast(p) = EndianScalar(t); -} - -// Computes how many bytes you'd have to pad to be able to write an -// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in -// memory). -inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) { - return ((~buf_size) + 1) & (scalar_size - 1); -} - -} // namespace flatbuffers -#endif // FLATBUFFERS_BASE_H_ diff --git a/src/internal/include/flatbuffers/code_generators.h b/src/internal/include/flatbuffers/code_generators.h deleted file mode 100644 index df09ca0..0000000 --- a/src/internal/include/flatbuffers/code_generators.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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. - */ - -#ifndef FLATBUFFERS_CODE_GENERATORS_H_ -#define FLATBUFFERS_CODE_GENERATORS_H_ - -#include -#include -#include "flatbuffers/idl.h" - -namespace flatbuffers { - -// Utility class to assist in generating code through use of text templates. -// -// Example code: -// CodeWriter code; -// code.SetValue("NAME", "Foo"); -// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }"; -// code.SetValue("NAME", "Bar"); -// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }"; -// std::cout << code.ToString() << std::endl; -// -// Output: -// void Foo() { printf("%s", "Foo"); } -// void Bar() { printf("%s", "Bar"); } -class CodeWriter { - public: - CodeWriter() {} - - // Clears the current "written" code. - void Clear() { - stream_.str(""); - stream_.clear(); - } - - // Associates a key with a value. All subsequent calls to operator+=, where - // the specified key is contained in {{ and }} delimiters will be replaced by - // the given value. - void SetValue(const std::string &key, const std::string &value) { - value_map_[key] = value; - } - - // Appends the given text to the generated code as well as a newline - // character. Any text within {{ and }} delimeters is replaced by values - // previously stored in the CodeWriter by calling SetValue above. The newline - // will be suppressed if the text ends with the \\ character. - void operator+=(std::string text); - - // Returns the current contents of the CodeWriter as a std::string. - std::string ToString() const { return stream_.str(); } - - private: - std::map value_map_; - std::stringstream stream_; -}; - -class BaseGenerator { - public: - virtual bool generate() = 0; - - static std::string NamespaceDir(const Parser &parser, const std::string &path, - const Namespace &ns); - - protected: - BaseGenerator(const Parser &parser, const std::string &path, - const std::string &file_name, - const std::string qualifying_start, - const std::string qualifying_separator) - : parser_(parser), - path_(path), - file_name_(file_name), - qualifying_start_(qualifying_start), - qualifying_separator_(qualifying_separator) {} - virtual ~BaseGenerator() {} - - // No copy/assign. - BaseGenerator &operator=(const BaseGenerator &); - BaseGenerator(const BaseGenerator &); - - std::string NamespaceDir(const Namespace &ns) const; - - static const char *FlatBuffersGeneratedWarning(); - - static std::string FullNamespace(const char *separator, const Namespace &ns); - - static std::string LastNamespacePart(const Namespace &ns); - - // tracks the current namespace for early exit in WrapInNameSpace - // c++, java and csharp returns a different namespace from - // the following default (no early exit, always fully qualify), - // which works for js and php - virtual const Namespace *CurrentNameSpace() const { return nullptr; } - - // Ensure that a type is prefixed with its namespace whenever it is used - // outside of its namespace. - std::string WrapInNameSpace(const Namespace *ns, - const std::string &name) const; - - std::string WrapInNameSpace(const Definition &def) const; - - std::string GetNameSpace(const Definition &def) const; - - const Parser &parser_; - const std::string &path_; - const std::string &file_name_; - const std::string qualifying_start_; - const std::string qualifying_separator_; -}; - -struct CommentConfig { - const char *first_line; - const char *content_line_prefix; - const char *last_line; -}; - -extern void GenComment(const std::vector &dc, - std::string *code_ptr, const CommentConfig *config, - const char *prefix = ""); - -class FloatConstantGenerator { - public: - virtual ~FloatConstantGenerator(){}; - std::string GenFloatConstant(const FieldDef &field) const; - - private: - virtual std::string Value(double v, const std::string &src) const = 0; - virtual std::string Inf(double v) const = 0; - virtual std::string NaN(double v) const = 0; - - virtual std::string Value(float v, const std::string &src) const = 0; - virtual std::string Inf(float v) const = 0; - virtual std::string NaN(float v) const = 0; - - template - std::string GenFloatConstantImpl(const FieldDef &field) const; -}; - -class SimpleFloatConstantGenerator : public FloatConstantGenerator { - public: - SimpleFloatConstantGenerator(const char *nan_number, - const char *pos_inf_number, - const char *neg_inf_number); - - private: - std::string Value(double v, - const std::string &src) const FLATBUFFERS_OVERRIDE; - std::string Inf(double v) const FLATBUFFERS_OVERRIDE; - std::string NaN(double v) const FLATBUFFERS_OVERRIDE; - - std::string Value(float v, const std::string &src) const FLATBUFFERS_OVERRIDE; - std::string Inf(float v) const FLATBUFFERS_OVERRIDE; - std::string NaN(float v) const FLATBUFFERS_OVERRIDE; - - const std::string nan_number_; - const std::string pos_inf_number_; - const std::string neg_inf_number_; -}; - -// C++, C#, Java like generator. -class TypedFloatConstantGenerator : public FloatConstantGenerator { - public: - TypedFloatConstantGenerator(const char *double_prefix, - const char *single_prefix, const char *nan_number, - const char *pos_inf_number, - const char *neg_inf_number = ""); - - private: - std::string Value(double v, - const std::string &src) const FLATBUFFERS_OVERRIDE; - std::string Inf(double v) const FLATBUFFERS_OVERRIDE; - - std::string NaN(double v) const FLATBUFFERS_OVERRIDE; - - std::string Value(float v, const std::string &src) const FLATBUFFERS_OVERRIDE; - std::string Inf(float v) const FLATBUFFERS_OVERRIDE; - std::string NaN(float v) const FLATBUFFERS_OVERRIDE; - - std::string MakeNaN(const std::string &prefix) const; - std::string MakeInf(bool neg, const std::string &prefix) const; - - const std::string double_prefix_; - const std::string single_prefix_; - const std::string nan_number_; - const std::string pos_inf_number_; - const std::string neg_inf_number_; -}; - -} // namespace flatbuffers - -#endif // FLATBUFFERS_CODE_GENERATORS_H_ diff --git a/src/internal/include/flatbuffers/flatbuffers.h b/src/internal/include/flatbuffers/flatbuffers.h deleted file mode 100644 index 8f5ae32..0000000 --- a/src/internal/include/flatbuffers/flatbuffers.h +++ /dev/null @@ -1,2616 +0,0 @@ -/* - * 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. - */ - -#ifndef FLATBUFFERS_H_ -#define FLATBUFFERS_H_ - -#include "flatbuffers/base.h" - -#if defined(FLATBUFFERS_NAN_DEFAULTS) -#include -#endif - -namespace flatbuffers { -// Generic 'operator==' with conditional specialisations. -template inline bool IsTheSameAs(T e, T def) { return e == def; } - -#if defined(FLATBUFFERS_NAN_DEFAULTS) && \ - (!defined(_MSC_VER) || _MSC_VER >= 1800) -// Like `operator==(e, def)` with weak NaN if T=(float|double). -template<> inline bool IsTheSameAs(float e, float def) { - return (e == def) || (std::isnan(def) && std::isnan(e)); -} -template<> inline bool IsTheSameAs(double e, double def) { - return (e == def) || (std::isnan(def) && std::isnan(e)); -} -#endif - -// Wrapper for uoffset_t to allow safe template specialization. -// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset). -template struct Offset { - uoffset_t o; - Offset() : o(0) {} - Offset(uoffset_t _o) : o(_o) {} - Offset Union() const { return Offset(o); } - bool IsNull() const { return !o; } -}; - -inline void EndianCheck() { - int endiantest = 1; - // If this fails, see FLATBUFFERS_LITTLEENDIAN above. - FLATBUFFERS_ASSERT(*reinterpret_cast(&endiantest) == - FLATBUFFERS_LITTLEENDIAN); - (void)endiantest; -} - -template FLATBUFFERS_CONSTEXPR size_t AlignOf() { - // clang-format off - #ifdef _MSC_VER - return __alignof(T); - #else - #ifndef alignof - return __alignof__(T); - #else - return alignof(T); - #endif - #endif - // clang-format on -} - -// When we read serialized data from memory, in the case of most scalars, -// we want to just read T, but in the case of Offset, we want to actually -// perform the indirection and return a pointer. -// The template specialization below does just that. -// It is wrapped in a struct since function templates can't overload on the -// return type like this. -// The typedef is for the convenience of callers of this function -// (avoiding the need for a trailing return decltype) -template struct IndirectHelper { - typedef T return_type; - typedef T mutable_return_type; - static const size_t element_stride = sizeof(T); - static return_type Read(const uint8_t *p, uoffset_t i) { - return EndianScalar((reinterpret_cast(p))[i]); - } -}; -template struct IndirectHelper> { - typedef const T *return_type; - typedef T *mutable_return_type; - static const size_t element_stride = sizeof(uoffset_t); - static return_type Read(const uint8_t *p, uoffset_t i) { - p += i * sizeof(uoffset_t); - return reinterpret_cast(p + ReadScalar(p)); - } -}; -template struct IndirectHelper { - typedef const T *return_type; - typedef T *mutable_return_type; - static const size_t element_stride = sizeof(T); - static return_type Read(const uint8_t *p, uoffset_t i) { - return reinterpret_cast(p + i * sizeof(T)); - } -}; - -// An STL compatible iterator implementation for Vector below, effectively -// calling Get() for every element. -template struct VectorIterator { - typedef std::random_access_iterator_tag iterator_category; - typedef IT value_type; - typedef ptrdiff_t difference_type; - typedef IT *pointer; - typedef IT &reference; - - VectorIterator(const uint8_t *data, uoffset_t i) - : data_(data + IndirectHelper::element_stride * i) {} - VectorIterator(const VectorIterator &other) : data_(other.data_) {} - VectorIterator() : data_(nullptr) {} - - VectorIterator &operator=(const VectorIterator &other) { - data_ = other.data_; - return *this; - } - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - VectorIterator &operator=(VectorIterator &&other) { - data_ = other.data_; - return *this; - } - #endif // !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - - bool operator==(const VectorIterator &other) const { - return data_ == other.data_; - } - - bool operator<(const VectorIterator &other) const { - return data_ < other.data_; - } - - bool operator!=(const VectorIterator &other) const { - return data_ != other.data_; - } - - difference_type operator-(const VectorIterator &other) const { - return (data_ - other.data_) / IndirectHelper::element_stride; - } - - IT operator*() const { return IndirectHelper::Read(data_, 0); } - - IT operator->() const { return IndirectHelper::Read(data_, 0); } - - VectorIterator &operator++() { - data_ += IndirectHelper::element_stride; - return *this; - } - - VectorIterator operator++(int) { - VectorIterator temp(data_, 0); - data_ += IndirectHelper::element_stride; - return temp; - } - - VectorIterator operator+(const uoffset_t &offset) const { - return VectorIterator(data_ + offset * IndirectHelper::element_stride, - 0); - } - - VectorIterator &operator+=(const uoffset_t &offset) { - data_ += offset * IndirectHelper::element_stride; - return *this; - } - - VectorIterator &operator--() { - data_ -= IndirectHelper::element_stride; - return *this; - } - - VectorIterator operator--(int) { - VectorIterator temp(data_, 0); - data_ -= IndirectHelper::element_stride; - return temp; - } - - VectorIterator operator-(const uoffset_t &offset) const { - return VectorIterator(data_ - offset * IndirectHelper::element_stride, - 0); - } - - VectorIterator &operator-=(const uoffset_t &offset) { - data_ -= offset * IndirectHelper::element_stride; - return *this; - } - - private: - const uint8_t *data_; -}; - -template struct VectorReverseIterator : - public std::reverse_iterator { - - explicit VectorReverseIterator(Iterator iter) : std::reverse_iterator(iter) {} - - typename Iterator::value_type operator*() const { return *(std::reverse_iterator::current - 1); } - - typename Iterator::value_type operator->() const { return *(std::reverse_iterator::current - 1); } -}; - -struct String; - -// This is used as a helper type for accessing vectors. -// Vector::data() assumes the vector elements start after the length field. -template class Vector { - public: - typedef VectorIterator::mutable_return_type> - iterator; - typedef VectorIterator::return_type> - const_iterator; - typedef VectorReverseIterator reverse_iterator; - typedef VectorReverseIterator const_reverse_iterator; - - uoffset_t size() const { return EndianScalar(length_); } - - // Deprecated: use size(). Here for backwards compatibility. - FLATBUFFERS_ATTRIBUTE(deprecated("use size() instead")) - uoffset_t Length() const { return size(); } - - typedef typename IndirectHelper::return_type return_type; - typedef typename IndirectHelper::mutable_return_type mutable_return_type; - - return_type Get(uoffset_t i) const { - FLATBUFFERS_ASSERT(i < size()); - return IndirectHelper::Read(Data(), i); - } - - return_type operator[](uoffset_t i) const { return Get(i); } - - // If this is a Vector of enums, T will be its storage type, not the enum - // type. This function makes it convenient to retrieve value with enum - // type E. - template E GetEnum(uoffset_t i) const { - return static_cast(Get(i)); - } - - // If this a vector of unions, this does the cast for you. There's no check - // to make sure this is the right type! - template const U *GetAs(uoffset_t i) const { - return reinterpret_cast(Get(i)); - } - - // If this a vector of unions, this does the cast for you. There's no check - // to make sure this is actually a string! - const String *GetAsString(uoffset_t i) const { - return reinterpret_cast(Get(i)); - } - - const void *GetStructFromOffset(size_t o) const { - return reinterpret_cast(Data() + o); - } - - iterator begin() { return iterator(Data(), 0); } - const_iterator begin() const { return const_iterator(Data(), 0); } - - iterator end() { return iterator(Data(), size()); } - const_iterator end() const { return const_iterator(Data(), size()); } - - reverse_iterator rbegin() { return reverse_iterator(end()); } - const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - - reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } - - const_iterator cbegin() const { return begin(); } - - const_iterator cend() const { return end(); } - - const_reverse_iterator crbegin() const { return rbegin(); } - - const_reverse_iterator crend() const { return rend(); } - - // Change elements if you have a non-const pointer to this object. - // Scalars only. See reflection.h, and the documentation. - void Mutate(uoffset_t i, const T &val) { - FLATBUFFERS_ASSERT(i < size()); - WriteScalar(data() + i, val); - } - - // Change an element of a vector of tables (or strings). - // "val" points to the new table/string, as you can obtain from - // e.g. reflection::AddFlatBuffer(). - void MutateOffset(uoffset_t i, const uint8_t *val) { - FLATBUFFERS_ASSERT(i < size()); - static_assert(sizeof(T) == sizeof(uoffset_t), "Unrelated types"); - WriteScalar(data() + i, - static_cast(val - (Data() + i * sizeof(uoffset_t)))); - } - - // Get a mutable pointer to tables/strings inside this vector. - mutable_return_type GetMutableObject(uoffset_t i) const { - FLATBUFFERS_ASSERT(i < size()); - return const_cast(IndirectHelper::Read(Data(), i)); - } - - // The raw data in little endian format. Use with care. - const uint8_t *Data() const { - return reinterpret_cast(&length_ + 1); - } - - uint8_t *Data() { return reinterpret_cast(&length_ + 1); } - - // Similarly, but typed, much like std::vector::data - const T *data() const { return reinterpret_cast(Data()); } - T *data() { return reinterpret_cast(Data()); } - - template return_type LookupByKey(K key) const { - void *search_result = std::bsearch( - &key, Data(), size(), IndirectHelper::element_stride, KeyCompare); - - if (!search_result) { - return nullptr; // Key not found. - } - - const uint8_t *element = reinterpret_cast(search_result); - - return IndirectHelper::Read(element, 0); - } - - protected: - // This class is only used to access pre-existing data. Don't ever - // try to construct these manually. - Vector(); - - uoffset_t length_; - - private: - // This class is a pointer. Copying will therefore create an invalid object. - // Private and unimplemented copy constructor. - Vector(const Vector &); - - template static int KeyCompare(const void *ap, const void *bp) { - const K *key = reinterpret_cast(ap); - const uint8_t *data = reinterpret_cast(bp); - auto table = IndirectHelper::Read(data, 0); - - // std::bsearch compares with the operands transposed, so we negate the - // result here. - return -table->KeyCompareWithValue(*key); - } -}; - -// Represent a vector much like the template above, but in this case we -// don't know what the element types are (used with reflection.h). -class VectorOfAny { - public: - uoffset_t size() const { return EndianScalar(length_); } - - const uint8_t *Data() const { - return reinterpret_cast(&length_ + 1); - } - uint8_t *Data() { return reinterpret_cast(&length_ + 1); } - - protected: - VectorOfAny(); - - uoffset_t length_; - - private: - VectorOfAny(const VectorOfAny &); -}; - -#ifndef FLATBUFFERS_CPP98_STL -template -Vector> *VectorCast(Vector> *ptr) { - static_assert(std::is_base_of::value, "Unrelated types"); - return reinterpret_cast> *>(ptr); -} - -template -const Vector> *VectorCast(const Vector> *ptr) { - static_assert(std::is_base_of::value, "Unrelated types"); - return reinterpret_cast> *>(ptr); -} -#endif - -// Convenient helper function to get the length of any vector, regardless -// of whether it is null or not (the field is not set). -template static inline size_t VectorLength(const Vector *v) { - return v ? v->size() : 0; -} - -// Lexicographically compare two strings (possibly containing nulls), and -// return true if the first is less than the second. -static inline bool StringLessThan(const char *a_data, uoffset_t a_size, - const char *b_data, uoffset_t b_size) { - const auto cmp = memcmp(a_data, b_data, (std::min)(a_size, b_size)); - return cmp == 0 ? a_size < b_size : cmp < 0; -} - -struct String : public Vector { - const char *c_str() const { return reinterpret_cast(Data()); } - std::string str() const { return std::string(c_str(), size()); } - - // clang-format off - #ifdef FLATBUFFERS_HAS_STRING_VIEW - flatbuffers::string_view string_view() const { - return flatbuffers::string_view(c_str(), size()); - } - #endif // FLATBUFFERS_HAS_STRING_VIEW - // clang-format on - - bool operator<(const String &o) const { - return StringLessThan(this->data(), this->size(), o.data(), o.size()); - } -}; - -// Convenience function to get std::string from a String returning an empty -// string on null pointer. -static inline std::string GetString(const String * str) { - return str ? str->str() : ""; -} - -// Convenience function to get char* from a String returning an empty string on -// null pointer. -static inline const char * GetCstring(const String * str) { - return str ? str->c_str() : ""; -} - -// Allocator interface. This is flatbuffers-specific and meant only for -// `vector_downward` usage. -class Allocator { - public: - virtual ~Allocator() {} - - // Allocate `size` bytes of memory. - virtual uint8_t *allocate(size_t size) = 0; - - // Deallocate `size` bytes of memory at `p` allocated by this allocator. - virtual void deallocate(uint8_t *p, size_t size) = 0; - - // Reallocate `new_size` bytes of memory, replacing the old region of size - // `old_size` at `p`. In contrast to a normal realloc, this grows downwards, - // and is intended specifcally for `vector_downward` use. - // `in_use_back` and `in_use_front` indicate how much of `old_size` is - // actually in use at each end, and needs to be copied. - virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, - size_t new_size, size_t in_use_back, - size_t in_use_front) { - FLATBUFFERS_ASSERT(new_size > old_size); // vector_downward only grows - uint8_t *new_p = allocate(new_size); - memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, - in_use_front); - deallocate(old_p, old_size); - return new_p; - } - - protected: - // Called by `reallocate_downward` to copy memory from `old_p` of `old_size` - // to `new_p` of `new_size`. Only memory of size `in_use_front` and - // `in_use_back` will be copied from the front and back of the old memory - // allocation. - void memcpy_downward(uint8_t *old_p, size_t old_size, - uint8_t *new_p, size_t new_size, - size_t in_use_back, size_t in_use_front) { - memcpy(new_p + new_size - in_use_back, old_p + old_size - in_use_back, - in_use_back); - memcpy(new_p, old_p, in_use_front); - } -}; - -// DefaultAllocator uses new/delete to allocate memory regions -class DefaultAllocator : public Allocator { - public: - uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE { - return new uint8_t[size]; - } - - void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { - delete[] p; - } - - static void dealloc(void *p, size_t) { - delete[] static_cast(p); - } -}; - -// These functions allow for a null allocator to mean use the default allocator, -// as used by DetachedBuffer and vector_downward below. -// This is to avoid having a statically or dynamically allocated default -// allocator, or having to move it between the classes that may own it. -inline uint8_t *Allocate(Allocator *allocator, size_t size) { - return allocator ? allocator->allocate(size) - : DefaultAllocator().allocate(size); -} - -inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) { - if (allocator) allocator->deallocate(p, size); - else DefaultAllocator().deallocate(p, size); -} - -inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p, - size_t old_size, size_t new_size, - size_t in_use_back, size_t in_use_front) { - return allocator - ? allocator->reallocate_downward(old_p, old_size, new_size, - in_use_back, in_use_front) - : DefaultAllocator().reallocate_downward(old_p, old_size, new_size, - in_use_back, in_use_front); -} - -// DetachedBuffer is a finished flatbuffer memory region, detached from its -// builder. The original memory region and allocator are also stored so that -// the DetachedBuffer can manage the memory lifetime. -class DetachedBuffer { - public: - DetachedBuffer() - : allocator_(nullptr), - own_allocator_(false), - buf_(nullptr), - reserved_(0), - cur_(nullptr), - size_(0) {} - - DetachedBuffer(Allocator *allocator, bool own_allocator, uint8_t *buf, - size_t reserved, uint8_t *cur, size_t sz) - : allocator_(allocator), - own_allocator_(own_allocator), - buf_(buf), - reserved_(reserved), - cur_(cur), - size_(sz) {} - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - DetachedBuffer(DetachedBuffer &&other) - : allocator_(other.allocator_), - own_allocator_(other.own_allocator_), - buf_(other.buf_), - reserved_(other.reserved_), - cur_(other.cur_), - size_(other.size_) { - other.reset(); - } - // clang-format off - #endif // !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - DetachedBuffer &operator=(DetachedBuffer &&other) { - if (this == &other) - return *this; - - destroy(); - - allocator_ = other.allocator_; - own_allocator_ = other.own_allocator_; - buf_ = other.buf_; - reserved_ = other.reserved_; - cur_ = other.cur_; - size_ = other.size_; - - other.reset(); - - return *this; - } - // clang-format off - #endif // !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - - ~DetachedBuffer() { destroy(); } - - const uint8_t *data() const { return cur_; } - - uint8_t *data() { return cur_; } - - size_t size() const { return size_; } - - // clang-format off - #if 0 // disabled for now due to the ordering of classes in this header - template - bool Verify() const { - Verifier verifier(data(), size()); - return verifier.Verify(nullptr); - } - - template - const T* GetRoot() const { - return flatbuffers::GetRoot(data()); - } - - template - T* GetRoot() { - return flatbuffers::GetRoot(data()); - } - #endif - // clang-format on - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - // These may change access mode, leave these at end of public section - FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other)) - FLATBUFFERS_DELETE_FUNC( - DetachedBuffer &operator=(const DetachedBuffer &other)) - // clang-format off - #endif // !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - -protected: - Allocator *allocator_; - bool own_allocator_; - uint8_t *buf_; - size_t reserved_; - uint8_t *cur_; - size_t size_; - - inline void destroy() { - if (buf_) Deallocate(allocator_, buf_, reserved_); - if (own_allocator_ && allocator_) { delete allocator_; } - reset(); - } - - inline void reset() { - allocator_ = nullptr; - own_allocator_ = false; - buf_ = nullptr; - reserved_ = 0; - cur_ = nullptr; - size_ = 0; - } -}; - -// This is a minimal replication of std::vector functionality, -// except growing from higher to lower addresses. i.e push_back() inserts data -// in the lowest address in the vector. -// Since this vector leaves the lower part unused, we support a "scratch-pad" -// that can be stored there for temporary data, to share the allocated space. -// Essentially, this supports 2 std::vectors in a single buffer. -class vector_downward { - public: - explicit vector_downward(size_t initial_size, - Allocator *allocator, - bool own_allocator, - size_t buffer_minalign) - : allocator_(allocator), - own_allocator_(own_allocator), - initial_size_(initial_size), - buffer_minalign_(buffer_minalign), - reserved_(0), - buf_(nullptr), - cur_(nullptr), - scratch_(nullptr) {} - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - vector_downward(vector_downward &&other) - #else - vector_downward(vector_downward &other) - #endif // defined(FLATBUFFERS_CPP98_STL) - // clang-format on - : allocator_(other.allocator_), - own_allocator_(other.own_allocator_), - initial_size_(other.initial_size_), - buffer_minalign_(other.buffer_minalign_), - reserved_(other.reserved_), - buf_(other.buf_), - cur_(other.cur_), - scratch_(other.scratch_) { - // No change in other.allocator_ - // No change in other.initial_size_ - // No change in other.buffer_minalign_ - other.own_allocator_ = false; - other.reserved_ = 0; - other.buf_ = nullptr; - other.cur_ = nullptr; - other.scratch_ = nullptr; - } - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - vector_downward &operator=(vector_downward &&other) { - // Move construct a temporary and swap idiom - vector_downward temp(std::move(other)); - swap(temp); - return *this; - } - // clang-format off - #endif // defined(FLATBUFFERS_CPP98_STL) - // clang-format on - - ~vector_downward() { - clear_buffer(); - clear_allocator(); - } - - void reset() { - clear_buffer(); - clear(); - } - - void clear() { - if (buf_) { - cur_ = buf_ + reserved_; - } else { - reserved_ = 0; - cur_ = nullptr; - } - clear_scratch(); - } - - void clear_scratch() { - scratch_ = buf_; - } - - void clear_allocator() { - if (own_allocator_ && allocator_) { delete allocator_; } - allocator_ = nullptr; - own_allocator_ = false; - } - - void clear_buffer() { - if (buf_) Deallocate(allocator_, buf_, reserved_); - buf_ = nullptr; - } - - // Relinquish the pointer to the caller. - uint8_t *release_raw(size_t &allocated_bytes, size_t &offset) { - auto *buf = buf_; - allocated_bytes = reserved_; - offset = static_cast(cur_ - buf_); - - // release_raw only relinquishes the buffer ownership. - // Does not deallocate or reset the allocator. Destructor will do that. - buf_ = nullptr; - clear(); - return buf; - } - - // Relinquish the pointer to the caller. - DetachedBuffer release() { - // allocator ownership (if any) is transferred to DetachedBuffer. - DetachedBuffer fb(allocator_, own_allocator_, buf_, reserved_, cur_, - size()); - if (own_allocator_) { - allocator_ = nullptr; - own_allocator_ = false; - } - buf_ = nullptr; - clear(); - return fb; - } - - size_t ensure_space(size_t len) { - FLATBUFFERS_ASSERT(cur_ >= scratch_ && scratch_ >= buf_); - if (len > static_cast(cur_ - scratch_)) { reallocate(len); } - // Beyond this, signed offsets may not have enough range: - // (FlatBuffers > 2GB not supported). - FLATBUFFERS_ASSERT(size() < FLATBUFFERS_MAX_BUFFER_SIZE); - return len; - } - - inline uint8_t *make_space(size_t len) { - size_t space = ensure_space(len); - cur_ -= space; - return cur_; - } - - // Returns nullptr if using the DefaultAllocator. - Allocator *get_custom_allocator() { return allocator_; } - - uoffset_t size() const { - return static_cast(reserved_ - (cur_ - buf_)); - } - - uoffset_t scratch_size() const { - return static_cast(scratch_ - buf_); - } - - size_t capacity() const { return reserved_; } - - uint8_t *data() const { - FLATBUFFERS_ASSERT(cur_); - return cur_; - } - - uint8_t *scratch_data() const { - FLATBUFFERS_ASSERT(buf_); - return buf_; - } - - uint8_t *scratch_end() const { - FLATBUFFERS_ASSERT(scratch_); - return scratch_; - } - - uint8_t *data_at(size_t offset) const { return buf_ + reserved_ - offset; } - - void push(const uint8_t *bytes, size_t num) { - memcpy(make_space(num), bytes, num); - } - - // Specialized version of push() that avoids memcpy call for small data. - template void push_small(const T &little_endian_t) { - make_space(sizeof(T)); - *reinterpret_cast(cur_) = little_endian_t; - } - - template void scratch_push_small(const T &t) { - ensure_space(sizeof(T)); - *reinterpret_cast(scratch_) = t; - scratch_ += sizeof(T); - } - - // fill() is most frequently called with small byte counts (<= 4), - // which is why we're using loops rather than calling memset. - void fill(size_t zero_pad_bytes) { - make_space(zero_pad_bytes); - for (size_t i = 0; i < zero_pad_bytes; i++) cur_[i] = 0; - } - - // Version for when we know the size is larger. - void fill_big(size_t zero_pad_bytes) { - memset(make_space(zero_pad_bytes), 0, zero_pad_bytes); - } - - void pop(size_t bytes_to_remove) { cur_ += bytes_to_remove; } - void scratch_pop(size_t bytes_to_remove) { scratch_ -= bytes_to_remove; } - - void swap(vector_downward &other) { - using std::swap; - swap(allocator_, other.allocator_); - swap(own_allocator_, other.own_allocator_); - swap(initial_size_, other.initial_size_); - swap(buffer_minalign_, other.buffer_minalign_); - swap(reserved_, other.reserved_); - swap(buf_, other.buf_); - swap(cur_, other.cur_); - swap(scratch_, other.scratch_); - } - - void swap_allocator(vector_downward &other) { - using std::swap; - swap(allocator_, other.allocator_); - swap(own_allocator_, other.own_allocator_); - } - - private: - // You shouldn't really be copying instances of this class. - FLATBUFFERS_DELETE_FUNC(vector_downward(const vector_downward &)) - FLATBUFFERS_DELETE_FUNC(vector_downward &operator=(const vector_downward &)) - - Allocator *allocator_; - bool own_allocator_; - size_t initial_size_; - size_t buffer_minalign_; - size_t reserved_; - uint8_t *buf_; - uint8_t *cur_; // Points at location between empty (below) and used (above). - uint8_t *scratch_; // Points to the end of the scratchpad in use. - - void reallocate(size_t len) { - auto old_reserved = reserved_; - auto old_size = size(); - auto old_scratch_size = scratch_size(); - reserved_ += (std::max)(len, - old_reserved ? old_reserved / 2 : initial_size_); - reserved_ = (reserved_ + buffer_minalign_ - 1) & ~(buffer_minalign_ - 1); - if (buf_) { - buf_ = ReallocateDownward(allocator_, buf_, old_reserved, reserved_, - old_size, old_scratch_size); - } else { - buf_ = Allocate(allocator_, reserved_); - } - cur_ = buf_ + reserved_ - old_size; - scratch_ = buf_ + old_scratch_size; - } -}; - -// Converts a Field ID to a virtual table offset. -inline voffset_t FieldIndexToOffset(voffset_t field_id) { - // Should correspond to what EndTable() below builds up. - const int fixed_fields = 2; // Vtable size and Object Size. - return static_cast((field_id + fixed_fields) * sizeof(voffset_t)); -} - -template -const T *data(const std::vector &v) { - return v.empty() ? nullptr : &v.front(); -} -template T *data(std::vector &v) { - return v.empty() ? nullptr : &v.front(); -} - -/// @endcond - -/// @addtogroup flatbuffers_cpp_api -/// @{ -/// @class FlatBufferBuilder -/// @brief Helper class to hold data needed in creation of a FlatBuffer. -/// To serialize data, you typically call one of the `Create*()` functions in -/// the generated code, which in turn call a sequence of `StartTable`/ -/// `PushElement`/`AddElement`/`EndTable`, or the builtin `CreateString`/ -/// `CreateVector` functions. Do this is depth-first order to build up a tree to -/// the root. `Finish()` wraps up the buffer ready for transport. -class FlatBufferBuilder { - public: - /// @brief Default constructor for FlatBufferBuilder. - /// @param[in] initial_size The initial size of the buffer, in bytes. Defaults - /// to `1024`. - /// @param[in] allocator An `Allocator` to use. If null will use - /// `DefaultAllocator`. - /// @param[in] own_allocator Whether the builder/vector should own the - /// allocator. Defaults to / `false`. - /// @param[in] buffer_minalign Force the buffer to be aligned to the given - /// minimum alignment upon reallocation. Only needed if you intend to store - /// types with custom alignment AND you wish to read the buffer in-place - /// directly after creation. - explicit FlatBufferBuilder(size_t initial_size = 1024, - Allocator *allocator = nullptr, - bool own_allocator = false, - size_t buffer_minalign = - AlignOf()) - : buf_(initial_size, allocator, own_allocator, buffer_minalign), - num_field_loc(0), - max_voffset_(0), - nested(false), - finished(false), - minalign_(1), - force_defaults_(false), - dedup_vtables_(true), - string_pool(nullptr) { - EndianCheck(); - } - - // clang-format off - /// @brief Move constructor for FlatBufferBuilder. - #if !defined(FLATBUFFERS_CPP98_STL) - FlatBufferBuilder(FlatBufferBuilder &&other) - #else - FlatBufferBuilder(FlatBufferBuilder &other) - #endif // #if !defined(FLATBUFFERS_CPP98_STL) - : buf_(1024, nullptr, false, AlignOf()), - num_field_loc(0), - max_voffset_(0), - nested(false), - finished(false), - minalign_(1), - force_defaults_(false), - dedup_vtables_(true), - string_pool(nullptr) { - EndianCheck(); - // Default construct and swap idiom. - // Lack of delegating constructors in vs2010 makes it more verbose than needed. - Swap(other); - } - // clang-format on - - // clang-format off - #if !defined(FLATBUFFERS_CPP98_STL) - // clang-format on - /// @brief Move assignment operator for FlatBufferBuilder. - FlatBufferBuilder &operator=(FlatBufferBuilder &&other) { - // Move construct a temporary and swap idiom - FlatBufferBuilder temp(std::move(other)); - Swap(temp); - return *this; - } - // clang-format off - #endif // defined(FLATBUFFERS_CPP98_STL) - // clang-format on - - void Swap(FlatBufferBuilder &other) { - using std::swap; - buf_.swap(other.buf_); - swap(num_field_loc, other.num_field_loc); - swap(max_voffset_, other.max_voffset_); - swap(nested, other.nested); - swap(finished, other.finished); - swap(minalign_, other.minalign_); - swap(force_defaults_, other.force_defaults_); - swap(dedup_vtables_, other.dedup_vtables_); - swap(string_pool, other.string_pool); - } - - ~FlatBufferBuilder() { - if (string_pool) delete string_pool; - } - - void Reset() { - Clear(); // clear builder state - buf_.reset(); // deallocate buffer - } - - /// @brief Reset all the state in this FlatBufferBuilder so it can be reused - /// to construct another buffer. - void Clear() { - ClearOffsets(); - buf_.clear(); - nested = false; - finished = false; - minalign_ = 1; - if (string_pool) string_pool->clear(); - } - - /// @brief The current size of the serialized buffer, counting from the end. - /// @return Returns an `uoffset_t` with the current size of the buffer. - uoffset_t GetSize() const { return buf_.size(); } - - /// @brief Get the serialized buffer (after you call `Finish()`). - /// @return Returns an `uint8_t` pointer to the FlatBuffer data inside the - /// buffer. - uint8_t *GetBufferPointer() const { - Finished(); - return buf_.data(); - } - - /// @brief Get a pointer to an unfinished buffer. - /// @return Returns a `uint8_t` pointer to the unfinished buffer. - uint8_t *GetCurrentBufferPointer() const { return buf_.data(); } - - /// @brief Get the released pointer to the serialized buffer. - /// @warning Do NOT attempt to use this FlatBufferBuilder afterwards! - /// @return A `FlatBuffer` that owns the buffer and its allocator and - /// behaves similar to a `unique_ptr` with a deleter. - FLATBUFFERS_ATTRIBUTE(deprecated("use Release() instead")) DetachedBuffer - ReleaseBufferPointer() { - Finished(); - return buf_.release(); - } - - /// @brief Get the released DetachedBuffer. - /// @return A `DetachedBuffer` that owns the buffer and its allocator. - DetachedBuffer Release() { - Finished(); - return buf_.release(); - } - - /// @brief Get the released pointer to the serialized buffer. - /// @param The size of the memory block containing - /// the serialized `FlatBuffer`. - /// @param The offset from the released pointer where the finished - /// `FlatBuffer` starts. - /// @return A raw pointer to the start of the memory block containing - /// the serialized `FlatBuffer`. - /// @remark If the allocator is owned, it gets deleted when the destructor is called.. - uint8_t *ReleaseRaw(size_t &size, size_t &offset) { - Finished(); - return buf_.release_raw(size, offset); - } - - /// @brief get the minimum alignment this buffer needs to be accessed - /// properly. This is only known once all elements have been written (after - /// you call Finish()). You can use this information if you need to embed - /// a FlatBuffer in some other buffer, such that you can later read it - /// without first having to copy it into its own buffer. - size_t GetBufferMinAlignment() { - Finished(); - return minalign_; - } - - /// @cond FLATBUFFERS_INTERNAL - void Finished() const { - // If you get this assert, you're attempting to get access a buffer - // which hasn't been finished yet. Be sure to call - // FlatBufferBuilder::Finish with your root table. - // If you really need to access an unfinished buffer, call - // GetCurrentBufferPointer instead. - FLATBUFFERS_ASSERT(finished); - } - /// @endcond - - /// @brief In order to save space, fields that are set to their default value - /// don't get serialized into the buffer. - /// @param[in] bool fd When set to `true`, always serializes default values that are set. - /// Optional fields which are not set explicitly, will still not be serialized. - void ForceDefaults(bool fd) { force_defaults_ = fd; } - - /// @brief By default vtables are deduped in order to save space. - /// @param[in] bool dedup When set to `true`, dedup vtables. - void DedupVtables(bool dedup) { dedup_vtables_ = dedup; } - - /// @cond FLATBUFFERS_INTERNAL - void Pad(size_t num_bytes) { buf_.fill(num_bytes); } - - void TrackMinAlign(size_t elem_size) { - if (elem_size > minalign_) minalign_ = elem_size; - } - - void Align(size_t elem_size) { - TrackMinAlign(elem_size); - buf_.fill(PaddingBytes(buf_.size(), elem_size)); - } - - void PushFlatBuffer(const uint8_t *bytes, size_t size) { - PushBytes(bytes, size); - finished = true; - } - - void PushBytes(const uint8_t *bytes, size_t size) { buf_.push(bytes, size); } - - void PopBytes(size_t amount) { buf_.pop(amount); } - - template void AssertScalarT() { - // The code assumes power of 2 sizes and endian-swap-ability. - static_assert(flatbuffers::is_scalar::value, "T must be a scalar type"); - } - - // Write a single aligned scalar to the buffer - template uoffset_t PushElement(T element) { - AssertScalarT(); - T litle_endian_element = EndianScalar(element); - Align(sizeof(T)); - buf_.push_small(litle_endian_element); - return GetSize(); - } - - template uoffset_t PushElement(Offset off) { - // Special case for offsets: see ReferTo below. - return PushElement(ReferTo(off.o)); - } - - // When writing fields, we track where they are, so we can create correct - // vtables later. - void TrackField(voffset_t field, uoffset_t off) { - FieldLoc fl = { off, field }; - buf_.scratch_push_small(fl); - num_field_loc++; - max_voffset_ = (std::max)(max_voffset_, field); - } - - // Like PushElement, but additionally tracks the field this represents. - template void AddElement(voffset_t field, T e, T def) { - // We don't serialize values equal to the default. - if (IsTheSameAs(e, def) && !force_defaults_) return; - auto off = PushElement(e); - TrackField(field, off); - } - - template void AddOffset(voffset_t field, Offset off) { - if (off.IsNull()) return; // Don't store. - AddElement(field, ReferTo(off.o), static_cast(0)); - } - - template void AddStruct(voffset_t field, const T *structptr) { - if (!structptr) return; // Default, don't store. - Align(AlignOf()); - buf_.push_small(*structptr); - TrackField(field, GetSize()); - } - - void AddStructOffset(voffset_t field, uoffset_t off) { - TrackField(field, off); - } - - // Offsets initially are relative to the end of the buffer (downwards). - // This function converts them to be relative to the current location - // in the buffer (when stored here), pointing upwards. - uoffset_t ReferTo(uoffset_t off) { - // Align to ensure GetSize() below is correct. - Align(sizeof(uoffset_t)); - // Offset must refer to something already in buffer. - FLATBUFFERS_ASSERT(off && off <= GetSize()); - return GetSize() - off + static_cast(sizeof(uoffset_t)); - } - - void NotNested() { - // If you hit this, you're trying to construct a Table/Vector/String - // during the construction of its parent table (between the MyTableBuilder - // and table.Finish(). - // Move the creation of these sub-objects to above the MyTableBuilder to - // not get this assert. - // Ignoring this assert may appear to work in simple cases, but the reason - // it is here is that storing objects in-line may cause vtable offsets - // to not fit anymore. It also leads to vtable duplication. - FLATBUFFERS_ASSERT(!nested); - // If you hit this, fields were added outside the scope of a table. - FLATBUFFERS_ASSERT(!num_field_loc); - } - - // From generated code (or from the parser), we call StartTable/EndTable - // with a sequence of AddElement calls in between. - uoffset_t StartTable() { - NotNested(); - nested = true; - return GetSize(); - } - - // This finishes one serialized object by generating the vtable if it's a - // table, comparing it against existing vtables, and writing the - // resulting vtable offset. - uoffset_t EndTable(uoffset_t start) { - // If you get this assert, a corresponding StartTable wasn't called. - FLATBUFFERS_ASSERT(nested); - // Write the vtable offset, which is the start of any Table. - // We fill it's value later. - auto vtableoffsetloc = PushElement(0); - // Write a vtable, which consists entirely of voffset_t elements. - // It starts with the number of offsets, followed by a type id, followed - // by the offsets themselves. In reverse: - // Include space for the last offset and ensure empty tables have a - // minimum size. - max_voffset_ = - (std::max)(static_cast(max_voffset_ + sizeof(voffset_t)), - FieldIndexToOffset(0)); - buf_.fill_big(max_voffset_); - auto table_object_size = vtableoffsetloc - start; - // Vtable use 16bit offsets. - FLATBUFFERS_ASSERT(table_object_size < 0x10000); - WriteScalar(buf_.data() + sizeof(voffset_t), - static_cast(table_object_size)); - WriteScalar(buf_.data(), max_voffset_); - // Write the offsets into the table - for (auto it = buf_.scratch_end() - num_field_loc * sizeof(FieldLoc); - it < buf_.scratch_end(); it += sizeof(FieldLoc)) { - auto field_location = reinterpret_cast(it); - auto pos = static_cast(vtableoffsetloc - field_location->off); - // If this asserts, it means you've set a field twice. - FLATBUFFERS_ASSERT( - !ReadScalar(buf_.data() + field_location->id)); - WriteScalar(buf_.data() + field_location->id, pos); - } - ClearOffsets(); - auto vt1 = reinterpret_cast(buf_.data()); - auto vt1_size = ReadScalar(vt1); - auto vt_use = GetSize(); - // See if we already have generated a vtable with this exact same - // layout before. If so, make it point to the old one, remove this one. - if (dedup_vtables_) { - for (auto it = buf_.scratch_data(); it < buf_.scratch_end(); - it += sizeof(uoffset_t)) { - auto vt_offset_ptr = reinterpret_cast(it); - auto vt2 = reinterpret_cast(buf_.data_at(*vt_offset_ptr)); - auto vt2_size = *vt2; - if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue; - vt_use = *vt_offset_ptr; - buf_.pop(GetSize() - vtableoffsetloc); - break; - } - } - // If this is a new vtable, remember it. - if (vt_use == GetSize()) { buf_.scratch_push_small(vt_use); } - // Fill the vtable offset we created above. - // The offset points from the beginning of the object to where the - // vtable is stored. - // Offsets default direction is downward in memory for future format - // flexibility (storing all vtables at the start of the file). - WriteScalar(buf_.data_at(vtableoffsetloc), - static_cast(vt_use) - - static_cast(vtableoffsetloc)); - - nested = false; - return vtableoffsetloc; - } - - FLATBUFFERS_ATTRIBUTE(deprecated("call the version above instead")) - uoffset_t EndTable(uoffset_t start, voffset_t /*numfields*/) { - return EndTable(start); - } - - // This checks a required field has been set in a given table that has - // just been constructed. - template void Required(Offset table, voffset_t field); - - uoffset_t StartStruct(size_t alignment) { - Align(alignment); - return GetSize(); - } - - uoffset_t EndStruct() { return GetSize(); } - - void ClearOffsets() { - buf_.scratch_pop(num_field_loc * sizeof(FieldLoc)); - num_field_loc = 0; - max_voffset_ = 0; - } - - // Aligns such that when "len" bytes are written, an object can be written - // after it with "alignment" without padding. - void PreAlign(size_t len, size_t alignment) { - TrackMinAlign(alignment); - buf_.fill(PaddingBytes(GetSize() + len, alignment)); - } - template void PreAlign(size_t len) { - AssertScalarT(); - PreAlign(len, sizeof(T)); - } - /// @endcond - - /// @brief Store a string in the buffer, which can contain any binary data. - /// @param[in] str A const char pointer to the data to be stored as a string. - /// @param[in] len The number of bytes that should be stored from `str`. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateString(const char *str, size_t len) { - NotNested(); - PreAlign(len + 1); // Always 0-terminated. - buf_.fill(1); - PushBytes(reinterpret_cast(str), len); - PushElement(static_cast(len)); - return Offset(GetSize()); - } - - /// @brief Store a string in the buffer, which is null-terminated. - /// @param[in] str A const char pointer to a C-string to add to the buffer. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateString(const char *str) { - return CreateString(str, strlen(str)); - } - - /// @brief Store a string in the buffer, which is null-terminated. - /// @param[in] str A char pointer to a C-string to add to the buffer. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateString(char *str) { - return CreateString(str, strlen(str)); - } - - /// @brief Store a string in the buffer, which can contain any binary data. - /// @param[in] str A const reference to a std::string to store in the buffer. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateString(const std::string &str) { - return CreateString(str.c_str(), str.length()); - } - - // clang-format off - #ifdef FLATBUFFERS_HAS_STRING_VIEW - /// @brief Store a string in the buffer, which can contain any binary data. - /// @param[in] str A const string_view to copy in to the buffer. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateString(flatbuffers::string_view str) { - return CreateString(str.data(), str.size()); - } - #endif // FLATBUFFERS_HAS_STRING_VIEW - // clang-format on - - /// @brief Store a string in the buffer, which can contain any binary data. - /// @param[in] str A const pointer to a `String` struct to add to the buffer. - /// @return Returns the offset in the buffer where the string starts - Offset CreateString(const String *str) { - return str ? CreateString(str->c_str(), str->size()) : 0; - } - - /// @brief Store a string in the buffer, which can contain any binary data. - /// @param[in] str A const reference to a std::string like type with support - /// of T::c_str() and T::length() to store in the buffer. - /// @return Returns the offset in the buffer where the string starts. - template Offset CreateString(const T &str) { - return CreateString(str.c_str(), str.length()); - } - - /// @brief Store a string in the buffer, which can contain any binary data. - /// If a string with this exact contents has already been serialized before, - /// instead simply returns the offset of the existing string. - /// @param[in] str A const char pointer to the data to be stored as a string. - /// @param[in] len The number of bytes that should be stored from `str`. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateSharedString(const char *str, size_t len) { - if (!string_pool) - string_pool = new StringOffsetMap(StringOffsetCompare(buf_)); - auto size_before_string = buf_.size(); - // Must first serialize the string, since the set is all offsets into - // buffer. - auto off = CreateString(str, len); - auto it = string_pool->find(off); - // If it exists we reuse existing serialized data! - if (it != string_pool->end()) { - // We can remove the string we serialized. - buf_.pop(buf_.size() - size_before_string); - return *it; - } - // Record this string for future use. - string_pool->insert(off); - return off; - } - - /// @brief Store a string in the buffer, which null-terminated. - /// If a string with this exact contents has already been serialized before, - /// instead simply returns the offset of the existing string. - /// @param[in] str A const char pointer to a C-string to add to the buffer. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateSharedString(const char *str) { - return CreateSharedString(str, strlen(str)); - } - - /// @brief Store a string in the buffer, which can contain any binary data. - /// If a string with this exact contents has already been serialized before, - /// instead simply returns the offset of the existing string. - /// @param[in] str A const reference to a std::string to store in the buffer. - /// @return Returns the offset in the buffer where the string starts. - Offset CreateSharedString(const std::string &str) { - return CreateSharedString(str.c_str(), str.length()); - } - - /// @brief Store a string in the buffer, which can contain any binary data. - /// If a string with this exact contents has already been serialized before, - /// instead simply returns the offset of the existing string. - /// @param[in] str A const pointer to a `String` struct to add to the buffer. - /// @return Returns the offset in the buffer where the string starts - Offset CreateSharedString(const String *str) { - return CreateSharedString(str->c_str(), str->size()); - } - - /// @cond FLATBUFFERS_INTERNAL - uoffset_t EndVector(size_t len) { - FLATBUFFERS_ASSERT(nested); // Hit if no corresponding StartVector. - nested = false; - return PushElement(static_cast(len)); - } - - void StartVector(size_t len, size_t elemsize) { - NotNested(); - nested = true; - PreAlign(len * elemsize); - PreAlign(len * elemsize, elemsize); // Just in case elemsize > uoffset_t. - } - - // Call this right before StartVector/CreateVector if you want to force the - // alignment to be something different than what the element size would - // normally dictate. - // This is useful when storing a nested_flatbuffer in a vector of bytes, - // or when storing SIMD floats, etc. - void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) { - PreAlign(len * elemsize, alignment); - } - - // Similar to ForceVectorAlignment but for String fields. - void ForceStringAlignment(size_t len, size_t alignment) { - PreAlign((len + 1) * sizeof(char), alignment); - } - - /// @endcond - - /// @brief Serialize an array into a FlatBuffer `vector`. - /// @tparam T The data type of the array elements. - /// @param[in] v A pointer to the array of type `T` to serialize into the - /// buffer as a `vector`. - /// @param[in] len The number of elements to serialize. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template Offset> CreateVector(const T *v, size_t len) { - // If this assert hits, you're specifying a template argument that is - // causing the wrong overload to be selected, remove it. - AssertScalarT(); - StartVector(len, sizeof(T)); - // clang-format off - #if FLATBUFFERS_LITTLEENDIAN - PushBytes(reinterpret_cast(v), len * sizeof(T)); - #else - if (sizeof(T) == 1) { - PushBytes(reinterpret_cast(v), len); - } else { - for (auto i = len; i > 0; ) { - PushElement(v[--i]); - } - } - #endif - // clang-format on - return Offset>(EndVector(len)); - } - - template - Offset>> CreateVector(const Offset *v, size_t len) { - StartVector(len, sizeof(Offset)); - for (auto i = len; i > 0;) { PushElement(v[--i]); } - return Offset>>(EndVector(len)); - } - - /// @brief Serialize a `std::vector` into a FlatBuffer `vector`. - /// @tparam T The data type of the `std::vector` elements. - /// @param v A const reference to the `std::vector` to serialize into the - /// buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template Offset> CreateVector(const std::vector &v) { - return CreateVector(data(v), v.size()); - } - - // vector may be implemented using a bit-set, so we can't access it as - // an array. Instead, read elements manually. - // Background: https://isocpp.org/blog/2012/11/on-vectorbool - Offset> CreateVector(const std::vector &v) { - StartVector(v.size(), sizeof(uint8_t)); - for (auto i = v.size(); i > 0;) { - PushElement(static_cast(v[--i])); - } - return Offset>(EndVector(v.size())); - } - - // clang-format off - #ifndef FLATBUFFERS_CPP98_STL - /// @brief Serialize values returned by a function into a FlatBuffer `vector`. - /// This is a convenience function that takes care of iteration for you. - /// @tparam T The data type of the `std::vector` elements. - /// @param f A function that takes the current iteration 0..vector_size-1 and - /// returns any type that you can construct a FlatBuffers vector out of. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template Offset> CreateVector(size_t vector_size, - const std::function &f) { - std::vector elems(vector_size); - for (size_t i = 0; i < vector_size; i++) elems[i] = f(i); - return CreateVector(elems); - } - #endif - // clang-format on - - /// @brief Serialize values returned by a function into a FlatBuffer `vector`. - /// This is a convenience function that takes care of iteration for you. - /// @tparam T The data type of the `std::vector` elements. - /// @param f A function that takes the current iteration 0..vector_size-1, - /// and the state parameter returning any type that you can construct a - /// FlatBuffers vector out of. - /// @param state State passed to f. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVector(size_t vector_size, F f, S *state) { - std::vector elems(vector_size); - for (size_t i = 0; i < vector_size; i++) elems[i] = f(i, state); - return CreateVector(elems); - } - - /// @brief Serialize a `std::vector` into a FlatBuffer `vector`. - /// This is a convenience function for a common case. - /// @param v A const reference to the `std::vector` to serialize into the - /// buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - Offset>> CreateVectorOfStrings( - const std::vector &v) { - std::vector> offsets(v.size()); - for (size_t i = 0; i < v.size(); i++) offsets[i] = CreateString(v[i]); - return CreateVector(offsets); - } - - /// @brief Serialize an array of structs into a FlatBuffer `vector`. - /// @tparam T The data type of the struct array elements. - /// @param[in] v A pointer to the array of type `T` to serialize into the - /// buffer as a `vector`. - /// @param[in] len The number of elements to serialize. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfStructs(const T *v, size_t len) { - StartVector(len * sizeof(T) / AlignOf(), AlignOf()); - PushBytes(reinterpret_cast(v), sizeof(T) * len); - return Offset>(EndVector(len)); - } - - /// @brief Serialize an array of native structs into a FlatBuffer `vector`. - /// @tparam T The data type of the struct array elements. - /// @tparam S The data type of the native struct array elements. - /// @param[in] v A pointer to the array of type `S` to serialize into the - /// buffer as a `vector`. - /// @param[in] len The number of elements to serialize. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfNativeStructs(const S *v, - size_t len) { - extern T Pack(const S &); - typedef T (*Pack_t)(const S &); - std::vector vv(len); - std::transform(v, v + len, vv.begin(), static_cast(Pack)); - return CreateVectorOfStructs(vv.data(), vv.size()); - } - - // clang-format off - #ifndef FLATBUFFERS_CPP98_STL - /// @brief Serialize an array of structs into a FlatBuffer `vector`. - /// @tparam T The data type of the struct array elements. - /// @param[in] f A function that takes the current iteration 0..vector_size-1 - /// and a pointer to the struct that must be filled. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - /// This is mostly useful when flatbuffers are generated with mutation - /// accessors. - template Offset> CreateVectorOfStructs( - size_t vector_size, const std::function &filler) { - T* structs = StartVectorOfStructs(vector_size); - for (size_t i = 0; i < vector_size; i++) { - filler(i, structs); - structs++; - } - return EndVectorOfStructs(vector_size); - } - #endif - // clang-format on - - /// @brief Serialize an array of structs into a FlatBuffer `vector`. - /// @tparam T The data type of the struct array elements. - /// @param[in] f A function that takes the current iteration 0..vector_size-1, - /// a pointer to the struct that must be filled and the state argument. - /// @param[in] state Arbitrary state to pass to f. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - /// This is mostly useful when flatbuffers are generated with mutation - /// accessors. - template - Offset> CreateVectorOfStructs(size_t vector_size, F f, - S *state) { - T *structs = StartVectorOfStructs(vector_size); - for (size_t i = 0; i < vector_size; i++) { - f(i, structs, state); - structs++; - } - return EndVectorOfStructs(vector_size); - } - - /// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector`. - /// @tparam T The data type of the `std::vector` struct elements. - /// @param[in]] v A const reference to the `std::vector` of structs to - /// serialize into the buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfStructs( - const std::vector &v) { - return CreateVectorOfStructs(data(v), v.size()); - } - - /// @brief Serialize a `std::vector` of native structs into a FlatBuffer - /// `vector`. - /// @tparam T The data type of the `std::vector` struct elements. - /// @tparam S The data type of the `std::vector` native struct elements. - /// @param[in]] v A const reference to the `std::vector` of structs to - /// serialize into the buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfNativeStructs( - const std::vector &v) { - return CreateVectorOfNativeStructs(data(v), v.size()); - } - - /// @cond FLATBUFFERS_INTERNAL - template struct StructKeyComparator { - bool operator()(const T &a, const T &b) const { - return a.KeyCompareLessThan(&b); - } - - private: - StructKeyComparator &operator=(const StructKeyComparator &); - }; - /// @endcond - - /// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector` - /// in sorted order. - /// @tparam T The data type of the `std::vector` struct elements. - /// @param[in]] v A const reference to the `std::vector` of structs to - /// serialize into the buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfSortedStructs(std::vector *v) { - return CreateVectorOfSortedStructs(data(*v), v->size()); - } - - /// @brief Serialize a `std::vector` of native structs into a FlatBuffer - /// `vector` in sorted order. - /// @tparam T The data type of the `std::vector` struct elements. - /// @tparam S The data type of the `std::vector` native struct elements. - /// @param[in]] v A const reference to the `std::vector` of structs to - /// serialize into the buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfSortedNativeStructs( - std::vector *v) { - return CreateVectorOfSortedNativeStructs(data(*v), v->size()); - } - - /// @brief Serialize an array of structs into a FlatBuffer `vector` in sorted - /// order. - /// @tparam T The data type of the struct array elements. - /// @param[in] v A pointer to the array of type `T` to serialize into the - /// buffer as a `vector`. - /// @param[in] len The number of elements to serialize. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfSortedStructs(T *v, size_t len) { - std::sort(v, v + len, StructKeyComparator()); - return CreateVectorOfStructs(v, len); - } - - /// @brief Serialize an array of native structs into a FlatBuffer `vector` in - /// sorted order. - /// @tparam T The data type of the struct array elements. - /// @tparam S The data type of the native struct array elements. - /// @param[in] v A pointer to the array of type `S` to serialize into the - /// buffer as a `vector`. - /// @param[in] len The number of elements to serialize. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset> CreateVectorOfSortedNativeStructs(S *v, - size_t len) { - extern T Pack(const S &); - typedef T (*Pack_t)(const S &); - std::vector vv(len); - std::transform(v, v + len, vv.begin(), static_cast(Pack)); - return CreateVectorOfSortedStructs(vv, len); - } - - /// @cond FLATBUFFERS_INTERNAL - template struct TableKeyComparator { - TableKeyComparator(vector_downward &buf) : buf_(buf) {} - bool operator()(const Offset &a, const Offset &b) const { - auto table_a = reinterpret_cast(buf_.data_at(a.o)); - auto table_b = reinterpret_cast(buf_.data_at(b.o)); - return table_a->KeyCompareLessThan(table_b); - } - vector_downward &buf_; - - private: - TableKeyComparator &operator=(const TableKeyComparator &); - }; - /// @endcond - - /// @brief Serialize an array of `table` offsets as a `vector` in the buffer - /// in sorted order. - /// @tparam T The data type that the offset refers to. - /// @param[in] v An array of type `Offset` that contains the `table` - /// offsets to store in the buffer in sorted order. - /// @param[in] len The number of elements to store in the `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset>> CreateVectorOfSortedTables(Offset *v, - size_t len) { - std::sort(v, v + len, TableKeyComparator(buf_)); - return CreateVector(v, len); - } - - /// @brief Serialize an array of `table` offsets as a `vector` in the buffer - /// in sorted order. - /// @tparam T The data type that the offset refers to. - /// @param[in] v An array of type `Offset` that contains the `table` - /// offsets to store in the buffer in sorted order. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template - Offset>> CreateVectorOfSortedTables( - std::vector> *v) { - return CreateVectorOfSortedTables(data(*v), v->size()); - } - - /// @brief Specialized version of `CreateVector` for non-copying use cases. - /// Write the data any time later to the returned buffer pointer `buf`. - /// @param[in] len The number of elements to store in the `vector`. - /// @param[in] elemsize The size of each element in the `vector`. - /// @param[out] buf A pointer to a `uint8_t` pointer that can be - /// written to at a later time to serialize the data into a `vector` - /// in the buffer. - uoffset_t CreateUninitializedVector(size_t len, size_t elemsize, - uint8_t **buf) { - NotNested(); - StartVector(len, elemsize); - buf_.make_space(len * elemsize); - auto vec_start = GetSize(); - auto vec_end = EndVector(len); - *buf = buf_.data_at(vec_start); - return vec_end; - } - - /// @brief Specialized version of `CreateVector` for non-copying use cases. - /// Write the data any time later to the returned buffer pointer `buf`. - /// @tparam T The data type of the data that will be stored in the buffer - /// as a `vector`. - /// @param[in] len The number of elements to store in the `vector`. - /// @param[out] buf A pointer to a pointer of type `T` that can be - /// written to at a later time to serialize the data into a `vector` - /// in the buffer. - template - Offset> CreateUninitializedVector(size_t len, T **buf) { - AssertScalarT(); - return CreateUninitializedVector(len, sizeof(T), - reinterpret_cast(buf)); - } - - template - Offset> CreateUninitializedVectorOfStructs(size_t len, T **buf) { - return CreateUninitializedVector(len, sizeof(T), - reinterpret_cast(buf)); - } - - - // @brief Create a vector of scalar type T given as input a vector of scalar - // type U, useful with e.g. pre "enum class" enums, or any existing scalar - // data of the wrong type. - template - Offset> CreateVectorScalarCast(const U *v, size_t len) { - AssertScalarT(); - AssertScalarT(); - StartVector(len, sizeof(T)); - for (auto i = len; i > 0;) { PushElement(static_cast(v[--i])); } - return Offset>(EndVector(len)); - } - - /// @brief Write a struct by itself, typically to be part of a union. - template Offset CreateStruct(const T &structobj) { - NotNested(); - Align(AlignOf()); - buf_.push_small(structobj); - return Offset(GetSize()); - } - - /// @brief The length of a FlatBuffer file header. - static const size_t kFileIdentifierLength = 4; - - /// @brief Finish serializing a buffer by writing the root offset. - /// @param[in] file_identifier If a `file_identifier` is given, the buffer - /// will be prefixed with a standard FlatBuffers file header. - template - void Finish(Offset root, const char *file_identifier = nullptr) { - Finish(root.o, file_identifier, false); - } - - /// @brief Finish a buffer with a 32 bit size field pre-fixed (size of the - /// buffer following the size field). These buffers are NOT compatible - /// with standard buffers created by Finish, i.e. you can't call GetRoot - /// on them, you have to use GetSizePrefixedRoot instead. - /// All >32 bit quantities in this buffer will be aligned when the whole - /// size pre-fixed buffer is aligned. - /// These kinds of buffers are useful for creating a stream of FlatBuffers. - template - void FinishSizePrefixed(Offset root, - const char *file_identifier = nullptr) { - Finish(root.o, file_identifier, true); - } - - void SwapBufAllocator(FlatBufferBuilder &other) { - buf_.swap_allocator(other.buf_); - } - -protected: - - // You shouldn't really be copying instances of this class. - FlatBufferBuilder(const FlatBufferBuilder &); - FlatBufferBuilder &operator=(const FlatBufferBuilder &); - - void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) { - NotNested(); - buf_.clear_scratch(); - // This will cause the whole buffer to be aligned. - PreAlign((size_prefix ? sizeof(uoffset_t) : 0) + sizeof(uoffset_t) + - (file_identifier ? kFileIdentifierLength : 0), - minalign_); - if (file_identifier) { - FLATBUFFERS_ASSERT(strlen(file_identifier) == kFileIdentifierLength); - PushBytes(reinterpret_cast(file_identifier), - kFileIdentifierLength); - } - PushElement(ReferTo(root)); // Location of root. - if (size_prefix) { PushElement(GetSize()); } - finished = true; - } - - struct FieldLoc { - uoffset_t off; - voffset_t id; - }; - - vector_downward buf_; - - // Accumulating offsets of table members while it is being built. - // We store these in the scratch pad of buf_, after the vtable offsets. - uoffset_t num_field_loc; - // Track how much of the vtable is in use, so we can output the most compact - // possible vtable. - voffset_t max_voffset_; - - // Ensure objects are not nested. - bool nested; - - // Ensure the buffer is finished before it is being accessed. - bool finished; - - size_t minalign_; - - bool force_defaults_; // Serialize values equal to their defaults anyway. - - bool dedup_vtables_; - - struct StringOffsetCompare { - StringOffsetCompare(const vector_downward &buf) : buf_(&buf) {} - bool operator()(const Offset &a, const Offset &b) const { - auto stra = reinterpret_cast(buf_->data_at(a.o)); - auto strb = reinterpret_cast(buf_->data_at(b.o)); - return StringLessThan(stra->data(), stra->size(), - strb->data(), strb->size()); - } - const vector_downward *buf_; - }; - - // For use with CreateSharedString. Instantiated on first use only. - typedef std::set, StringOffsetCompare> StringOffsetMap; - StringOffsetMap *string_pool; - - private: - // Allocates space for a vector of structures. - // Must be completed with EndVectorOfStructs(). - template T *StartVectorOfStructs(size_t vector_size) { - StartVector(vector_size * sizeof(T) / AlignOf(), AlignOf()); - return reinterpret_cast(buf_.make_space(vector_size * sizeof(T))); - } - - // End the vector of structues in the flatbuffers. - // Vector should have previously be started with StartVectorOfStructs(). - template - Offset> EndVectorOfStructs(size_t vector_size) { - return Offset>(EndVector(vector_size)); - } -}; -/// @} - -/// @cond FLATBUFFERS_INTERNAL -// Helpers to get a typed pointer to the root object contained in the buffer. -template T *GetMutableRoot(void *buf) { - EndianCheck(); - return reinterpret_cast( - reinterpret_cast(buf) + - EndianScalar(*reinterpret_cast(buf))); -} - -template const T *GetRoot(const void *buf) { - return GetMutableRoot(const_cast(buf)); -} - -template const T *GetSizePrefixedRoot(const void *buf) { - return GetRoot(reinterpret_cast(buf) + sizeof(uoffset_t)); -} - -/// Helpers to get a typed pointer to objects that are currently being built. -/// @warning Creating new objects will lead to reallocations and invalidates -/// the pointer! -template -T *GetMutableTemporaryPointer(FlatBufferBuilder &fbb, Offset offset) { - return reinterpret_cast(fbb.GetCurrentBufferPointer() + fbb.GetSize() - - offset.o); -} - -template -const T *GetTemporaryPointer(FlatBufferBuilder &fbb, Offset offset) { - return GetMutableTemporaryPointer(fbb, offset); -} - -/// @brief Get a pointer to the the file_identifier section of the buffer. -/// @return Returns a const char pointer to the start of the file_identifier -/// characters in the buffer. The returned char * has length -/// 'flatbuffers::FlatBufferBuilder::kFileIdentifierLength'. -/// This function is UNDEFINED for FlatBuffers whose schema does not include -/// a file_identifier (likely points at padding or the start of a the root -/// vtable). -inline const char *GetBufferIdentifier(const void *buf, bool size_prefixed = false) { - return reinterpret_cast(buf) + - ((size_prefixed) ? 2 * sizeof(uoffset_t) : sizeof(uoffset_t)); -} - -// Helper to see if the identifier in a buffer has the expected value. -inline bool BufferHasIdentifier(const void *buf, const char *identifier, bool size_prefixed = false) { - return strncmp(GetBufferIdentifier(buf, size_prefixed), identifier, - FlatBufferBuilder::kFileIdentifierLength) == 0; -} - -// Helper class to verify the integrity of a FlatBuffer -class Verifier FLATBUFFERS_FINAL_CLASS { - public: - Verifier(const uint8_t *buf, size_t buf_len, uoffset_t _max_depth = 64, - uoffset_t _max_tables = 1000000, bool _check_alignment = true) - : buf_(buf), - size_(buf_len), - depth_(0), - max_depth_(_max_depth), - num_tables_(0), - max_tables_(_max_tables) - // clang-format off - #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - , upper_bound_(0) - #endif - , check_alignment_(_check_alignment) - // clang-format on - { - FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE); - } - - // Central location where any verification failures register. - bool Check(bool ok) const { - // clang-format off - #ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE - FLATBUFFERS_ASSERT(ok); - #endif - #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - if (!ok) - upper_bound_ = 0; - #endif - // clang-format on - return ok; - } - - // Verify any range within the buffer. - bool Verify(size_t elem, size_t elem_len) const { - // clang-format off - #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - auto upper_bound = elem + elem_len; - if (upper_bound_ < upper_bound) - upper_bound_ = upper_bound; - #endif - // clang-format on - return Check(elem_len < size_ && elem <= size_ - elem_len); - } - - template bool VerifyAlignment(size_t elem) const { - return (elem & (sizeof(T) - 1)) == 0 || !check_alignment_; - } - - // Verify a range indicated by sizeof(T). - template bool Verify(size_t elem) const { - return VerifyAlignment(elem) && Verify(elem, sizeof(T)); - } - - // Verify relative to a known-good base pointer. - bool Verify(const uint8_t *base, voffset_t elem_off, size_t elem_len) const { - return Verify(static_cast(base - buf_) + elem_off, elem_len); - } - - template bool Verify(const uint8_t *base, voffset_t elem_off) - const { - return Verify(static_cast(base - buf_) + elem_off, sizeof(T)); - } - - // Verify a pointer (may be NULL) of a table type. - template bool VerifyTable(const T *table) { - return !table || table->Verify(*this); - } - - // Verify a pointer (may be NULL) of any vector type. - template bool VerifyVector(const Vector *vec) const { - return !vec || VerifyVectorOrString(reinterpret_cast(vec), - sizeof(T)); - } - - // Verify a pointer (may be NULL) of a vector to struct. - template bool VerifyVector(const Vector *vec) const { - return VerifyVector(reinterpret_cast *>(vec)); - } - - // Verify a pointer (may be NULL) to string. - bool VerifyString(const String *str) const { - size_t end; - return !str || - (VerifyVectorOrString(reinterpret_cast(str), - 1, &end) && - Verify(end, 1) && // Must have terminator - Check(buf_[end] == '\0')); // Terminating byte must be 0. - } - - // Common code between vectors and strings. - bool VerifyVectorOrString(const uint8_t *vec, size_t elem_size, - size_t *end = nullptr) const { - auto veco = static_cast(vec - buf_); - // Check we can read the size field. - if (!Verify(veco)) return false; - // Check the whole array. If this is a string, the byte past the array - // must be 0. - auto size = ReadScalar(vec); - auto max_elems = FLATBUFFERS_MAX_BUFFER_SIZE / elem_size; - if (!Check(size < max_elems)) - return false; // Protect against byte_size overflowing. - auto byte_size = sizeof(size) + elem_size * size; - if (end) *end = veco + byte_size; - return Verify(veco, byte_size); - } - - // Special case for string contents, after the above has been called. - bool VerifyVectorOfStrings(const Vector> *vec) const { - if (vec) { - for (uoffset_t i = 0; i < vec->size(); i++) { - if (!VerifyString(vec->Get(i))) return false; - } - } - return true; - } - - // Special case for table contents, after the above has been called. - template bool VerifyVectorOfTables(const Vector> *vec) { - if (vec) { - for (uoffset_t i = 0; i < vec->size(); i++) { - if (!vec->Get(i)->Verify(*this)) return false; - } - } - return true; - } - - bool VerifyTableStart(const uint8_t *table) { - // Check the vtable offset. - auto tableo = static_cast(table - buf_); - if (!Verify(tableo)) return false; - // This offset may be signed, but doing the substraction unsigned always - // gives the result we want. - auto vtableo = tableo - static_cast(ReadScalar(table)); - // Check the vtable size field, then check vtable fits in its entirety. - return VerifyComplexity() && Verify(vtableo) && - VerifyAlignment(ReadScalar(buf_ + vtableo)) && - Verify(vtableo, ReadScalar(buf_ + vtableo)); - } - - template - bool VerifyBufferFromStart(const char *identifier, size_t start) { - if (identifier && - (size_ < 2 * sizeof(flatbuffers::uoffset_t) || - !BufferHasIdentifier(buf_ + start, identifier))) { - return false; - } - - // Call T::Verify, which must be in the generated code for this type. - auto o = VerifyOffset(start); - return o && reinterpret_cast(buf_ + start + o)->Verify(*this) - // clang-format off - #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - && GetComputedSize() - #endif - ; - // clang-format on - } - - // Verify this whole buffer, starting with root type T. - template bool VerifyBuffer() { return VerifyBuffer(nullptr); } - - template bool VerifyBuffer(const char *identifier) { - return VerifyBufferFromStart(identifier, 0); - } - - template bool VerifySizePrefixedBuffer(const char *identifier) { - return Verify(0U) && - ReadScalar(buf_) == size_ - sizeof(uoffset_t) && - VerifyBufferFromStart(identifier, sizeof(uoffset_t)); - } - - uoffset_t VerifyOffset(size_t start) const { - if (!Verify(start)) return 0; - auto o = ReadScalar(buf_ + start); - // May not point to itself. - if (!Check(o != 0)) return 0; - // Can't wrap around / buffers are max 2GB. - if (!Check(static_cast(o) >= 0)) return 0; - // Must be inside the buffer to create a pointer from it (pointer outside - // buffer is UB). - if (!Verify(start + o, 1)) return 0; - return o; - } - - uoffset_t VerifyOffset(const uint8_t *base, voffset_t start) const { - return VerifyOffset(static_cast(base - buf_) + start); - } - - // Called at the start of a table to increase counters measuring data - // structure depth and amount, and possibly bails out with false if - // limits set by the constructor have been hit. Needs to be balanced - // with EndTable(). - bool VerifyComplexity() { - depth_++; - num_tables_++; - return Check(depth_ <= max_depth_ && num_tables_ <= max_tables_); - } - - // Called at the end of a table to pop the depth count. - bool EndTable() { - depth_--; - return true; - } - - // clang-format off - #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - // Returns the message size in bytes - size_t GetComputedSize() const { - uintptr_t size = upper_bound_; - // Align the size to uoffset_t - size = (size - 1 + sizeof(uoffset_t)) & ~(sizeof(uoffset_t) - 1); - return (size > size_) ? 0 : size; - } - #endif - // clang-format on - - private: - const uint8_t *buf_; - size_t size_; - uoffset_t depth_; - uoffset_t max_depth_; - uoffset_t num_tables_; - uoffset_t max_tables_; - // clang-format off - #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - mutable size_t upper_bound_; - #endif - // clang-format on - bool check_alignment_; -}; - -// Convenient way to bundle a buffer and its length, to pass it around -// typed by its root. -// A BufferRef does not own its buffer. -struct BufferRefBase {}; // for std::is_base_of -template struct BufferRef : BufferRefBase { - BufferRef() : buf(nullptr), len(0), must_free(false) {} - BufferRef(uint8_t *_buf, uoffset_t _len) - : buf(_buf), len(_len), must_free(false) {} - - ~BufferRef() { - if (must_free) free(buf); - } - - const T *GetRoot() const { return flatbuffers::GetRoot(buf); } - - bool Verify() { - Verifier verifier(buf, len); - return verifier.VerifyBuffer(nullptr); - } - - uint8_t *buf; - uoffset_t len; - bool must_free; -}; - -// "structs" are flat structures that do not have an offset table, thus -// always have all members present and do not support forwards/backwards -// compatible extensions. - -class Struct FLATBUFFERS_FINAL_CLASS { - public: - template T GetField(uoffset_t o) const { - return ReadScalar(&data_[o]); - } - - template T GetStruct(uoffset_t o) const { - return reinterpret_cast(&data_[o]); - } - - const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; } - uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; } - - private: - uint8_t data_[1]; -}; - -// "tables" use an offset table (possibly shared) that allows fields to be -// omitted and added at will, but uses an extra indirection to read. -class Table { - public: - const uint8_t *GetVTable() const { - return data_ - ReadScalar(data_); - } - - // This gets the field offset for any of the functions below it, or 0 - // if the field was not present. - voffset_t GetOptionalFieldOffset(voffset_t field) const { - // The vtable offset is always at the start. - auto vtable = GetVTable(); - // The first element is the size of the vtable (fields + type id + itself). - auto vtsize = ReadScalar(vtable); - // If the field we're accessing is outside the vtable, we're reading older - // data, so it's the same as if the offset was 0 (not present). - return field < vtsize ? ReadScalar(vtable + field) : 0; - } - - template T GetField(voffset_t field, T defaultval) const { - auto field_offset = GetOptionalFieldOffset(field); - return field_offset ? ReadScalar(data_ + field_offset) : defaultval; - } - - template P GetPointer(voffset_t field) { - auto field_offset = GetOptionalFieldOffset(field); - auto p = data_ + field_offset; - return field_offset ? reinterpret_cast

(p + ReadScalar(p)) - : nullptr; - } - template P GetPointer(voffset_t field) const { - return const_cast(this)->GetPointer

(field); - } - - template P GetStruct(voffset_t field) const { - auto field_offset = GetOptionalFieldOffset(field); - auto p = const_cast(data_ + field_offset); - return field_offset ? reinterpret_cast

(p) : nullptr; - } - - template bool SetField(voffset_t field, T val, T def) { - auto field_offset = GetOptionalFieldOffset(field); - if (!field_offset) return IsTheSameAs(val, def); - WriteScalar(data_ + field_offset, val); - return true; - } - - bool SetPointer(voffset_t field, const uint8_t *val) { - auto field_offset = GetOptionalFieldOffset(field); - if (!field_offset) return false; - WriteScalar(data_ + field_offset, - static_cast(val - (data_ + field_offset))); - return true; - } - - uint8_t *GetAddressOf(voffset_t field) { - auto field_offset = GetOptionalFieldOffset(field); - return field_offset ? data_ + field_offset : nullptr; - } - const uint8_t *GetAddressOf(voffset_t field) const { - return const_cast

(this)->GetAddressOf(field); - } - - bool CheckField(voffset_t field) const { - return GetOptionalFieldOffset(field) != 0; - } - - // Verify the vtable of this table. - // Call this once per table, followed by VerifyField once per field. - bool VerifyTableStart(Verifier &verifier) const { - return verifier.VerifyTableStart(data_); - } - - // Verify a particular field. - template - bool VerifyField(const Verifier &verifier, voffset_t field) const { - // Calling GetOptionalFieldOffset should be safe now thanks to - // VerifyTable(). - auto field_offset = GetOptionalFieldOffset(field); - // Check the actual field. - return !field_offset || verifier.Verify(data_, field_offset); - } - - // VerifyField for required fields. - template - bool VerifyFieldRequired(const Verifier &verifier, voffset_t field) const { - auto field_offset = GetOptionalFieldOffset(field); - return verifier.Check(field_offset != 0) && - verifier.Verify(data_, field_offset); - } - - // Versions for offsets. - bool VerifyOffset(const Verifier &verifier, voffset_t field) const { - auto field_offset = GetOptionalFieldOffset(field); - return !field_offset || verifier.VerifyOffset(data_, field_offset); - } - - bool VerifyOffsetRequired(const Verifier &verifier, voffset_t field) const { - auto field_offset = GetOptionalFieldOffset(field); - return verifier.Check(field_offset != 0) && - verifier.VerifyOffset(data_, field_offset); - } - - private: - // private constructor & copy constructor: you obtain instances of this - // class by pointing to existing data only - Table(); - Table(const Table &other); - - uint8_t data_[1]; -}; - -template void FlatBufferBuilder::Required(Offset table, - voffset_t field) { - auto table_ptr = reinterpret_cast(buf_.data_at(table.o)); - bool ok = table_ptr->GetOptionalFieldOffset(field) != 0; - // If this fails, the caller will show what field needs to be set. - FLATBUFFERS_ASSERT(ok); - (void)ok; -} - -/// @brief This can compute the start of a FlatBuffer from a root pointer, i.e. -/// it is the opposite transformation of GetRoot(). -/// This may be useful if you want to pass on a root and have the recipient -/// delete the buffer afterwards. -inline const uint8_t *GetBufferStartFromRootPointer(const void *root) { - auto table = reinterpret_cast(root); - auto vtable = table->GetVTable(); - // Either the vtable is before the root or after the root. - auto start = (std::min)(vtable, reinterpret_cast(root)); - // Align to at least sizeof(uoffset_t). - start = reinterpret_cast(reinterpret_cast(start) & - ~(sizeof(uoffset_t) - 1)); - // Additionally, there may be a file_identifier in the buffer, and the root - // offset. The buffer may have been aligned to any size between - // sizeof(uoffset_t) and FLATBUFFERS_MAX_ALIGNMENT (see "force_align"). - // Sadly, the exact alignment is only known when constructing the buffer, - // since it depends on the presence of values with said alignment properties. - // So instead, we simply look at the next uoffset_t values (root, - // file_identifier, and alignment padding) to see which points to the root. - // None of the other values can "impersonate" the root since they will either - // be 0 or four ASCII characters. - static_assert(FlatBufferBuilder::kFileIdentifierLength == sizeof(uoffset_t), - "file_identifier is assumed to be the same size as uoffset_t"); - for (auto possible_roots = FLATBUFFERS_MAX_ALIGNMENT / sizeof(uoffset_t) + 1; - possible_roots; possible_roots--) { - start -= sizeof(uoffset_t); - if (ReadScalar(start) + start == - reinterpret_cast(root)) - return start; - } - // We didn't find the root, either the "root" passed isn't really a root, - // or the buffer is corrupt. - // Assert, because calling this function with bad data may cause reads - // outside of buffer boundaries. - FLATBUFFERS_ASSERT(false); - return nullptr; -} - -/// @brief This return the prefixed size of a FlatBuffer. -inline uoffset_t GetPrefixedSize(const uint8_t* buf){ return ReadScalar(buf); } - -// Base class for native objects (FlatBuffer data de-serialized into native -// C++ data structures). -// Contains no functionality, purely documentative. -struct NativeTable {}; - -/// @brief Function types to be used with resolving hashes into objects and -/// back again. The resolver gets a pointer to a field inside an object API -/// object that is of the type specified in the schema using the attribute -/// `cpp_type` (it is thus important whatever you write to this address -/// matches that type). The value of this field is initially null, so you -/// may choose to implement a delayed binding lookup using this function -/// if you wish. The resolver does the opposite lookup, for when the object -/// is being serialized again. -typedef uint64_t hash_value_t; -// clang-format off -#ifdef FLATBUFFERS_CPP98_STL - typedef void (*resolver_function_t)(void **pointer_adr, hash_value_t hash); - typedef hash_value_t (*rehasher_function_t)(void *pointer); -#else - typedef std::function - resolver_function_t; - typedef std::function rehasher_function_t; -#endif -// clang-format on - -// Helper function to test if a field is present, using any of the field -// enums in the generated code. -// `table` must be a generated table type. Since this is a template parameter, -// this is not typechecked to be a subclass of Table, so beware! -// Note: this function will return false for fields equal to the default -// value, since they're not stored in the buffer (unless force_defaults was -// used). -template -bool IsFieldPresent(const T *table, typename T::FlatBuffersVTableOffset field) { - // Cast, since Table is a private baseclass of any table types. - return reinterpret_cast(table)->CheckField( - static_cast(field)); -} - -// Utility function for reverse lookups on the EnumNames*() functions -// (in the generated C++ code) -// names must be NULL terminated. -inline int LookupEnum(const char **names, const char *name) { - for (const char **p = names; *p; p++) - if (!strcmp(*p, name)) return static_cast(p - names); - return -1; -} - -// These macros allow us to layout a struct with a guarantee that they'll end -// up looking the same on different compilers and platforms. -// It does this by disallowing the compiler to do any padding, and then -// does padding itself by inserting extra padding fields that make every -// element aligned to its own size. -// Additionally, it manually sets the alignment of the struct as a whole, -// which is typically its largest element, or a custom size set in the schema -// by the force_align attribute. -// These are used in the generated code only. - -// clang-format off -#if defined(_MSC_VER) - #define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \ - __pragma(pack(1)); \ - struct __declspec(align(alignment)) - #define FLATBUFFERS_STRUCT_END(name, size) \ - __pragma(pack()); \ - static_assert(sizeof(name) == size, "compiler breaks packing rules") -#elif defined(__GNUC__) || defined(__clang__) - #define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \ - _Pragma("pack(1)") \ - struct __attribute__((aligned(alignment))) - #define FLATBUFFERS_STRUCT_END(name, size) \ - _Pragma("pack()") \ - static_assert(sizeof(name) == size, "compiler breaks packing rules") -#else - #error Unknown compiler, please define structure alignment macros -#endif -// clang-format on - -// Minimal reflection via code generation. -// Besides full-fat reflection (see reflection.h) and parsing/printing by -// loading schemas (see idl.h), we can also have code generation for mimimal -// reflection data which allows pretty-printing and other uses without needing -// a schema or a parser. -// Generate code with --reflect-types (types only) or --reflect-names (names -// also) to enable. -// See minireflect.h for utilities using this functionality. - -// These types are organized slightly differently as the ones in idl.h. -enum SequenceType { ST_TABLE, ST_STRUCT, ST_UNION, ST_ENUM }; - -// Scalars have the same order as in idl.h -// clang-format off -#define FLATBUFFERS_GEN_ELEMENTARY_TYPES(ET) \ - ET(ET_UTYPE) \ - ET(ET_BOOL) \ - ET(ET_CHAR) \ - ET(ET_UCHAR) \ - ET(ET_SHORT) \ - ET(ET_USHORT) \ - ET(ET_INT) \ - ET(ET_UINT) \ - ET(ET_LONG) \ - ET(ET_ULONG) \ - ET(ET_FLOAT) \ - ET(ET_DOUBLE) \ - ET(ET_STRING) \ - ET(ET_SEQUENCE) // See SequenceType. - -enum ElementaryType { - #define FLATBUFFERS_ET(E) E, - FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET) - #undef FLATBUFFERS_ET -}; - -inline const char * const *ElementaryTypeNames() { - static const char * const names[] = { - #define FLATBUFFERS_ET(E) #E, - FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET) - #undef FLATBUFFERS_ET - }; - return names; -} -// clang-format on - -// Basic type info cost just 16bits per field! -struct TypeCode { - uint16_t base_type : 4; // ElementaryType - uint16_t is_vector : 1; - int16_t sequence_ref : 11; // Index into type_refs below, or -1 for none. -}; - -static_assert(sizeof(TypeCode) == 2, "TypeCode"); - -struct TypeTable; - -// Signature of the static method present in each type. -typedef const TypeTable *(*TypeFunction)(); - -struct TypeTable { - SequenceType st; - size_t num_elems; // of type_codes, values, names (but not type_refs). - const TypeCode *type_codes; // num_elems count - const TypeFunction *type_refs; // less than num_elems entries (see TypeCode). - const int64_t *values; // Only set for non-consecutive enum/union or structs. - const char * const *names; // Only set if compiled with --reflect-names. -}; - -// String which identifies the current version of FlatBuffers. -// flatbuffer_version_string is used by Google developers to identify which -// applications uploaded to Google Play are using this library. This allows -// the development team at Google to determine the popularity of the library. -// How it works: Applications that are uploaded to the Google Play Store are -// scanned for this version string. We track which applications are using it -// to measure popularity. You are free to remove it (of course) but we would -// appreciate if you left it in. - -// Weak linkage is culled by VS & doesn't work on cygwin. -// clang-format off -#if !defined(_WIN32) && !defined(__CYGWIN__) - -extern volatile __attribute__((weak)) const char *flatbuffer_version_string; -volatile __attribute__((weak)) const char *flatbuffer_version_string = - "FlatBuffers " - FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "." - FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "." - FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION); - -#endif // !defined(_WIN32) && !defined(__CYGWIN__) - -#define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\ - inline E operator | (E lhs, E rhs){\ - return E(T(lhs) | T(rhs));\ - }\ - inline E operator & (E lhs, E rhs){\ - return E(T(lhs) & T(rhs));\ - }\ - inline E operator ^ (E lhs, E rhs){\ - return E(T(lhs) ^ T(rhs));\ - }\ - inline E operator ~ (E lhs){\ - return E(~T(lhs));\ - }\ - inline E operator |= (E &lhs, E rhs){\ - lhs = lhs | rhs;\ - return lhs;\ - }\ - inline E operator &= (E &lhs, E rhs){\ - lhs = lhs & rhs;\ - return lhs;\ - }\ - inline E operator ^= (E &lhs, E rhs){\ - lhs = lhs ^ rhs;\ - return lhs;\ - }\ - inline bool operator !(E rhs) \ - {\ - return !bool(T(rhs)); \ - } -/// @endcond -} // namespace flatbuffers - -// clang-format on - -#endif // FLATBUFFERS_H_ diff --git a/src/internal/include/flatbuffers/flatc.h b/src/internal/include/flatbuffers/flatc.h deleted file mode 100644 index f2765d2..0000000 --- a/src/internal/include/flatbuffers/flatc.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2017 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. - */ - -#include -#include -#include -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" -#include "flatbuffers/util.h" - -#ifndef FLATC_H_ -# define FLATC_H_ - -namespace flatbuffers { - -class FlatCompiler { - public: - // Output generator for the various programming languages and formats we - // support. - struct Generator { - typedef bool (*GenerateFn)(const flatbuffers::Parser &parser, - const std::string &path, - const std::string &file_name); - typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser, - const std::string &path, - const std::string &file_name); - - GenerateFn generate; - const char *generator_opt_short; - const char *generator_opt_long; - const char *lang_name; - bool schema_only; - GenerateFn generateGRPC; - flatbuffers::IDLOptions::Language lang; - const char *generator_help; - MakeRuleFn make_rule; - }; - - typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn, - bool show_exe_name); - - typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err, - bool usage, bool show_exe_name); - - // Parameters required to initialize the FlatCompiler. - struct InitParams { - InitParams() - : generators(nullptr), - num_generators(0), - warn_fn(nullptr), - error_fn(nullptr) {} - - const Generator *generators; - size_t num_generators; - WarnFn warn_fn; - ErrorFn error_fn; - }; - - explicit FlatCompiler(const InitParams ¶ms) : params_(params) {} - - int Compile(int argc, const char **argv); - - std::string GetUsageString(const char *program_name) const; - - private: - void ParseFile(flatbuffers::Parser &parser, const std::string &filename, - const std::string &contents, - std::vector &include_directories) const; - - void LoadBinarySchema(Parser &parser, const std::string &filename, - const std::string &contents); - - void Warn(const std::string &warn, bool show_exe_name = true) const; - - void Error(const std::string &err, bool usage = true, - bool show_exe_name = true) const; - - InitParams params_; -}; - -} // namespace flatbuffers - -#endif // FLATC_H_ diff --git a/src/internal/include/flatbuffers/flexbuffers.h b/src/internal/include/flatbuffers/flexbuffers.h deleted file mode 100644 index 7cba5b7..0000000 --- a/src/internal/include/flatbuffers/flexbuffers.h +++ /dev/null @@ -1,1538 +0,0 @@ -/* - * Copyright 2017 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. - */ - -#ifndef FLATBUFFERS_FLEXBUFFERS_H_ -#define FLATBUFFERS_FLEXBUFFERS_H_ - -#include -// Used to select STL variant. -#include "flatbuffers/base.h" -// We use the basic binary writing functions from the regular FlatBuffers. -#include "flatbuffers/util.h" - -#ifdef _MSC_VER -# include -#endif - -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4127) // C4127: conditional expression is constant -#endif - -namespace flexbuffers { - -class Reference; -class Map; - -// These are used in the lower 2 bits of a type field to determine the size of -// the elements (and or size field) of the item pointed to (e.g. vector). -enum BitWidth { - BIT_WIDTH_8 = 0, - BIT_WIDTH_16 = 1, - BIT_WIDTH_32 = 2, - BIT_WIDTH_64 = 3, -}; - -// These are used as the upper 6 bits of a type field to indicate the actual -// type. -enum Type { - FBT_NULL = 0, - FBT_INT = 1, - FBT_UINT = 2, - FBT_FLOAT = 3, - // Types above stored inline, types below store an offset. - FBT_KEY = 4, - FBT_STRING = 5, - FBT_INDIRECT_INT = 6, - FBT_INDIRECT_UINT = 7, - FBT_INDIRECT_FLOAT = 8, - FBT_MAP = 9, - FBT_VECTOR = 10, // Untyped. - FBT_VECTOR_INT = 11, // Typed any size (stores no type table). - FBT_VECTOR_UINT = 12, - FBT_VECTOR_FLOAT = 13, - FBT_VECTOR_KEY = 14, - FBT_VECTOR_STRING = 15, - FBT_VECTOR_INT2 = 16, // Typed tuple (no type table, no size field). - FBT_VECTOR_UINT2 = 17, - FBT_VECTOR_FLOAT2 = 18, - FBT_VECTOR_INT3 = 19, // Typed triple (no type table, no size field). - FBT_VECTOR_UINT3 = 20, - FBT_VECTOR_FLOAT3 = 21, - FBT_VECTOR_INT4 = 22, // Typed quad (no type table, no size field). - FBT_VECTOR_UINT4 = 23, - FBT_VECTOR_FLOAT4 = 24, - FBT_BLOB = 25, - FBT_BOOL = 26, - FBT_VECTOR_BOOL = - 36, // To Allow the same type of conversion of type to vector type -}; - -inline bool IsInline(Type t) { return t <= FBT_FLOAT || t == FBT_BOOL; } - -inline bool IsTypedVectorElementType(Type t) { - return (t >= FBT_INT && t <= FBT_STRING) || t == FBT_BOOL; -} - -inline bool IsTypedVector(Type t) { - return (t >= FBT_VECTOR_INT && t <= FBT_VECTOR_STRING) || - t == FBT_VECTOR_BOOL; -} - -inline bool IsFixedTypedVector(Type t) { - return t >= FBT_VECTOR_INT2 && t <= FBT_VECTOR_FLOAT4; -} - -inline Type ToTypedVector(Type t, size_t fixed_len = 0) { - FLATBUFFERS_ASSERT(IsTypedVectorElementType(t)); - switch (fixed_len) { - case 0: return static_cast(t - FBT_INT + FBT_VECTOR_INT); - case 2: return static_cast(t - FBT_INT + FBT_VECTOR_INT2); - case 3: return static_cast(t - FBT_INT + FBT_VECTOR_INT3); - case 4: return static_cast(t - FBT_INT + FBT_VECTOR_INT4); - default: FLATBUFFERS_ASSERT(0); return FBT_NULL; - } -} - -inline Type ToTypedVectorElementType(Type t) { - FLATBUFFERS_ASSERT(IsTypedVector(t)); - return static_cast(t - FBT_VECTOR_INT + FBT_INT); -} - -inline Type ToFixedTypedVectorElementType(Type t, uint8_t *len) { - FLATBUFFERS_ASSERT(IsFixedTypedVector(t)); - auto fixed_type = t - FBT_VECTOR_INT2; - *len = static_cast(fixed_type / 3 + - 2); // 3 types each, starting from length 2. - return static_cast(fixed_type % 3 + FBT_INT); -} - -// TODO: implement proper support for 8/16bit floats, or decide not to -// support them. -typedef int16_t half; -typedef int8_t quarter; - -// TODO: can we do this without conditionals using intrinsics or inline asm -// on some platforms? Given branch prediction the method below should be -// decently quick, but it is the most frequently executed function. -// We could do an (unaligned) 64-bit read if we ifdef out the platforms for -// which that doesn't work (or where we'd read into un-owned memory). -template -R ReadSizedScalar(const uint8_t *data, uint8_t byte_width) { - return byte_width < 4 - ? (byte_width < 2 - ? static_cast(flatbuffers::ReadScalar(data)) - : static_cast(flatbuffers::ReadScalar(data))) - : (byte_width < 8 - ? static_cast(flatbuffers::ReadScalar(data)) - : static_cast(flatbuffers::ReadScalar(data))); -} - -inline int64_t ReadInt64(const uint8_t *data, uint8_t byte_width) { - return ReadSizedScalar( - data, byte_width); -} - -inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) { - // This is the "hottest" function (all offset lookups use this), so worth - // optimizing if possible. - // TODO: GCC apparently replaces memcpy by a rep movsb, but only if count is a - // constant, which here it isn't. Test if memcpy is still faster than - // the conditionals in ReadSizedScalar. Can also use inline asm. - // clang-format off - #if defined(_MSC_VER) && (defined(_M_X64) || defined _M_IX86) - uint64_t u = 0; - __movsb(reinterpret_cast(&u), - reinterpret_cast(data), byte_width); - return flatbuffers::EndianScalar(u); - #else - return ReadSizedScalar( - data, byte_width); - #endif - // clang-format on -} - -inline double ReadDouble(const uint8_t *data, uint8_t byte_width) { - return ReadSizedScalar(data, - byte_width); -} - -inline const uint8_t *Indirect(const uint8_t *offset, uint8_t byte_width) { - return offset - ReadUInt64(offset, byte_width); -} - -template const uint8_t *Indirect(const uint8_t *offset) { - return offset - flatbuffers::ReadScalar(offset); -} - -inline BitWidth WidthU(uint64_t u) { -#define FLATBUFFERS_GET_FIELD_BIT_WIDTH(value, width) \ - { \ - if (!((u) & ~((1ULL << (width)) - 1ULL))) return BIT_WIDTH_##width; \ - } - FLATBUFFERS_GET_FIELD_BIT_WIDTH(u, 8); - FLATBUFFERS_GET_FIELD_BIT_WIDTH(u, 16); - FLATBUFFERS_GET_FIELD_BIT_WIDTH(u, 32); -#undef FLATBUFFERS_GET_FIELD_BIT_WIDTH - return BIT_WIDTH_64; -} - -inline BitWidth WidthI(int64_t i) { - auto u = static_cast(i) << 1; - return WidthU(i >= 0 ? u : ~u); -} - -inline BitWidth WidthF(double f) { - return static_cast(static_cast(f)) == f ? BIT_WIDTH_32 - : BIT_WIDTH_64; -} - -// Base class of all types below. -// Points into the data buffer and allows access to one type. -class Object { - public: - Object(const uint8_t *data, uint8_t byte_width) - : data_(data), byte_width_(byte_width) {} - - protected: - const uint8_t *data_; - uint8_t byte_width_; -}; - -// Stores size in `byte_width_` bytes before data_ pointer. -class Sized : public Object { - public: - Sized(const uint8_t *data, uint8_t byte_width) : Object(data, byte_width) {} - size_t size() const { - return static_cast(ReadUInt64(data_ - byte_width_, byte_width_)); - } -}; - -class String : public Sized { - public: - String(const uint8_t *data, uint8_t byte_width) : Sized(data, byte_width) {} - - size_t length() const { return size(); } - const char *c_str() const { return reinterpret_cast(data_); } - std::string str() const { return std::string(c_str(), length()); } - - static String EmptyString() { - static const uint8_t empty_string[] = { 0 /*len*/, 0 /*terminator*/ }; - return String(empty_string + 1, 1); - } - bool IsTheEmptyString() const { return data_ == EmptyString().data_; } -}; - -class Blob : public Sized { - public: - Blob(const uint8_t *data_buf, uint8_t byte_width) - : Sized(data_buf, byte_width) {} - - static Blob EmptyBlob() { - static const uint8_t empty_blob[] = { 0 /*len*/ }; - return Blob(empty_blob + 1, 1); - } - bool IsTheEmptyBlob() const { return data_ == EmptyBlob().data_; } - const uint8_t *data() const { return data_; } -}; - -class Vector : public Sized { - public: - Vector(const uint8_t *data, uint8_t byte_width) : Sized(data, byte_width) {} - - Reference operator[](size_t i) const; - - static Vector EmptyVector() { - static const uint8_t empty_vector[] = { 0 /*len*/ }; - return Vector(empty_vector + 1, 1); - } - bool IsTheEmptyVector() const { return data_ == EmptyVector().data_; } -}; - -class TypedVector : public Sized { - public: - TypedVector(const uint8_t *data, uint8_t byte_width, Type element_type) - : Sized(data, byte_width), type_(element_type) {} - - Reference operator[](size_t i) const; - - static TypedVector EmptyTypedVector() { - static const uint8_t empty_typed_vector[] = { 0 /*len*/ }; - return TypedVector(empty_typed_vector + 1, 1, FBT_INT); - } - bool IsTheEmptyVector() const { - return data_ == TypedVector::EmptyTypedVector().data_; - } - - Type ElementType() { return type_; } - - private: - Type type_; - - friend Map; -}; - -class FixedTypedVector : public Object { - public: - FixedTypedVector(const uint8_t *data, uint8_t byte_width, Type element_type, - uint8_t len) - : Object(data, byte_width), type_(element_type), len_(len) {} - - Reference operator[](size_t i) const; - - static FixedTypedVector EmptyFixedTypedVector() { - static const uint8_t fixed_empty_vector[] = { 0 /* unused */ }; - return FixedTypedVector(fixed_empty_vector, 1, FBT_INT, 0); - } - bool IsTheEmptyFixedTypedVector() const { - return data_ == FixedTypedVector::EmptyFixedTypedVector().data_; - } - - Type ElementType() { return type_; } - uint8_t size() { return len_; } - - private: - Type type_; - uint8_t len_; -}; - -class Map : public Vector { - public: - Map(const uint8_t *data, uint8_t byte_width) : Vector(data, byte_width) {} - - Reference operator[](const char *key) const; - Reference operator[](const std::string &key) const; - - Vector Values() const { return Vector(data_, byte_width_); } - - TypedVector Keys() const { - const size_t num_prefixed_fields = 3; - auto keys_offset = data_ - byte_width_ * num_prefixed_fields; - return TypedVector(Indirect(keys_offset, byte_width_), - static_cast( - ReadUInt64(keys_offset + byte_width_, byte_width_)), - FBT_KEY); - } - - static Map EmptyMap() { - static const uint8_t empty_map[] = { - 0 /*keys_len*/, 0 /*keys_offset*/, 1 /*keys_width*/, 0 /*len*/ - }; - return Map(empty_map + 4, 1); - } - - bool IsTheEmptyMap() const { return data_ == EmptyMap().data_; } -}; - -template -void AppendToString(std::string &s, T &&v, bool keys_quoted) { - s += "[ "; - for (size_t i = 0; i < v.size(); i++) { - if (i) s += ", "; - v[i].ToString(true, keys_quoted, s); - } - s += " ]"; -} - -class Reference { - public: - Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width, - Type type) - : data_(data), - parent_width_(parent_width), - byte_width_(byte_width), - type_(type) {} - - Reference(const uint8_t *data, uint8_t parent_width, uint8_t packed_type) - : data_(data), parent_width_(parent_width) { - byte_width_ = 1U << static_cast(packed_type & 3); - type_ = static_cast(packed_type >> 2); - } - - Type GetType() const { return type_; } - - bool IsNull() const { return type_ == FBT_NULL; } - bool IsBool() const { return type_ == FBT_BOOL; } - bool IsInt() const { return type_ == FBT_INT || type_ == FBT_INDIRECT_INT; } - bool IsUInt() const { - return type_ == FBT_UINT || type_ == FBT_INDIRECT_UINT; - } - bool IsIntOrUint() const { return IsInt() || IsUInt(); } - bool IsFloat() const { - return type_ == FBT_FLOAT || type_ == FBT_INDIRECT_FLOAT; - } - bool IsNumeric() const { return IsIntOrUint() || IsFloat(); } - bool IsString() const { return type_ == FBT_STRING; } - bool IsKey() const { return type_ == FBT_KEY; } - bool IsVector() const { return type_ == FBT_VECTOR || type_ == FBT_MAP; } - bool IsTypedVector() const { return flexbuffers::IsTypedVector(type_); } - bool IsFixedTypedVector() const { return flexbuffers::IsFixedTypedVector(type_); } - bool IsAnyVector() const { return (IsTypedVector() || IsFixedTypedVector() || IsVector());} - bool IsMap() const { return type_ == FBT_MAP; } - bool IsBlob() const { return type_ == FBT_BLOB; } - - bool AsBool() const { - return (type_ == FBT_BOOL ? ReadUInt64(data_, parent_width_) - : AsUInt64()) != 0; - } - - // Reads any type as a int64_t. Never fails, does most sensible conversion. - // Truncates floats, strings are attempted to be parsed for a number, - // vectors/maps return their size. Returns 0 if all else fails. - int64_t AsInt64() const { - if (type_ == FBT_INT) { - // A fast path for the common case. - return ReadInt64(data_, parent_width_); - } else - switch (type_) { - case FBT_INDIRECT_INT: return ReadInt64(Indirect(), byte_width_); - case FBT_UINT: return ReadUInt64(data_, parent_width_); - case FBT_INDIRECT_UINT: return ReadUInt64(Indirect(), byte_width_); - case FBT_FLOAT: - return static_cast(ReadDouble(data_, parent_width_)); - case FBT_INDIRECT_FLOAT: - return static_cast(ReadDouble(Indirect(), byte_width_)); - case FBT_NULL: return 0; - case FBT_STRING: return flatbuffers::StringToInt(AsString().c_str()); - case FBT_VECTOR: return static_cast(AsVector().size()); - case FBT_BOOL: return ReadInt64(data_, parent_width_); - default: - // Convert other things to int. - return 0; - } - } - - // TODO: could specialize these to not use AsInt64() if that saves - // extension ops in generated code, and use a faster op than ReadInt64. - int32_t AsInt32() const { return static_cast(AsInt64()); } - int16_t AsInt16() const { return static_cast(AsInt64()); } - int8_t AsInt8() const { return static_cast(AsInt64()); } - - uint64_t AsUInt64() const { - if (type_ == FBT_UINT) { - // A fast path for the common case. - return ReadUInt64(data_, parent_width_); - } else - switch (type_) { - case FBT_INDIRECT_UINT: return ReadUInt64(Indirect(), byte_width_); - case FBT_INT: return ReadInt64(data_, parent_width_); - case FBT_INDIRECT_INT: return ReadInt64(Indirect(), byte_width_); - case FBT_FLOAT: - return static_cast(ReadDouble(data_, parent_width_)); - case FBT_INDIRECT_FLOAT: - return static_cast(ReadDouble(Indirect(), byte_width_)); - case FBT_NULL: return 0; - case FBT_STRING: return flatbuffers::StringToUInt(AsString().c_str()); - case FBT_VECTOR: return static_cast(AsVector().size()); - case FBT_BOOL: return ReadUInt64(data_, parent_width_); - default: - // Convert other things to uint. - return 0; - } - } - - uint32_t AsUInt32() const { return static_cast(AsUInt64()); } - uint16_t AsUInt16() const { return static_cast(AsUInt64()); } - uint8_t AsUInt8() const { return static_cast(AsUInt64()); } - - double AsDouble() const { - if (type_ == FBT_FLOAT) { - // A fast path for the common case. - return ReadDouble(data_, parent_width_); - } else - switch (type_) { - case FBT_INDIRECT_FLOAT: return ReadDouble(Indirect(), byte_width_); - case FBT_INT: - return static_cast(ReadInt64(data_, parent_width_)); - case FBT_UINT: - return static_cast(ReadUInt64(data_, parent_width_)); - case FBT_INDIRECT_INT: - return static_cast(ReadInt64(Indirect(), byte_width_)); - case FBT_INDIRECT_UINT: - return static_cast(ReadUInt64(Indirect(), byte_width_)); - case FBT_NULL: return 0.0; - case FBT_STRING: return strtod(AsString().c_str(), nullptr); - case FBT_VECTOR: return static_cast(AsVector().size()); - case FBT_BOOL: - return static_cast(ReadUInt64(data_, parent_width_)); - default: - // Convert strings and other things to float. - return 0; - } - } - - float AsFloat() const { return static_cast(AsDouble()); } - - const char *AsKey() const { - if (type_ == FBT_KEY) { - return reinterpret_cast(Indirect()); - } else { - return ""; - } - } - - // This function returns the empty string if you try to read a not-string. - String AsString() const { - if (type_ == FBT_STRING) { - return String(Indirect(), byte_width_); - } else { - return String::EmptyString(); - } - } - - // Unlike AsString(), this will convert any type to a std::string. - std::string ToString() const { - std::string s; - ToString(false, false, s); - return s; - } - - // Convert any type to a JSON-like string. strings_quoted determines if - // string values at the top level receive "" quotes (inside other values - // they always do). keys_quoted determines if keys are quoted, at any level. - // TODO(wvo): add further options to have indentation/newlines. - void ToString(bool strings_quoted, bool keys_quoted, std::string &s) const { - if (type_ == FBT_STRING) { - String str(Indirect(), byte_width_); - if (strings_quoted) { - flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false); - } else { - s.append(str.c_str(), str.length()); - } - } else if (IsKey()) { - auto str = AsKey(); - if (keys_quoted) { - flatbuffers::EscapeString(str, strlen(str), &s, true, false); - } else { - s += str; - } - } else if (IsInt()) { - s += flatbuffers::NumToString(AsInt64()); - } else if (IsUInt()) { - s += flatbuffers::NumToString(AsUInt64()); - } else if (IsFloat()) { - s += flatbuffers::NumToString(AsDouble()); - } else if (IsNull()) { - s += "null"; - } else if (IsBool()) { - s += AsBool() ? "true" : "false"; - } else if (IsMap()) { - s += "{ "; - auto m = AsMap(); - auto keys = m.Keys(); - auto vals = m.Values(); - for (size_t i = 0; i < keys.size(); i++) { - keys[i].ToString(true, keys_quoted, s); - s += ": "; - vals[i].ToString(true, keys_quoted, s); - if (i < keys.size() - 1) s += ", "; - } - s += " }"; - } else if (IsVector()) { - AppendToString(s, AsVector(), keys_quoted); - } else if (IsTypedVector()) { - AppendToString(s, AsTypedVector(), keys_quoted); - } else if (IsFixedTypedVector()) { - AppendToString(s, AsFixedTypedVector(), keys_quoted); - } else if (IsBlob()) { - auto blob = AsBlob(); - flatbuffers::EscapeString(reinterpret_cast(blob.data()), blob.size(), &s, true, false); - } else { - s += "(?)"; - } - } - - // This function returns the empty blob if you try to read a not-blob. - // Strings can be viewed as blobs too. - Blob AsBlob() const { - if (type_ == FBT_BLOB || type_ == FBT_STRING) { - return Blob(Indirect(), byte_width_); - } else { - return Blob::EmptyBlob(); - } - } - - // This function returns the empty vector if you try to read a not-vector. - // Maps can be viewed as vectors too. - Vector AsVector() const { - if (type_ == FBT_VECTOR || type_ == FBT_MAP) { - return Vector(Indirect(), byte_width_); - } else { - return Vector::EmptyVector(); - } - } - - TypedVector AsTypedVector() const { - if (IsTypedVector()) { - return TypedVector(Indirect(), byte_width_, - ToTypedVectorElementType(type_)); - } else { - return TypedVector::EmptyTypedVector(); - } - } - - FixedTypedVector AsFixedTypedVector() const { - if (IsFixedTypedVector()) { - uint8_t len = 0; - auto vtype = ToFixedTypedVectorElementType(type_, &len); - return FixedTypedVector(Indirect(), byte_width_, vtype, len); - } else { - return FixedTypedVector::EmptyFixedTypedVector(); - } - } - - Map AsMap() const { - if (type_ == FBT_MAP) { - return Map(Indirect(), byte_width_); - } else { - return Map::EmptyMap(); - } - } - - template T As() const; - - // Experimental: Mutation functions. - // These allow scalars in an already created buffer to be updated in-place. - // Since by default scalars are stored in the smallest possible space, - // the new value may not fit, in which case these functions return false. - // To avoid this, you can construct the values you intend to mutate using - // Builder::ForceMinimumBitWidth. - bool MutateInt(int64_t i) { - if (type_ == FBT_INT) { - return Mutate(data_, i, parent_width_, WidthI(i)); - } else if (type_ == FBT_INDIRECT_INT) { - return Mutate(Indirect(), i, byte_width_, WidthI(i)); - } else if (type_ == FBT_UINT) { - auto u = static_cast(i); - return Mutate(data_, u, parent_width_, WidthU(u)); - } else if (type_ == FBT_INDIRECT_UINT) { - auto u = static_cast(i); - return Mutate(Indirect(), u, byte_width_, WidthU(u)); - } else { - return false; - } - } - - bool MutateBool(bool b) { - return type_ == FBT_BOOL && Mutate(data_, b, parent_width_, BIT_WIDTH_8); - } - - bool MutateUInt(uint64_t u) { - if (type_ == FBT_UINT) { - return Mutate(data_, u, parent_width_, WidthU(u)); - } else if (type_ == FBT_INDIRECT_UINT) { - return Mutate(Indirect(), u, byte_width_, WidthU(u)); - } else if (type_ == FBT_INT) { - auto i = static_cast(u); - return Mutate(data_, i, parent_width_, WidthI(i)); - } else if (type_ == FBT_INDIRECT_INT) { - auto i = static_cast(u); - return Mutate(Indirect(), i, byte_width_, WidthI(i)); - } else { - return false; - } - } - - bool MutateFloat(float f) { - if (type_ == FBT_FLOAT) { - return MutateF(data_, f, parent_width_, BIT_WIDTH_32); - } else if (type_ == FBT_INDIRECT_FLOAT) { - return MutateF(Indirect(), f, byte_width_, BIT_WIDTH_32); - } else { - return false; - } - } - - bool MutateFloat(double d) { - if (type_ == FBT_FLOAT) { - return MutateF(data_, d, parent_width_, WidthF(d)); - } else if (type_ == FBT_INDIRECT_FLOAT) { - return MutateF(Indirect(), d, byte_width_, WidthF(d)); - } else { - return false; - } - } - - bool MutateString(const char *str, size_t len) { - auto s = AsString(); - if (s.IsTheEmptyString()) return false; - // This is very strict, could allow shorter strings, but that creates - // garbage. - if (s.length() != len) return false; - memcpy(const_cast(s.c_str()), str, len); - return true; - } - bool MutateString(const char *str) { return MutateString(str, strlen(str)); } - bool MutateString(const std::string &str) { - return MutateString(str.data(), str.length()); - } - - private: - const uint8_t *Indirect() const { - return flexbuffers::Indirect(data_, parent_width_); - } - - template - bool Mutate(const uint8_t *dest, T t, size_t byte_width, - BitWidth value_width) { - auto fits = static_cast(static_cast(1U) << value_width) <= - byte_width; - if (fits) { - t = flatbuffers::EndianScalar(t); - memcpy(const_cast(dest), &t, byte_width); - } - return fits; - } - - template - bool MutateF(const uint8_t *dest, T t, size_t byte_width, - BitWidth value_width) { - if (byte_width == sizeof(double)) - return Mutate(dest, static_cast(t), byte_width, value_width); - if (byte_width == sizeof(float)) - return Mutate(dest, static_cast(t), byte_width, value_width); - FLATBUFFERS_ASSERT(false); - return false; - } - - const uint8_t *data_; - uint8_t parent_width_; - uint8_t byte_width_; - Type type_; -}; - -// Template specialization for As(). -template<> inline bool Reference::As() const { return AsBool(); } - -template<> inline int8_t Reference::As() const { return AsInt8(); } -template<> inline int16_t Reference::As() const { return AsInt16(); } -template<> inline int32_t Reference::As() const { return AsInt32(); } -template<> inline int64_t Reference::As() const { return AsInt64(); } - -template<> inline uint8_t Reference::As() const { return AsUInt8(); } -template<> inline uint16_t Reference::As() const { return AsUInt16(); } -template<> inline uint32_t Reference::As() const { return AsUInt32(); } -template<> inline uint64_t Reference::As() const { return AsUInt64(); } - -template<> inline double Reference::As() const { return AsDouble(); } -template<> inline float Reference::As() const { return AsFloat(); } - -template<> inline String Reference::As() const { return AsString(); } -template<> inline std::string Reference::As() const { - return AsString().str(); -} - -template<> inline Blob Reference::As() const { return AsBlob(); } -template<> inline Vector Reference::As() const { return AsVector(); } -template<> inline TypedVector Reference::As() const { - return AsTypedVector(); -} -template<> inline FixedTypedVector Reference::As() const { - return AsFixedTypedVector(); -} -template<> inline Map Reference::As() const { return AsMap(); } - -inline uint8_t PackedType(BitWidth bit_width, Type type) { - return static_cast(bit_width | (type << 2)); -} - -inline uint8_t NullPackedType() { return PackedType(BIT_WIDTH_8, FBT_NULL); } - -// Vector accessors. -// Note: if you try to access outside of bounds, you get a Null value back -// instead. Normally this would be an assert, but since this is "dynamically -// typed" data, you may not want that (someone sends you a 2d vector and you -// wanted 3d). -// The Null converts seamlessly into a default value for any other type. -// TODO(wvo): Could introduce an #ifdef that makes this into an assert? -inline Reference Vector::operator[](size_t i) const { - auto len = size(); - if (i >= len) return Reference(nullptr, 1, NullPackedType()); - auto packed_type = (data_ + len * byte_width_)[i]; - auto elem = data_ + i * byte_width_; - return Reference(elem, byte_width_, packed_type); -} - -inline Reference TypedVector::operator[](size_t i) const { - auto len = size(); - if (i >= len) return Reference(nullptr, 1, NullPackedType()); - auto elem = data_ + i * byte_width_; - return Reference(elem, byte_width_, 1, type_); -} - -inline Reference FixedTypedVector::operator[](size_t i) const { - if (i >= len_) return Reference(nullptr, 1, NullPackedType()); - auto elem = data_ + i * byte_width_; - return Reference(elem, byte_width_, 1, type_); -} - -template int KeyCompare(const void *key, const void *elem) { - auto str_elem = reinterpret_cast( - Indirect(reinterpret_cast(elem))); - auto skey = reinterpret_cast(key); - return strcmp(skey, str_elem); -} - -inline Reference Map::operator[](const char *key) const { - auto keys = Keys(); - // We can't pass keys.byte_width_ to the comparison function, so we have - // to pick the right one ahead of time. - int (*comp)(const void *, const void *) = nullptr; - switch (keys.byte_width_) { - case 1: comp = KeyCompare; break; - case 2: comp = KeyCompare; break; - case 4: comp = KeyCompare; break; - case 8: comp = KeyCompare; break; - } - auto res = std::bsearch(key, keys.data_, keys.size(), keys.byte_width_, comp); - if (!res) return Reference(nullptr, 1, NullPackedType()); - auto i = (reinterpret_cast(res) - keys.data_) / keys.byte_width_; - return (*static_cast(this))[i]; -} - -inline Reference Map::operator[](const std::string &key) const { - return (*this)[key.c_str()]; -} - -inline Reference GetRoot(const uint8_t *buffer, size_t size) { - // See Finish() below for the serialization counterpart of this. - // The root starts at the end of the buffer, so we parse backwards from there. - auto end = buffer + size; - auto byte_width = *--end; - auto packed_type = *--end; - end -= byte_width; // The root data item. - return Reference(end, byte_width, packed_type); -} - -inline Reference GetRoot(const std::vector &buffer) { - return GetRoot(flatbuffers::vector_data(buffer), buffer.size()); -} - -// Flags that configure how the Builder behaves. -// The "Share" flags determine if the Builder automatically tries to pool -// this type. Pooling can reduce the size of serialized data if there are -// multiple maps of the same kind, at the expense of slightly slower -// serialization (the cost of lookups) and more memory use (std::set). -// By default this is on for keys, but off for strings. -// Turn keys off if you have e.g. only one map. -// Turn strings on if you expect many non-unique string values. -// Additionally, sharing key vectors can save space if you have maps with -// identical field populations. -enum BuilderFlag { - BUILDER_FLAG_NONE = 0, - BUILDER_FLAG_SHARE_KEYS = 1, - BUILDER_FLAG_SHARE_STRINGS = 2, - BUILDER_FLAG_SHARE_KEYS_AND_STRINGS = 3, - BUILDER_FLAG_SHARE_KEY_VECTORS = 4, - BUILDER_FLAG_SHARE_ALL = 7, -}; - -class Builder FLATBUFFERS_FINAL_CLASS { - public: - Builder(size_t initial_size = 256, - BuilderFlag flags = BUILDER_FLAG_SHARE_KEYS) - : buf_(initial_size), - finished_(false), - flags_(flags), - force_min_bit_width_(BIT_WIDTH_8), - key_pool(KeyOffsetCompare(buf_)), - string_pool(StringOffsetCompare(buf_)) { - buf_.clear(); - } - - /// @brief Get the serialized buffer (after you call `Finish()`). - /// @return Returns a vector owned by this class. - const std::vector &GetBuffer() const { - Finished(); - return buf_; - } - - // Size of the buffer. Does not include unfinished values. - size_t GetSize() const { return buf_.size(); } - - // Reset all state so we can re-use the buffer. - void Clear() { - buf_.clear(); - stack_.clear(); - finished_ = false; - // flags_ remains as-is; - force_min_bit_width_ = BIT_WIDTH_8; - key_pool.clear(); - string_pool.clear(); - } - - // All value constructing functions below have two versions: one that - // takes a key (for placement inside a map) and one that doesn't (for inside - // vectors and elsewhere). - - void Null() { stack_.push_back(Value()); } - void Null(const char *key) { - Key(key); - Null(); - } - - void Int(int64_t i) { stack_.push_back(Value(i, FBT_INT, WidthI(i))); } - void Int(const char *key, int64_t i) { - Key(key); - Int(i); - } - - void UInt(uint64_t u) { stack_.push_back(Value(u, FBT_UINT, WidthU(u))); } - void UInt(const char *key, uint64_t u) { - Key(key); - UInt(u); - } - - void Float(float f) { stack_.push_back(Value(f)); } - void Float(const char *key, float f) { - Key(key); - Float(f); - } - - void Double(double f) { stack_.push_back(Value(f)); } - void Double(const char *key, double d) { - Key(key); - Double(d); - } - - void Bool(bool b) { stack_.push_back(Value(b)); } - void Bool(const char *key, bool b) { - Key(key); - Bool(b); - } - - void IndirectInt(int64_t i) { PushIndirect(i, FBT_INDIRECT_INT, WidthI(i)); } - void IndirectInt(const char *key, int64_t i) { - Key(key); - IndirectInt(i); - } - - void IndirectUInt(uint64_t u) { - PushIndirect(u, FBT_INDIRECT_UINT, WidthU(u)); - } - void IndirectUInt(const char *key, uint64_t u) { - Key(key); - IndirectUInt(u); - } - - void IndirectFloat(float f) { - PushIndirect(f, FBT_INDIRECT_FLOAT, BIT_WIDTH_32); - } - void IndirectFloat(const char *key, float f) { - Key(key); - IndirectFloat(f); - } - - void IndirectDouble(double f) { - PushIndirect(f, FBT_INDIRECT_FLOAT, WidthF(f)); - } - void IndirectDouble(const char *key, double d) { - Key(key); - IndirectDouble(d); - } - - size_t Key(const char *str, size_t len) { - auto sloc = buf_.size(); - WriteBytes(str, len + 1); - if (flags_ & BUILDER_FLAG_SHARE_KEYS) { - auto it = key_pool.find(sloc); - if (it != key_pool.end()) { - // Already in the buffer. Remove key we just serialized, and use - // existing offset instead. - buf_.resize(sloc); - sloc = *it; - } else { - key_pool.insert(sloc); - } - } - stack_.push_back(Value(static_cast(sloc), FBT_KEY, BIT_WIDTH_8)); - return sloc; - } - - size_t Key(const char *str) { return Key(str, strlen(str)); } - size_t Key(const std::string &str) { return Key(str.c_str(), str.size()); } - - size_t String(const char *str, size_t len) { - auto reset_to = buf_.size(); - auto sloc = CreateBlob(str, len, 1, FBT_STRING); - if (flags_ & BUILDER_FLAG_SHARE_STRINGS) { - StringOffset so(sloc, len); - auto it = string_pool.find(so); - if (it != string_pool.end()) { - // Already in the buffer. Remove string we just serialized, and use - // existing offset instead. - buf_.resize(reset_to); - sloc = it->first; - stack_.back().u_ = sloc; - } else { - string_pool.insert(so); - } - } - return sloc; - } - size_t String(const char *str) { return String(str, strlen(str)); } - size_t String(const std::string &str) { - return String(str.c_str(), str.size()); - } - void String(const flexbuffers::String &str) { - String(str.c_str(), str.length()); - } - - void String(const char *key, const char *str) { - Key(key); - String(str); - } - void String(const char *key, const std::string &str) { - Key(key); - String(str); - } - void String(const char *key, const flexbuffers::String &str) { - Key(key); - String(str); - } - - size_t Blob(const void *data, size_t len) { - return CreateBlob(data, len, 0, FBT_BLOB); - } - size_t Blob(const std::vector &v) { - return CreateBlob(flatbuffers::vector_data(v), v.size(), 0, FBT_BLOB); - } - - // TODO(wvo): support all the FlexBuffer types (like flexbuffers::String), - // e.g. Vector etc. Also in overloaded versions. - // Also some FlatBuffers types? - - size_t StartVector() { return stack_.size(); } - size_t StartVector(const char *key) { - Key(key); - return stack_.size(); - } - size_t StartMap() { return stack_.size(); } - size_t StartMap(const char *key) { - Key(key); - return stack_.size(); - } - - // TODO(wvo): allow this to specify an aligment greater than the natural - // alignment. - size_t EndVector(size_t start, bool typed, bool fixed) { - auto vec = CreateVector(start, stack_.size() - start, 1, typed, fixed); - // Remove temp elements and return vector. - stack_.resize(start); - stack_.push_back(vec); - return static_cast(vec.u_); - } - - size_t EndMap(size_t start) { - // We should have interleaved keys and values on the stack. - // Make sure it is an even number: - auto len = stack_.size() - start; - FLATBUFFERS_ASSERT(!(len & 1)); - len /= 2; - // Make sure keys are all strings: - for (auto key = start; key < stack_.size(); key += 2) { - FLATBUFFERS_ASSERT(stack_[key].type_ == FBT_KEY); - } - // Now sort values, so later we can do a binary seach lookup. - // We want to sort 2 array elements at a time. - struct TwoValue { - Value key; - Value val; - }; - // TODO(wvo): strict aliasing? - // TODO(wvo): allow the caller to indicate the data is already sorted - // for maximum efficiency? With an assert to check sortedness to make sure - // we're not breaking binary search. - // Or, we can track if the map is sorted as keys are added which would be - // be quite cheap (cheaper than checking it here), so we can skip this - // step automatically when appliccable, and encourage people to write in - // sorted fashion. - // std::sort is typically already a lot faster on sorted data though. - auto dict = - reinterpret_cast(flatbuffers::vector_data(stack_) + start); - std::sort(dict, dict + len, - [&](const TwoValue &a, const TwoValue &b) -> bool { - auto as = reinterpret_cast( - flatbuffers::vector_data(buf_) + a.key.u_); - auto bs = reinterpret_cast( - flatbuffers::vector_data(buf_) + b.key.u_); - auto comp = strcmp(as, bs); - // If this assertion hits, you've added two keys with the same - // value to this map. - // TODO: Have to check for pointer equality, as some sort - // implementation apparently call this function with the same - // element?? Why? - FLATBUFFERS_ASSERT(comp || &a == &b); - return comp < 0; - }); - // First create a vector out of all keys. - // TODO(wvo): if kBuilderFlagShareKeyVectors is true, see if we can share - // the first vector. - auto keys = CreateVector(start, len, 2, true, false); - auto vec = CreateVector(start + 1, len, 2, false, false, &keys); - // Remove temp elements and return map. - stack_.resize(start); - stack_.push_back(vec); - return static_cast(vec.u_); - } - - template size_t Vector(F f) { - auto start = StartVector(); - f(); - return EndVector(start, false, false); - } - template size_t Vector(F f, T &state) { - auto start = StartVector(); - f(state); - return EndVector(start, false, false); - } - template size_t Vector(const char *key, F f) { - auto start = StartVector(key); - f(); - return EndVector(start, false, false); - } - template - size_t Vector(const char *key, F f, T &state) { - auto start = StartVector(key); - f(state); - return EndVector(start, false, false); - } - - template void Vector(const T *elems, size_t len) { - if (flatbuffers::is_scalar::value) { - // This path should be a lot quicker and use less space. - ScalarVector(elems, len, false); - } else { - auto start = StartVector(); - for (size_t i = 0; i < len; i++) Add(elems[i]); - EndVector(start, false, false); - } - } - template - void Vector(const char *key, const T *elems, size_t len) { - Key(key); - Vector(elems, len); - } - template void Vector(const std::vector &vec) { - Vector(flatbuffers::vector_data(vec), vec.size()); - } - - template size_t TypedVector(F f) { - auto start = StartVector(); - f(); - return EndVector(start, true, false); - } - template size_t TypedVector(F f, T &state) { - auto start = StartVector(); - f(state); - return EndVector(start, true, false); - } - template size_t TypedVector(const char *key, F f) { - auto start = StartVector(key); - f(); - return EndVector(start, true, false); - } - template - size_t TypedVector(const char *key, F f, T &state) { - auto start = StartVector(key); - f(state); - return EndVector(start, true, false); - } - - template size_t FixedTypedVector(const T *elems, size_t len) { - // We only support a few fixed vector lengths. Anything bigger use a - // regular typed vector. - FLATBUFFERS_ASSERT(len >= 2 && len <= 4); - // And only scalar values. - static_assert(flatbuffers::is_scalar::value, "Unrelated types"); - return ScalarVector(elems, len, true); - } - - template - size_t FixedTypedVector(const char *key, const T *elems, size_t len) { - Key(key); - return FixedTypedVector(elems, len); - } - - template size_t Map(F f) { - auto start = StartMap(); - f(); - return EndMap(start); - } - template size_t Map(F f, T &state) { - auto start = StartMap(); - f(state); - return EndMap(start); - } - template size_t Map(const char *key, F f) { - auto start = StartMap(key); - f(); - return EndMap(start); - } - template size_t Map(const char *key, F f, T &state) { - auto start = StartMap(key); - f(state); - return EndMap(start); - } - template void Map(const std::map &map) { - auto start = StartMap(); - for (auto it = map.begin(); it != map.end(); ++it) - Add(it->first.c_str(), it->second); - EndMap(start); - } - - // Overloaded Add that tries to call the correct function above. - void Add(int8_t i) { Int(i); } - void Add(int16_t i) { Int(i); } - void Add(int32_t i) { Int(i); } - void Add(int64_t i) { Int(i); } - void Add(uint8_t u) { UInt(u); } - void Add(uint16_t u) { UInt(u); } - void Add(uint32_t u) { UInt(u); } - void Add(uint64_t u) { UInt(u); } - void Add(float f) { Float(f); } - void Add(double d) { Double(d); } - void Add(bool b) { Bool(b); } - void Add(const char *str) { String(str); } - void Add(const std::string &str) { String(str); } - void Add(const flexbuffers::String &str) { String(str); } - - template void Add(const std::vector &vec) { Vector(vec); } - - template void Add(const char *key, const T &t) { - Key(key); - Add(t); - } - - template void Add(const std::map &map) { - Map(map); - } - - template void operator+=(const T &t) { Add(t); } - - // This function is useful in combination with the Mutate* functions above. - // It forces elements of vectors and maps to have a minimum size, such that - // they can later be updated without failing. - // Call with no arguments to reset. - void ForceMinimumBitWidth(BitWidth bw = BIT_WIDTH_8) { - force_min_bit_width_ = bw; - } - - void Finish() { - // If you hit this assert, you likely have objects that were never included - // in a parent. You need to have exactly one root to finish a buffer. - // Check your Start/End calls are matched, and all objects are inside - // some other object. - FLATBUFFERS_ASSERT(stack_.size() == 1); - - // Write root value. - auto byte_width = Align(stack_[0].ElemWidth(buf_.size(), 0)); - WriteAny(stack_[0], byte_width); - // Write root type. - Write(stack_[0].StoredPackedType(), 1); - // Write root size. Normally determined by parent, but root has no parent :) - Write(byte_width, 1); - - finished_ = true; - } - - private: - void Finished() const { - // If you get this assert, you're attempting to get access a buffer - // which hasn't been finished yet. Be sure to call - // Builder::Finish with your root object. - FLATBUFFERS_ASSERT(finished_); - } - - // Align to prepare for writing a scalar with a certain size. - uint8_t Align(BitWidth alignment) { - auto byte_width = 1U << alignment; - buf_.insert(buf_.end(), flatbuffers::PaddingBytes(buf_.size(), byte_width), - 0); - return static_cast(byte_width); - } - - void WriteBytes(const void *val, size_t size) { - buf_.insert(buf_.end(), reinterpret_cast(val), - reinterpret_cast(val) + size); - } - - template void Write(T val, size_t byte_width) { - FLATBUFFERS_ASSERT(sizeof(T) >= byte_width); - val = flatbuffers::EndianScalar(val); - WriteBytes(&val, byte_width); - } - - void WriteDouble(double f, uint8_t byte_width) { - switch (byte_width) { - case 8: Write(f, byte_width); break; - case 4: Write(static_cast(f), byte_width); break; - // case 2: Write(static_cast(f), byte_width); break; - // case 1: Write(static_cast(f), byte_width); break; - default: FLATBUFFERS_ASSERT(0); - } - } - - void WriteOffset(uint64_t o, uint8_t byte_width) { - auto reloff = buf_.size() - o; - FLATBUFFERS_ASSERT(byte_width == 8 || reloff < 1ULL << (byte_width * 8)); - Write(reloff, byte_width); - } - - template void PushIndirect(T val, Type type, BitWidth bit_width) { - auto byte_width = Align(bit_width); - auto iloc = buf_.size(); - Write(val, byte_width); - stack_.push_back(Value(static_cast(iloc), type, bit_width)); - } - - static BitWidth WidthB(size_t byte_width) { - switch (byte_width) { - case 1: return BIT_WIDTH_8; - case 2: return BIT_WIDTH_16; - case 4: return BIT_WIDTH_32; - case 8: return BIT_WIDTH_64; - default: FLATBUFFERS_ASSERT(false); return BIT_WIDTH_64; - } - } - - template static Type GetScalarType() { - static_assert(flatbuffers::is_scalar::value, "Unrelated types"); - return flatbuffers::is_floating_point::value - ? FBT_FLOAT - : flatbuffers::is_same::value - ? FBT_BOOL - : (flatbuffers::is_unsigned::value ? FBT_UINT - : FBT_INT); - } - - struct Value { - union { - int64_t i_; - uint64_t u_; - double f_; - }; - - Type type_; - - // For scalars: of itself, for vector: of its elements, for string: length. - BitWidth min_bit_width_; - - Value() : i_(0), type_(FBT_NULL), min_bit_width_(BIT_WIDTH_8) {} - - Value(bool b) - : u_(static_cast(b)), - type_(FBT_BOOL), - min_bit_width_(BIT_WIDTH_8) {} - - Value(int64_t i, Type t, BitWidth bw) - : i_(i), type_(t), min_bit_width_(bw) {} - Value(uint64_t u, Type t, BitWidth bw) - : u_(u), type_(t), min_bit_width_(bw) {} - - Value(float f) : f_(f), type_(FBT_FLOAT), min_bit_width_(BIT_WIDTH_32) {} - Value(double f) : f_(f), type_(FBT_FLOAT), min_bit_width_(WidthF(f)) {} - - uint8_t StoredPackedType(BitWidth parent_bit_width_ = BIT_WIDTH_8) const { - return PackedType(StoredWidth(parent_bit_width_), type_); - } - - BitWidth ElemWidth(size_t buf_size, size_t elem_index) const { - if (IsInline(type_)) { - return min_bit_width_; - } else { - // We have an absolute offset, but want to store a relative offset - // elem_index elements beyond the current buffer end. Since whether - // the relative offset fits in a certain byte_width depends on - // the size of the elements before it (and their alignment), we have - // to test for each size in turn. - for (size_t byte_width = 1; - byte_width <= sizeof(flatbuffers::largest_scalar_t); - byte_width *= 2) { - // Where are we going to write this offset? - auto offset_loc = buf_size + - flatbuffers::PaddingBytes(buf_size, byte_width) + - elem_index * byte_width; - // Compute relative offset. - auto offset = offset_loc - u_; - // Does it fit? - auto bit_width = WidthU(offset); - if (static_cast(static_cast(1U) << bit_width) == - byte_width) - return bit_width; - } - FLATBUFFERS_ASSERT(false); // Must match one of the sizes above. - return BIT_WIDTH_64; - } - } - - BitWidth StoredWidth(BitWidth parent_bit_width_ = BIT_WIDTH_8) const { - if (IsInline(type_)) { - return (std::max)(min_bit_width_, parent_bit_width_); - } else { - return min_bit_width_; - } - } - }; - - void WriteAny(const Value &val, uint8_t byte_width) { - switch (val.type_) { - case FBT_NULL: - case FBT_INT: Write(val.i_, byte_width); break; - case FBT_BOOL: - case FBT_UINT: Write(val.u_, byte_width); break; - case FBT_FLOAT: WriteDouble(val.f_, byte_width); break; - default: WriteOffset(val.u_, byte_width); break; - } - } - - size_t CreateBlob(const void *data, size_t len, size_t trailing, Type type) { - auto bit_width = WidthU(len); - auto byte_width = Align(bit_width); - Write(len, byte_width); - auto sloc = buf_.size(); - WriteBytes(data, len + trailing); - stack_.push_back(Value(static_cast(sloc), type, bit_width)); - return sloc; - } - - template - size_t ScalarVector(const T *elems, size_t len, bool fixed) { - auto vector_type = GetScalarType(); - auto byte_width = sizeof(T); - auto bit_width = WidthB(byte_width); - // If you get this assert, you're trying to write a vector with a size - // field that is bigger than the scalars you're trying to write (e.g. a - // byte vector > 255 elements). For such types, write a "blob" instead. - // TODO: instead of asserting, could write vector with larger elements - // instead, though that would be wasteful. - FLATBUFFERS_ASSERT(WidthU(len) <= bit_width); - if (!fixed) Write(len, byte_width); - auto vloc = buf_.size(); - for (size_t i = 0; i < len; i++) Write(elems[i], byte_width); - stack_.push_back(Value(static_cast(vloc), - ToTypedVector(vector_type, fixed ? len : 0), - bit_width)); - return vloc; - } - - Value CreateVector(size_t start, size_t vec_len, size_t step, bool typed, - bool fixed, const Value *keys = nullptr) { - FLATBUFFERS_ASSERT(!fixed || typed); // typed=false, fixed=true combination is not supported. - // Figure out smallest bit width we can store this vector with. - auto bit_width = (std::max)(force_min_bit_width_, WidthU(vec_len)); - auto prefix_elems = 1; - if (keys) { - // If this vector is part of a map, we will pre-fix an offset to the keys - // to this vector. - bit_width = (std::max)(bit_width, keys->ElemWidth(buf_.size(), 0)); - prefix_elems += 2; - } - Type vector_type = FBT_KEY; - // Check bit widths and types for all elements. - for (size_t i = start; i < stack_.size(); i += step) { - auto elem_width = stack_[i].ElemWidth(buf_.size(), i + prefix_elems); - bit_width = (std::max)(bit_width, elem_width); - if (typed) { - if (i == start) { - vector_type = stack_[i].type_; - } else { - // If you get this assert, you are writing a typed vector with - // elements that are not all the same type. - FLATBUFFERS_ASSERT(vector_type == stack_[i].type_); - } - } - } - // If you get this assert, your fixed types are not one of: - // Int / UInt / Float / Key. - FLATBUFFERS_ASSERT(!fixed || IsTypedVectorElementType(vector_type)); - auto byte_width = Align(bit_width); - // Write vector. First the keys width/offset if available, and size. - if (keys) { - WriteOffset(keys->u_, byte_width); - Write(1ULL << keys->min_bit_width_, byte_width); - } - if (!fixed) Write(vec_len, byte_width); - // Then the actual data. - auto vloc = buf_.size(); - for (size_t i = start; i < stack_.size(); i += step) { - WriteAny(stack_[i], byte_width); - } - // Then the types. - if (!typed) { - for (size_t i = start; i < stack_.size(); i += step) { - buf_.push_back(stack_[i].StoredPackedType(bit_width)); - } - } - return Value(static_cast(vloc), - keys ? FBT_MAP - : (typed ? ToTypedVector(vector_type, fixed ? vec_len : 0) - : FBT_VECTOR), - bit_width); - } - - // You shouldn't really be copying instances of this class. - Builder(const Builder &); - Builder &operator=(const Builder &); - - std::vector buf_; - std::vector stack_; - - bool finished_; - - BuilderFlag flags_; - - BitWidth force_min_bit_width_; - - struct KeyOffsetCompare { - explicit KeyOffsetCompare(const std::vector &buf) : buf_(&buf) {} - bool operator()(size_t a, size_t b) const { - auto stra = - reinterpret_cast(flatbuffers::vector_data(*buf_) + a); - auto strb = - reinterpret_cast(flatbuffers::vector_data(*buf_) + b); - return strcmp(stra, strb) < 0; - } - const std::vector *buf_; - }; - - typedef std::pair StringOffset; - struct StringOffsetCompare { - explicit StringOffsetCompare(const std::vector &buf) : buf_(&buf) {} - bool operator()(const StringOffset &a, const StringOffset &b) const { - auto stra = reinterpret_cast( - flatbuffers::vector_data(*buf_) + a.first); - auto strb = reinterpret_cast( - flatbuffers::vector_data(*buf_) + b.first); - return strncmp(stra, strb, (std::min)(a.second, b.second) + 1) < 0; - } - const std::vector *buf_; - }; - - typedef std::set KeyOffsetMap; - typedef std::set StringOffsetMap; - - KeyOffsetMap key_pool; - StringOffsetMap string_pool; -}; - -} // namespace flexbuffers - -# if defined(_MSC_VER) -# pragma warning(pop) -# endif - -#endif // FLATBUFFERS_FLEXBUFFERS_H_ diff --git a/src/internal/include/flatbuffers/grpc.h b/src/internal/include/flatbuffers/grpc.h deleted file mode 100644 index a75b67c..0000000 --- a/src/internal/include/flatbuffers/grpc.h +++ /dev/null @@ -1,328 +0,0 @@ -/* - * 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. - */ - -#ifndef FLATBUFFERS_GRPC_H_ -#define FLATBUFFERS_GRPC_H_ - -// Helper functionality to glue FlatBuffers and GRPC. - -#include "flatbuffers/flatbuffers.h" -#include "grpc++/support/byte_buffer.h" -#include "grpc/byte_buffer_reader.h" - -namespace flatbuffers { -namespace grpc { - -// Message is a typed wrapper around a buffer that manages the underlying -// `grpc_slice` and also provides flatbuffers-specific helpers such as `Verify` -// and `GetRoot`. Since it is backed by a `grpc_slice`, the underlying buffer -// is refcounted and ownership is be managed automatically. -template class Message { - public: - Message() : slice_(grpc_empty_slice()) {} - - Message(grpc_slice slice, bool add_ref) - : slice_(add_ref ? grpc_slice_ref(slice) : slice) {} - - Message &operator=(const Message &other) = delete; - - Message(Message &&other) : slice_(other.slice_) { - other.slice_ = grpc_empty_slice(); - } - - Message(const Message &other) = delete; - - Message &operator=(Message &&other) { - grpc_slice_unref(slice_); - slice_ = other.slice_; - other.slice_ = grpc_empty_slice(); - return *this; - } - - ~Message() { grpc_slice_unref(slice_); } - - const uint8_t *mutable_data() const { return GRPC_SLICE_START_PTR(slice_); } - - const uint8_t *data() const { return GRPC_SLICE_START_PTR(slice_); } - - size_t size() const { return GRPC_SLICE_LENGTH(slice_); } - - bool Verify() const { - Verifier verifier(data(), size()); - return verifier.VerifyBuffer(nullptr); - } - - T *GetMutableRoot() { return flatbuffers::GetMutableRoot(mutable_data()); } - - const T *GetRoot() const { return flatbuffers::GetRoot(data()); } - - // This is only intended for serializer use, or if you know what you're doing - const grpc_slice &BorrowSlice() const { return slice_; } - - private: - grpc_slice slice_; -}; - -class MessageBuilder; - -// SliceAllocator is a gRPC-specific allocator that uses the `grpc_slice` -// refcounted slices to manage memory ownership. This makes it easy and -// efficient to transfer buffers to gRPC. -class SliceAllocator : public Allocator { - public: - SliceAllocator() : slice_(grpc_empty_slice()) {} - - SliceAllocator(const SliceAllocator &other) = delete; - SliceAllocator &operator=(const SliceAllocator &other) = delete; - - SliceAllocator(SliceAllocator &&other) - : slice_(grpc_empty_slice()) { - // default-construct and swap idiom - swap(other); - } - - SliceAllocator &operator=(SliceAllocator &&other) { - // move-construct and swap idiom - SliceAllocator temp(std::move(other)); - swap(temp); - return *this; - } - - void swap(SliceAllocator &other) { - using std::swap; - swap(slice_, other.slice_); - } - - virtual ~SliceAllocator() { grpc_slice_unref(slice_); } - - virtual uint8_t *allocate(size_t size) override { - FLATBUFFERS_ASSERT(GRPC_SLICE_IS_EMPTY(slice_)); - slice_ = grpc_slice_malloc(size); - return GRPC_SLICE_START_PTR(slice_); - } - - virtual void deallocate(uint8_t *p, size_t size) override { - FLATBUFFERS_ASSERT(p == GRPC_SLICE_START_PTR(slice_)); - FLATBUFFERS_ASSERT(size == GRPC_SLICE_LENGTH(slice_)); - grpc_slice_unref(slice_); - slice_ = grpc_empty_slice(); - } - - virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, - size_t new_size, size_t in_use_back, - size_t in_use_front) override { - FLATBUFFERS_ASSERT(old_p == GRPC_SLICE_START_PTR(slice_)); - FLATBUFFERS_ASSERT(old_size == GRPC_SLICE_LENGTH(slice_)); - FLATBUFFERS_ASSERT(new_size > old_size); - grpc_slice old_slice = slice_; - grpc_slice new_slice = grpc_slice_malloc(new_size); - uint8_t *new_p = GRPC_SLICE_START_PTR(new_slice); - memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, - in_use_front); - slice_ = new_slice; - grpc_slice_unref(old_slice); - return new_p; - } - - private: - grpc_slice &get_slice(uint8_t *p, size_t size) { - FLATBUFFERS_ASSERT(p == GRPC_SLICE_START_PTR(slice_)); - FLATBUFFERS_ASSERT(size == GRPC_SLICE_LENGTH(slice_)); - return slice_; - } - - grpc_slice slice_; - - friend class MessageBuilder; -}; - -// SliceAllocatorMember is a hack to ensure that the MessageBuilder's -// slice_allocator_ member is constructed before the FlatBufferBuilder, since -// the allocator is used in the FlatBufferBuilder ctor. -namespace detail { -struct SliceAllocatorMember { - SliceAllocator slice_allocator_; -}; -} // namespace detail - -// MessageBuilder is a gRPC-specific FlatBufferBuilder that uses SliceAllocator -// to allocate gRPC buffers. -class MessageBuilder : private detail::SliceAllocatorMember, - public FlatBufferBuilder { - public: - explicit MessageBuilder(uoffset_t initial_size = 1024) - : FlatBufferBuilder(initial_size, &slice_allocator_, false) {} - - MessageBuilder(const MessageBuilder &other) = delete; - MessageBuilder &operator=(const MessageBuilder &other) = delete; - - MessageBuilder(MessageBuilder &&other) - : FlatBufferBuilder(1024, &slice_allocator_, false) { - // Default construct and swap idiom. - Swap(other); - } - - /// Create a MessageBuilder from a FlatBufferBuilder. - explicit MessageBuilder(FlatBufferBuilder &&src, void (*dealloc)(void*, size_t) = &DefaultAllocator::dealloc) - : FlatBufferBuilder(1024, &slice_allocator_, false) { - src.Swap(*this); - src.SwapBufAllocator(*this); - if (buf_.capacity()) { - uint8_t *buf = buf_.scratch_data(); // pointer to memory - size_t capacity = buf_.capacity(); // size of memory - slice_allocator_.slice_ = grpc_slice_new_with_len(buf, capacity, dealloc); - } - else { - slice_allocator_.slice_ = grpc_empty_slice(); - } - } - - /// Move-assign a FlatBufferBuilder to a MessageBuilder. - /// Only FlatBufferBuilder with default allocator (basically, nullptr) is supported. - MessageBuilder &operator=(FlatBufferBuilder &&src) { - // Move construct a temporary and swap - MessageBuilder temp(std::move(src)); - Swap(temp); - return *this; - } - - MessageBuilder &operator=(MessageBuilder &&other) { - // Move construct a temporary and swap - MessageBuilder temp(std::move(other)); - Swap(temp); - return *this; - } - - void Swap(MessageBuilder &other) { - slice_allocator_.swap(other.slice_allocator_); - FlatBufferBuilder::Swap(other); - // After swapping the FlatBufferBuilder, we swap back the allocator, which restores - // the original allocator back in place. This is necessary because MessageBuilder's - // allocator is its own member (SliceAllocatorMember). The allocator passed to - // FlatBufferBuilder::vector_downward must point to this member. - buf_.swap_allocator(other.buf_); - } - - // Releases the ownership of the buffer pointer. - // Returns the size, offset, and the original grpc_slice that - // allocated the buffer. Also see grpc_slice_unref(). - uint8_t *ReleaseRaw(size_t &size, size_t &offset, grpc_slice &slice) { - uint8_t *buf = FlatBufferBuilder::ReleaseRaw(size, offset); - slice = slice_allocator_.slice_; - slice_allocator_.slice_ = grpc_empty_slice(); - return buf; - } - - ~MessageBuilder() {} - - // GetMessage extracts the subslice of the buffer corresponding to the - // flatbuffers-encoded region and wraps it in a `Message` to handle buffer - // ownership. - template Message GetMessage() { - auto buf_data = buf_.scratch_data(); // pointer to memory - auto buf_size = buf_.capacity(); // size of memory - auto msg_data = buf_.data(); // pointer to msg - auto msg_size = buf_.size(); // size of msg - // Do some sanity checks on data/size - FLATBUFFERS_ASSERT(msg_data); - FLATBUFFERS_ASSERT(msg_size); - FLATBUFFERS_ASSERT(msg_data >= buf_data); - FLATBUFFERS_ASSERT(msg_data + msg_size <= buf_data + buf_size); - // Calculate offsets from the buffer start - auto begin = msg_data - buf_data; - auto end = begin + msg_size; - // Get the slice we are working with (no refcount change) - grpc_slice slice = slice_allocator_.get_slice(buf_data, buf_size); - // Extract a subslice of the existing slice (increment refcount) - grpc_slice subslice = grpc_slice_sub(slice, begin, end); - // Wrap the subslice in a `Message`, but don't increment refcount - Message msg(subslice, false); - return msg; - } - - template Message ReleaseMessage() { - Message msg = GetMessage(); - Reset(); - return msg; - } - - private: - // SliceAllocator slice_allocator_; // part of SliceAllocatorMember -}; - -} // namespace grpc -} // namespace flatbuffers - -namespace grpc { - -template class SerializationTraits> { - public: - static grpc::Status Serialize(const flatbuffers::grpc::Message &msg, - grpc_byte_buffer **buffer, bool *own_buffer) { - // We are passed in a `Message`, which is a wrapper around a - // `grpc_slice`. We extract it here using `BorrowSlice()`. The const cast - // is necesary because the `grpc_raw_byte_buffer_create` func expects - // non-const slices in order to increment their refcounts. - grpc_slice *slice = const_cast(&msg.BorrowSlice()); - // Now use `grpc_raw_byte_buffer_create` to package the single slice into a - // `grpc_byte_buffer`, incrementing the refcount in the process. - *buffer = grpc_raw_byte_buffer_create(slice, 1); - *own_buffer = true; - return grpc::Status::OK; - } - - // Deserialize by pulling the - static grpc::Status Deserialize(grpc_byte_buffer *buffer, - flatbuffers::grpc::Message *msg) { - if (!buffer) { - return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload"); - } - // Check if this is a single uncompressed slice. - if ((buffer->type == GRPC_BB_RAW) && - (buffer->data.raw.compression == GRPC_COMPRESS_NONE) && - (buffer->data.raw.slice_buffer.count == 1)) { - // If it is, then we can reference the `grpc_slice` directly. - grpc_slice slice = buffer->data.raw.slice_buffer.slices[0]; - // We wrap a `Message` around the slice, incrementing the refcount. - *msg = flatbuffers::grpc::Message(slice, true); - } else { - // Otherwise, we need to use `grpc_byte_buffer_reader_readall` to read - // `buffer` into a single contiguous `grpc_slice`. The gRPC reader gives - // us back a new slice with the refcount already incremented. - grpc_byte_buffer_reader reader; - grpc_byte_buffer_reader_init(&reader, buffer); - grpc_slice slice = grpc_byte_buffer_reader_readall(&reader); - grpc_byte_buffer_reader_destroy(&reader); - // We wrap a `Message` around the slice, but dont increment refcount - *msg = flatbuffers::grpc::Message(slice, false); - } - grpc_byte_buffer_destroy(buffer); -#if FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION - return ::grpc::Status::OK; -#else - if (msg->Verify()) { - return ::grpc::Status::OK; - } else { - return ::grpc::Status(::grpc::StatusCode::INTERNAL, - "Message verification failed"); - } -#endif - } -}; - -} // namespace grpc - -#endif // FLATBUFFERS_GRPC_H_ diff --git a/src/internal/include/flatbuffers/hash.h b/src/internal/include/flatbuffers/hash.h deleted file mode 100644 index a97b231..0000000 --- a/src/internal/include/flatbuffers/hash.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2015 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. - */ - -#ifndef FLATBUFFERS_HASH_H_ -#define FLATBUFFERS_HASH_H_ - -#include -#include - -#include "flatbuffers/flatbuffers.h" - -namespace flatbuffers { - -template struct FnvTraits { - static const T kFnvPrime; - static const T kOffsetBasis; -}; - -template<> struct FnvTraits { - static const uint32_t kFnvPrime = 0x01000193; - static const uint32_t kOffsetBasis = 0x811C9DC5; -}; - -template<> struct FnvTraits { - static const uint64_t kFnvPrime = 0x00000100000001b3ULL; - static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL; -}; - -template FLATBUFFERS_CONSTEXPR_CPP14 T HashFnv1(const char *input) { - T hash = FnvTraits::kOffsetBasis; - for (const char *c = input; *c; ++c) { - hash *= FnvTraits::kFnvPrime; - hash ^= static_cast(*c); - } - return hash; -} - -template FLATBUFFERS_CONSTEXPR_CPP14 T HashFnv1a(const char *input) { - T hash = FnvTraits::kOffsetBasis; - for (const char *c = input; *c; ++c) { - hash ^= static_cast(*c); - hash *= FnvTraits::kFnvPrime; - } - return hash; -} - -template <> FLATBUFFERS_CONSTEXPR_CPP14 inline uint16_t HashFnv1(const char *input) { - uint32_t hash = HashFnv1(input); - return (hash >> 16) ^ (hash & 0xffff); -} - -template <> FLATBUFFERS_CONSTEXPR_CPP14 inline uint16_t HashFnv1a(const char *input) { - uint32_t hash = HashFnv1a(input); - return (hash >> 16) ^ (hash & 0xffff); -} - -template struct NamedHashFunction { - const char *name; - - typedef T (*HashFunction)(const char *); - HashFunction function; -}; - -const NamedHashFunction kHashFunctions16[] = { - { "fnv1_16", HashFnv1 }, - { "fnv1a_16", HashFnv1a }, -}; - -const NamedHashFunction kHashFunctions32[] = { - { "fnv1_32", HashFnv1 }, - { "fnv1a_32", HashFnv1a }, -}; - -const NamedHashFunction kHashFunctions64[] = { - { "fnv1_64", HashFnv1 }, - { "fnv1a_64", HashFnv1a }, -}; - -inline NamedHashFunction::HashFunction FindHashFunction16( - const char *name) { - std::size_t size = sizeof(kHashFunctions16) / sizeof(kHashFunctions16[0]); - for (std::size_t i = 0; i < size; ++i) { - if (std::strcmp(name, kHashFunctions16[i].name) == 0) { - return kHashFunctions16[i].function; - } - } - return nullptr; -} - -inline NamedHashFunction::HashFunction FindHashFunction32( - const char *name) { - std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]); - for (std::size_t i = 0; i < size; ++i) { - if (std::strcmp(name, kHashFunctions32[i].name) == 0) { - return kHashFunctions32[i].function; - } - } - return nullptr; -} - -inline NamedHashFunction::HashFunction FindHashFunction64( - const char *name) { - std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]); - for (std::size_t i = 0; i < size; ++i) { - if (std::strcmp(name, kHashFunctions64[i].name) == 0) { - return kHashFunctions64[i].function; - } - } - return nullptr; -} - -} // namespace flatbuffers - -#endif // FLATBUFFERS_HASH_H_ diff --git a/src/internal/include/flatbuffers/idl.h b/src/internal/include/flatbuffers/idl.h deleted file mode 100644 index e48edb0..0000000 --- a/src/internal/include/flatbuffers/idl.h +++ /dev/null @@ -1,973 +0,0 @@ -/* - * 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. - */ - -#ifndef FLATBUFFERS_IDL_H_ -#define FLATBUFFERS_IDL_H_ - -#include -#include -#include - -#include "flatbuffers/base.h" -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/flexbuffers.h" -#include "flatbuffers/hash.h" -#include "flatbuffers/reflection.h" - -#if !defined(FLATBUFFERS_CPP98_STL) -# include -#endif // !defined(FLATBUFFERS_CPP98_STL) - -// This file defines the data types representing a parsed IDL (Interface -// Definition Language) / schema file. - -// Limits maximum depth of nested objects. -// Prevents stack overflow while parse flatbuffers or json. -#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH) -# define FLATBUFFERS_MAX_PARSING_DEPTH 64 -#endif - -namespace flatbuffers { - -// The order of these matters for Is*() functions below. -// Additionally, Parser::ParseType assumes bool..string is a contiguous range -// of type tokens. -// clang-format off -#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ - TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8) \ - TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8) /* begin scalar/int */ \ - TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool) \ - TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8) \ - TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8) \ - TD(SHORT, "short", int16_t, short, int16, short, int16, i16) \ - TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16) \ - TD(INT, "int", int32_t, int, int32, int, int32, i32) \ - TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32) \ - TD(LONG, "long", int64_t, long, int64, long, int64, i64) \ - TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64) /* end int */ \ - TD(FLOAT, "float", float, float, float32, float, float32, f32) /* begin float */ \ - TD(DOUBLE, "double", double, double, float64, double, float64, f64) /* end float/scalar */ -#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \ - TD(STRING, "string", Offset, int, int, StringOffset, int, unused) \ - TD(VECTOR, "", Offset, int, int, VectorOffset, int, unused) \ - TD(STRUCT, "", Offset, int, int, int, int, unused) \ - TD(UNION, "", Offset, int, int, int, int, unused) - -// The fields are: -// - enum -// - FlatBuffers schema type. -// - C++ type. -// - Java type. -// - Go type. -// - C# / .Net type. -// - Python type. -// - Rust type. - -// using these macros, we can now write code dealing with types just once, e.g. - -/* -switch (type) { - #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE) \ - case BASE_TYPE_ ## ENUM: \ - // do something specific to CTYPE here - FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) - #undef FLATBUFFERS_TD -} -*/ - -#define FLATBUFFERS_GEN_TYPES(TD) \ - FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ - FLATBUFFERS_GEN_TYPES_POINTER(TD) - -// Create an enum for all the types above. -#ifdef __GNUC__ -__extension__ // Stop GCC complaining about trailing comma with -Wpendantic. -#endif -enum BaseType { - #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE) \ - BASE_TYPE_ ## ENUM, - FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) - #undef FLATBUFFERS_TD -}; - -#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE) \ - static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ - "define largest_scalar_t as " #CTYPE); - FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) -#undef FLATBUFFERS_TD - -inline bool IsScalar (BaseType t) { return t >= BASE_TYPE_UTYPE && - t <= BASE_TYPE_DOUBLE; } -inline bool IsInteger(BaseType t) { return t >= BASE_TYPE_UTYPE && - t <= BASE_TYPE_ULONG; } -inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT || - t == BASE_TYPE_DOUBLE; } -inline bool IsLong (BaseType t) { return t == BASE_TYPE_LONG || - t == BASE_TYPE_ULONG; } -inline bool IsBool (BaseType t) { return t == BASE_TYPE_BOOL; } -inline bool IsOneByte(BaseType t) { return t >= BASE_TYPE_UTYPE && - t <= BASE_TYPE_UCHAR; } -// clang-format on - -extern const char *const kTypeNames[]; -extern const char kTypeSizes[]; - -inline size_t SizeOf(BaseType t) { return kTypeSizes[t]; } - -struct StructDef; -struct EnumDef; -class Parser; - -// Represents any type in the IDL, which is a combination of the BaseType -// and additional information for vectors/structs_. -struct Type { - explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd = nullptr, - EnumDef *_ed = nullptr) - : base_type(_base_type), - element(BASE_TYPE_NONE), - struct_def(_sd), - enum_def(_ed) {} - - bool operator==(const Type &o) { - return base_type == o.base_type && element == o.element && - struct_def == o.struct_def && enum_def == o.enum_def; - } - - Type VectorType() const { return Type(element, struct_def, enum_def); } - - Offset Serialize(FlatBufferBuilder *builder) const; - - bool Deserialize(const Parser &parser, const reflection::Type *type); - - BaseType base_type; - BaseType element; // only set if t == BASE_TYPE_VECTOR - StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT - EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE, - // or for an integral type derived from an enum. -}; - -// Represents a parsed scalar value, it's type, and field offset. -struct Value { - Value() - : constant("0"), - offset(static_cast(~(static_cast(0U)))) {} - Type type; - std::string constant; - voffset_t offset; -}; - -// Helper class that retains the original order of a set of identifiers and -// also provides quick lookup. -template class SymbolTable { - public: - ~SymbolTable() { - for (auto it = vec.begin(); it != vec.end(); ++it) { delete *it; } - } - - bool Add(const std::string &name, T *e) { - vector_emplace_back(&vec, e); - auto it = dict.find(name); - if (it != dict.end()) return true; - dict[name] = e; - return false; - } - - void Move(const std::string &oldname, const std::string &newname) { - auto it = dict.find(oldname); - if (it != dict.end()) { - auto obj = it->second; - dict.erase(it); - dict[newname] = obj; - } else { - FLATBUFFERS_ASSERT(false); - } - } - - T *Lookup(const std::string &name) const { - auto it = dict.find(name); - return it == dict.end() ? nullptr : it->second; - } - - public: - std::map dict; // quick lookup - std::vector vec; // Used to iterate in order of insertion -}; - -// A name space, as set in the schema. -struct Namespace { - Namespace() : from_table(0) {} - - // Given a (potentally unqualified) name, return the "fully qualified" name - // which has a full namespaced descriptor. - // With max_components you can request less than the number of components - // the current namespace has. - std::string GetFullyQualifiedName(const std::string &name, - size_t max_components = 1000) const; - - std::vector components; - size_t from_table; // Part of the namespace corresponds to a message/table. -}; - -// Base class for all definition types (fields, structs_, enums_). -struct Definition { - Definition() - : generated(false), - defined_namespace(nullptr), - serialized_location(0), - index(-1), - refcount(1) {} - - flatbuffers::Offset< - flatbuffers::Vector>> - SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const; - - bool DeserializeAttributes(Parser &parser, - const Vector> *attrs); - - std::string name; - std::string file; - std::vector doc_comment; - SymbolTable attributes; - bool generated; // did we already output code for this definition? - Namespace *defined_namespace; // Where it was defined. - - // For use with Serialize() - uoffset_t serialized_location; - int index; // Inside the vector it is stored. - int refcount; -}; - -struct FieldDef : public Definition { - FieldDef() - : deprecated(false), - required(false), - key(false), - native_inline(false), - flexbuffer(false), - nested_flatbuffer(NULL), - padding(0) {} - - Offset Serialize(FlatBufferBuilder *builder, uint16_t id, - const Parser &parser) const; - - bool Deserialize(Parser &parser, const reflection::Field *field); - - Value value; - bool deprecated; // Field is allowed to be present in old data, but can't be. - // written in new data nor accessed in new code. - bool required; // Field must always be present. - bool key; // Field functions as a key for creating sorted vectors. - bool native_inline; // Field will be defined inline (instead of as a pointer) - // for native tables if field is a struct. - bool flexbuffer; // This field contains FlexBuffer data. - StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data. - size_t padding; // Bytes to always pad after this field. -}; - -struct StructDef : public Definition { - StructDef() - : fixed(false), - predecl(true), - sortbysize(true), - has_key(false), - minalign(1), - bytesize(0) {} - - void PadLastField(size_t min_align) { - auto padding = PaddingBytes(bytesize, min_align); - bytesize += padding; - if (fields.vec.size()) fields.vec.back()->padding = padding; - } - - Offset Serialize(FlatBufferBuilder *builder, - const Parser &parser) const; - - bool Deserialize(Parser &parser, const reflection::Object *object); - - SymbolTable fields; - - bool fixed; // If it's struct, not a table. - bool predecl; // If it's used before it was defined. - bool sortbysize; // Whether fields come in the declaration or size order. - bool has_key; // It has a key field. - size_t minalign; // What the whole object needs to be aligned to. - size_t bytesize; // Size if fixed. - - flatbuffers::unique_ptr original_location; -}; - -inline bool IsStruct(const Type &type) { - return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed; -} - -inline size_t InlineSize(const Type &type) { - return IsStruct(type) ? type.struct_def->bytesize : SizeOf(type.base_type); -} - -inline size_t InlineAlignment(const Type &type) { - return IsStruct(type) ? type.struct_def->minalign : SizeOf(type.base_type); -} - -struct EnumVal { - EnumVal(const std::string &_name, int64_t _val) : name(_name), value(_val) {} - EnumVal() : value(0){}; - - Offset Serialize(FlatBufferBuilder *builder, const Parser &parser) const; - - bool Deserialize(const Parser &parser, const reflection::EnumVal *val); - - std::string name; - std::vector doc_comment; - int64_t value; - Type union_type; -}; - -struct EnumDef : public Definition { - EnumDef() : is_union(false), uses_multiple_type_instances(false) {} - - EnumVal *ReverseLookup(int64_t enum_idx, bool skip_union_default = true) { - for (auto it = vals.vec.begin() + - static_cast(is_union && skip_union_default); - it != vals.vec.end(); ++it) { - if ((*it)->value == enum_idx) { return *it; } - } - return nullptr; - } - - Offset Serialize(FlatBufferBuilder *builder, const Parser &parser) const; - - bool Deserialize(Parser &parser, const reflection::Enum *values); - - SymbolTable vals; - bool is_union; - // Type is a union which uses type aliases where at least one type is - // available under two different names. - bool uses_multiple_type_instances; - Type underlying_type; -}; - -inline bool EqualByName(const Type &a, const Type &b) { - return a.base_type == b.base_type && a.element == b.element && - (a.struct_def == b.struct_def || - a.struct_def->name == b.struct_def->name) && - (a.enum_def == b.enum_def || a.enum_def->name == b.enum_def->name); -} - -struct RPCCall : public Definition { - Offset Serialize(FlatBufferBuilder *builder, const Parser &parser) const; - - bool Deserialize(Parser &parser, const reflection::RPCCall *call); - - StructDef *request, *response; -}; - -struct ServiceDef : public Definition { - Offset Serialize(FlatBufferBuilder *builder, const Parser &parser) const; - bool Deserialize(Parser &parser, const reflection::Service *service); - - SymbolTable calls; -}; - -// Container of options that may apply to any of the source/text generators. -struct IDLOptions { - bool strict_json; - bool skip_js_exports; - bool use_goog_js_export_format; - bool use_ES6_js_export_format; - bool output_default_scalars_in_json; - int indent_step; - bool output_enum_identifiers; - bool prefixed_enums; - bool scoped_enums; - bool include_dependence_headers; - bool mutable_buffer; - bool one_file; - bool proto_mode; - bool proto_oneof_union; - bool generate_all; - bool skip_unexpected_fields_in_json; - bool generate_name_strings; - bool generate_object_based_api; - bool gen_compare; - std::string cpp_object_api_pointer_type; - std::string cpp_object_api_string_type; - bool gen_nullable; - bool gen_generated; - std::string object_prefix; - std::string object_suffix; - bool union_value_namespacing; - bool allow_non_utf8; - bool natural_utf8; - std::string include_prefix; - bool keep_include_path; - bool binary_schema_comments; - bool binary_schema_builtins; - bool skip_flatbuffers_import; - std::string go_import; - std::string go_namespace; - bool reexport_ts_modules; - bool protobuf_ascii_alike; - bool size_prefixed; - std::string root_type; - bool force_defaults; - - // Possible options for the more general generator below. - enum Language { - kJava = 1 << 0, - kCSharp = 1 << 1, - kGo = 1 << 2, - kCpp = 1 << 3, - kJs = 1 << 4, - kPython = 1 << 5, - kPhp = 1 << 6, - kJson = 1 << 7, - kBinary = 1 << 8, - kTs = 1 << 9, - kJsonSchema = 1 << 10, - kDart = 1 << 11, - kLua = 1 << 12, - kLobster = 1 << 13, - kRust = 1 << 14, - kMAX - }; - - Language lang; - - enum MiniReflect { kNone, kTypes, kTypesAndNames }; - - MiniReflect mini_reflect; - - // The corresponding language bit will be set if a language is included - // for code generation. - unsigned long lang_to_generate; - - // If set (default behavior), empty string and vector fields will be set to - // nullptr to make the flatbuffer more compact. - bool set_empty_to_null; - - IDLOptions() - : strict_json(false), - skip_js_exports(false), - use_goog_js_export_format(false), - use_ES6_js_export_format(false), - output_default_scalars_in_json(false), - indent_step(2), - output_enum_identifiers(true), - prefixed_enums(true), - scoped_enums(false), - include_dependence_headers(true), - mutable_buffer(false), - one_file(false), - proto_mode(false), - proto_oneof_union(false), - generate_all(false), - skip_unexpected_fields_in_json(false), - generate_name_strings(false), - generate_object_based_api(false), - gen_compare(false), - cpp_object_api_pointer_type("std::unique_ptr"), - gen_nullable(false), - gen_generated(false), - object_suffix("T"), - union_value_namespacing(true), - allow_non_utf8(false), - natural_utf8(false), - keep_include_path(false), - binary_schema_comments(false), - binary_schema_builtins(false), - skip_flatbuffers_import(false), - reexport_ts_modules(true), - protobuf_ascii_alike(false), - size_prefixed(false), - force_defaults(false), - lang(IDLOptions::kJava), - mini_reflect(IDLOptions::kNone), - lang_to_generate(0), - set_empty_to_null(true) {} -}; - -// This encapsulates where the parser is in the current source file. -struct ParserState { - ParserState() - : cursor_(nullptr), - line_start_(nullptr), - line_(0), - token_(-1), - attr_is_trivial_ascii_string_(true) {} - - protected: - void ResetState(const char *source) { - cursor_ = source; - line_ = 0; - MarkNewLine(); - } - - void MarkNewLine() { - line_start_ = cursor_; - line_ += 1; - } - - int64_t CursorPosition() const { - FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_); - return static_cast(cursor_ - line_start_); - } - - const char *cursor_; - const char *line_start_; - int line_; // the current line being parsed - int token_; - - // Flag: text in attribute_ is true ASCII string without escape - // sequences. Only printable ASCII (without [\t\r\n]). - // Used for number-in-string (and base64 string in future). - bool attr_is_trivial_ascii_string_; - std::string attribute_; - std::vector doc_comment_; -}; - -// A way to make error propagation less error prone by requiring values to be -// checked. -// Once you create a value of this type you must either: -// - Call Check() on it. -// - Copy or assign it to another value. -// Failure to do so leads to an assert. -// This guarantees that this as return value cannot be ignored. -class CheckedError { - public: - explicit CheckedError(bool error) - : is_error_(error), has_been_checked_(false) {} - - CheckedError &operator=(const CheckedError &other) { - is_error_ = other.is_error_; - has_been_checked_ = false; - other.has_been_checked_ = true; - return *this; - } - - CheckedError(const CheckedError &other) { - *this = other; // Use assignment operator. - } - - ~CheckedError() { FLATBUFFERS_ASSERT(has_been_checked_); } - - bool Check() { - has_been_checked_ = true; - return is_error_; - } - - private: - bool is_error_; - mutable bool has_been_checked_; -}; - -// Additionally, in GCC we can get these errors statically, for additional -// assurance: -// clang-format off -#ifdef __GNUC__ -#define FLATBUFFERS_CHECKED_ERROR CheckedError \ - __attribute__((warn_unused_result)) -#else -#define FLATBUFFERS_CHECKED_ERROR CheckedError -#endif -// clang-format on - -class Parser : public ParserState { - public: - explicit Parser(const IDLOptions &options = IDLOptions()) - : current_namespace_(nullptr), - empty_namespace_(nullptr), - root_struct_def_(nullptr), - opts(options), - uses_flexbuffers_(false), - source_(nullptr), - anonymous_counter(0), - recurse_protection_counter(0) { - if (opts.force_defaults) { - builder_.ForceDefaults(true); - } - // Start out with the empty namespace being current. - empty_namespace_ = new Namespace(); - namespaces_.push_back(empty_namespace_); - current_namespace_ = empty_namespace_; - known_attributes_["deprecated"] = true; - known_attributes_["required"] = true; - known_attributes_["key"] = true; - known_attributes_["hash"] = true; - known_attributes_["id"] = true; - known_attributes_["force_align"] = true; - known_attributes_["bit_flags"] = true; - known_attributes_["original_order"] = true; - known_attributes_["nested_flatbuffer"] = true; - known_attributes_["csharp_partial"] = true; - known_attributes_["streaming"] = true; - known_attributes_["idempotent"] = true; - known_attributes_["cpp_type"] = true; - known_attributes_["cpp_ptr_type"] = true; - known_attributes_["cpp_ptr_type_get"] = true; - known_attributes_["cpp_str_type"] = true; - known_attributes_["native_inline"] = true; - known_attributes_["native_custom_alloc"] = true; - known_attributes_["native_type"] = true; - known_attributes_["native_default"] = true; - known_attributes_["flexbuffer"] = true; - known_attributes_["private"] = true; - } - - ~Parser() { - for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) { - delete *it; - } - } - - // Parse the string containing either schema or JSON data, which will - // populate the SymbolTable's or the FlatBufferBuilder above. - // include_paths is used to resolve any include statements, and typically - // should at least include the project path (where you loaded source_ from). - // include_paths must be nullptr terminated if specified. - // If include_paths is nullptr, it will attempt to load from the current - // directory. - // If the source was loaded from a file and isn't an include file, - // supply its name in source_filename. - // All paths specified in this call must be in posix format, if you accept - // paths from user input, please call PosixPath on them first. - bool Parse(const char *_source, const char **include_paths = nullptr, - const char *source_filename = nullptr); - - // Set the root type. May override the one set in the schema. - bool SetRootType(const char *name); - - // Mark all definitions as already having code generated. - void MarkGenerated(); - - // Get the files recursively included by the given file. The returned - // container will have at least the given file. - std::set GetIncludedFilesRecursive( - const std::string &file_name) const; - - // Fills builder_ with a binary version of the schema parsed. - // See reflection/reflection.fbs - void Serialize(); - - // Deserialize a schema buffer - bool Deserialize(const uint8_t *buf, const size_t size); - - // Fills internal structure as if the schema passed had been loaded by parsing - // with Parse except that included filenames will not be populated. - bool Deserialize(const reflection::Schema* schema); - - Type* DeserializeType(const reflection::Type* type); - - // Checks that the schema represented by this parser is a safe evolution - // of the schema provided. Returns non-empty error on any problems. - std::string ConformTo(const Parser &base); - - // Similar to Parse(), but now only accepts JSON to be parsed into a - // FlexBuffer. - bool ParseFlexBuffer(const char *source, const char *source_filename, - flexbuffers::Builder *builder); - - FLATBUFFERS_CHECKED_ERROR InvalidNumber(const char *number, - const std::string &msg); - - StructDef *LookupStruct(const std::string &id) const; - - std::string UnqualifiedName(std::string fullQualifiedName); - - private: - void Message(const std::string &msg); - void Warning(const std::string &msg); - FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg); - FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val); - FLATBUFFERS_CHECKED_ERROR Next(); - FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark(); - bool Is(int t) const; - bool IsIdent(const char *id) const; - FLATBUFFERS_CHECKED_ERROR Expect(int t); - std::string TokenToStringId(int t) const; - EnumDef *LookupEnum(const std::string &id); - FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id, - std::string *last); - FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type &type); - FLATBUFFERS_CHECKED_ERROR ParseType(Type &type); - FLATBUFFERS_CHECKED_ERROR AddField(StructDef &struct_def, - const std::string &name, const Type &type, - FieldDef **dest); - FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def); - FLATBUFFERS_CHECKED_ERROR ParseString(Value &val); - FLATBUFFERS_CHECKED_ERROR ParseComma(); - FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field, - size_t parent_fieldn, - const StructDef *parent_struct_def); - template - FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn, - const StructDef *struct_def, - F body); - FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def, - std::string *value, uoffset_t *ovalue); - void SerializeStruct(const StructDef &struct_def, const Value &val); - template - FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(size_t &count, F body); - FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue); - FLATBUFFERS_CHECKED_ERROR ParseNestedFlatbuffer(Value &val, FieldDef *field, - size_t fieldn, - const StructDef *parent_struct_def); - FLATBUFFERS_CHECKED_ERROR ParseMetaData(SymbolTable *attributes); - FLATBUFFERS_CHECKED_ERROR TryTypedValue(const std::string *name, int dtoken, bool check, Value &e, - BaseType req, bool *destmatch); - FLATBUFFERS_CHECKED_ERROR ParseHash(Value &e, FieldDef* field); - FLATBUFFERS_CHECKED_ERROR TokenError(); - FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e, bool check_now); - FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(Type &type, int64_t *result); - StructDef *LookupCreateStruct(const std::string &name, - bool create_if_new = true, - bool definition = false); - FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest); - FLATBUFFERS_CHECKED_ERROR ParseNamespace(); - FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name, - StructDef **dest); - FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string &name, - bool is_union, - EnumDef **dest); - FLATBUFFERS_CHECKED_ERROR ParseDecl(); - FLATBUFFERS_CHECKED_ERROR ParseService(); - FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def, - bool isextend, bool inside_oneof); - FLATBUFFERS_CHECKED_ERROR ParseProtoOption(); - FLATBUFFERS_CHECKED_ERROR ParseProtoKey(); - FLATBUFFERS_CHECKED_ERROR ParseProtoDecl(); - FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent(); - FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type); - FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue(); - FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder); - FLATBUFFERS_CHECKED_ERROR StartParseFile(const char *source, - const char *source_filename); - FLATBUFFERS_CHECKED_ERROR ParseRoot(const char *_source, - const char **include_paths, - const char *source_filename); - FLATBUFFERS_CHECKED_ERROR DoParse(const char *_source, - const char **include_paths, - const char *source_filename, - const char *include_filename); - FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector &fields, - StructDef *struct_def, - const char *suffix, - BaseType baseType); - - bool SupportsVectorOfUnions() const; - Namespace *UniqueNamespace(Namespace *ns); - - FLATBUFFERS_CHECKED_ERROR RecurseError(); - template CheckedError Recurse(F f); - - public: - SymbolTable types_; - SymbolTable structs_; - SymbolTable enums_; - SymbolTable services_; - std::vector namespaces_; - Namespace *current_namespace_; - Namespace *empty_namespace_; - std::string error_; // User readable error_ if Parse() == false - - FlatBufferBuilder builder_; // any data contained in the file - StructDef *root_struct_def_; - std::string file_identifier_; - std::string file_extension_; - - std::map included_files_; - std::map> files_included_per_file_; - std::vector native_included_files_; - - std::map known_attributes_; - - IDLOptions opts; - bool uses_flexbuffers_; - - private: - const char *source_; - - std::string file_being_parsed_; - - std::vector> field_stack_; - - int anonymous_counter; - int recurse_protection_counter; -}; - -// Utility functions for multiple generators: - -extern std::string MakeCamel(const std::string &in, bool first = true); - -// Generate text (JSON) from a given FlatBuffer, and a given Parser -// object that has been populated with the corresponding schema. -// If ident_step is 0, no indentation will be generated. Additionally, -// if it is less than 0, no linefeeds will be generated either. -// See idl_gen_text.cpp. -// strict_json adds "quotes" around field names if true. -// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8 -// byte arrays in String values), returns false. -extern bool GenerateText(const Parser &parser, - const void *flatbuffer, - std::string *text); -extern bool GenerateTextFile(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate binary files from a given FlatBuffer, and a given Parser -// object that has been populated with the corresponding schema. -// See idl_gen_general.cpp. -extern bool GenerateBinary(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a C++ header from the definitions in the Parser object. -// See idl_gen_cpp. -extern bool GenerateCPP(const Parser &parser, - const std::string &path, - const std::string &file_name); - -extern bool GenerateDart(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate JavaScript or TypeScript code from the definitions in the Parser object. -// See idl_gen_js. -extern bool GenerateJSTS(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Go files from the definitions in the Parser object. -// See idl_gen_go.cpp. -extern bool GenerateGo(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Php code from the definitions in the Parser object. -// See idl_gen_php. -extern bool GeneratePhp(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Python files from the definitions in the Parser object. -// See idl_gen_python.cpp. -extern bool GeneratePython(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Lobster files from the definitions in the Parser object. -// See idl_gen_lobster.cpp. -extern bool GenerateLobster(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Lua files from the definitions in the Parser object. -// See idl_gen_lua.cpp. -extern bool GenerateLua(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Rust files from the definitions in the Parser object. -// See idl_gen_rust.cpp. -extern bool GenerateRust(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Json schema file -// See idl_gen_json_schema.cpp. -extern bool GenerateJsonSchema(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Java/C#/.. files from the definitions in the Parser object. -// See idl_gen_general.cpp. -extern bool GenerateGeneral(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a schema file from the internal representation, useful after -// parsing a .proto schema. -extern std::string GenerateFBS(const Parser &parser, - const std::string &file_name); -extern bool GenerateFBS(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated JavaScript or TypeScript code. -// See idl_gen_js.cpp. -extern std::string JSTSMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated C++ header. -// See idl_gen_cpp.cpp. -extern std::string CPPMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Dart code -// see idl_gen_dart.cpp -extern std::string DartMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Rust code. -// See idl_gen_rust.cpp. -extern std::string RustMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Java/C#/... files. -// See idl_gen_general.cpp. -extern std::string GeneralMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated text (JSON) files. -// See idl_gen_text.cpp. -extern std::string TextMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_names); - -// Generate a make rule for the generated binary files. -// See idl_gen_general.cpp. -extern std::string BinaryMakeRule(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate GRPC Cpp interfaces. -// See idl_gen_grpc.cpp. -bool GenerateCppGRPC(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate GRPC Go interfaces. -// See idl_gen_grpc.cpp. -bool GenerateGoGRPC(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate GRPC Java classes. -// See idl_gen_grpc.cpp -bool GenerateJavaGRPC(const Parser &parser, - const std::string &path, - const std::string &file_name); - -} // namespace flatbuffers - -#endif // FLATBUFFERS_IDL_H_ diff --git a/src/internal/include/flatbuffers/minireflect.h b/src/internal/include/flatbuffers/minireflect.h deleted file mode 100644 index e3def08..0000000 --- a/src/internal/include/flatbuffers/minireflect.h +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright 2017 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. - */ - -#ifndef FLATBUFFERS_MINIREFLECT_H_ -#define FLATBUFFERS_MINIREFLECT_H_ - -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/util.h" - -namespace flatbuffers { - -// Utilities that can be used with the "mini reflection" tables present -// in generated code with --reflect-types (only types) or --reflect-names -// (also names). -// This allows basic reflection functionality such as pretty-printing -// that does not require the use of the schema parser or loading of binary -// schema files at runtime (reflection.h). - -// For any of the functions below that take `const TypeTable *`, you pass -// `FooTypeTable()` if the type of the root is `Foo`. - -// First, a generic iterator that can be used by multiple algorithms. - -struct IterationVisitor { - // These mark the scope of a table or struct. - virtual void StartSequence() {} - virtual void EndSequence() {} - // Called for each field regardless of wether it is present or not. - // If not present, val == nullptr. set_idx is the index of all set fields. - virtual void Field(size_t /*field_idx*/, size_t /*set_idx*/, - ElementaryType /*type*/, bool /*is_vector*/, - const TypeTable * /*type_table*/, const char * /*name*/, - const uint8_t * /*val*/) {} - // Called for a value that is actually present, after a field, or as part - // of a vector. - virtual void UType(uint8_t, const char *) {} - virtual void Bool(bool) {} - virtual void Char(int8_t, const char *) {} - virtual void UChar(uint8_t, const char *) {} - virtual void Short(int16_t, const char *) {} - virtual void UShort(uint16_t, const char *) {} - virtual void Int(int32_t, const char *) {} - virtual void UInt(uint32_t, const char *) {} - virtual void Long(int64_t) {} - virtual void ULong(uint64_t) {} - virtual void Float(float) {} - virtual void Double(double) {} - virtual void String(const String *) {} - virtual void Unknown(const uint8_t *) {} // From a future version. - // These mark the scope of a vector. - virtual void StartVector() {} - virtual void EndVector() {} - virtual void Element(size_t /*i*/, ElementaryType /*type*/, - const TypeTable * /*type_table*/, - const uint8_t * /*val*/) {} - virtual ~IterationVisitor() {} -}; - -inline size_t InlineSize(ElementaryType type, const TypeTable *type_table) { - switch (type) { - case ET_UTYPE: - case ET_BOOL: - case ET_CHAR: - case ET_UCHAR: return 1; - case ET_SHORT: - case ET_USHORT: return 2; - case ET_INT: - case ET_UINT: - case ET_FLOAT: - case ET_STRING: return 4; - case ET_LONG: - case ET_ULONG: - case ET_DOUBLE: return 8; - case ET_SEQUENCE: - switch (type_table->st) { - case ST_TABLE: - case ST_UNION: return 4; - case ST_STRUCT: return static_cast(type_table->values[type_table->num_elems]); - default: FLATBUFFERS_ASSERT(false); return 1; - } - default: FLATBUFFERS_ASSERT(false); return 1; - } -} - -inline int64_t LookupEnum(int64_t enum_val, const int64_t *values, - size_t num_values) { - if (!values) return enum_val; - for (size_t i = 0; i < num_values; i++) { - if (enum_val == values[i]) return static_cast(i); - } - return -1; // Unknown enum value. -} - -template const char *EnumName(T tval, const TypeTable *type_table) { - if (!type_table || !type_table->names) return nullptr; - auto i = LookupEnum(static_cast(tval), type_table->values, - type_table->num_elems); - if (i >= 0 && i < static_cast(type_table->num_elems)) { - return type_table->names[i]; - } - return nullptr; -} - -void IterateObject(const uint8_t *obj, const TypeTable *type_table, - IterationVisitor *visitor); - -inline void IterateValue(ElementaryType type, const uint8_t *val, - const TypeTable *type_table, const uint8_t *prev_val, - soffset_t vector_index, IterationVisitor *visitor) { - switch (type) { - case ET_UTYPE: { - auto tval = *reinterpret_cast(val); - visitor->UType(tval, EnumName(tval, type_table)); - break; - } - case ET_BOOL: { - visitor->Bool(*reinterpret_cast(val) != 0); - break; - } - case ET_CHAR: { - auto tval = *reinterpret_cast(val); - visitor->Char(tval, EnumName(tval, type_table)); - break; - } - case ET_UCHAR: { - auto tval = *reinterpret_cast(val); - visitor->UChar(tval, EnumName(tval, type_table)); - break; - } - case ET_SHORT: { - auto tval = *reinterpret_cast(val); - visitor->Short(tval, EnumName(tval, type_table)); - break; - } - case ET_USHORT: { - auto tval = *reinterpret_cast(val); - visitor->UShort(tval, EnumName(tval, type_table)); - break; - } - case ET_INT: { - auto tval = *reinterpret_cast(val); - visitor->Int(tval, EnumName(tval, type_table)); - break; - } - case ET_UINT: { - auto tval = *reinterpret_cast(val); - visitor->UInt(tval, EnumName(tval, type_table)); - break; - } - case ET_LONG: { - visitor->Long(*reinterpret_cast(val)); - break; - } - case ET_ULONG: { - visitor->ULong(*reinterpret_cast(val)); - break; - } - case ET_FLOAT: { - visitor->Float(*reinterpret_cast(val)); - break; - } - case ET_DOUBLE: { - visitor->Double(*reinterpret_cast(val)); - break; - } - case ET_STRING: { - val += ReadScalar(val); - visitor->String(reinterpret_cast(val)); - break; - } - case ET_SEQUENCE: { - switch (type_table->st) { - case ST_TABLE: - val += ReadScalar(val); - IterateObject(val, type_table, visitor); - break; - case ST_STRUCT: IterateObject(val, type_table, visitor); break; - case ST_UNION: { - val += ReadScalar(val); - FLATBUFFERS_ASSERT(prev_val); - auto union_type = *prev_val; // Always a uint8_t. - if (vector_index >= 0) { - auto type_vec = reinterpret_cast *>(prev_val); - union_type = type_vec->Get(static_cast(vector_index)); - } - auto type_code_idx = - LookupEnum(union_type, type_table->values, type_table->num_elems); - if (type_code_idx >= 0 && - type_code_idx < static_cast(type_table->num_elems)) { - auto type_code = type_table->type_codes[type_code_idx]; - switch (type_code.base_type) { - case ET_SEQUENCE: { - auto ref = type_table->type_refs[type_code.sequence_ref](); - IterateObject(val, ref, visitor); - break; - } - case ET_STRING: - visitor->String(reinterpret_cast(val)); - break; - default: visitor->Unknown(val); - } - } else { - visitor->Unknown(val); - } - break; - } - case ST_ENUM: FLATBUFFERS_ASSERT(false); break; - } - break; - } - default: { - visitor->Unknown(val); - break; - } - } -} - -inline void IterateObject(const uint8_t *obj, const TypeTable *type_table, - IterationVisitor *visitor) { - visitor->StartSequence(); - const uint8_t *prev_val = nullptr; - size_t set_idx = 0; - for (size_t i = 0; i < type_table->num_elems; i++) { - auto type_code = type_table->type_codes[i]; - auto type = static_cast(type_code.base_type); - auto is_vector = type_code.is_vector != 0; - auto ref_idx = type_code.sequence_ref; - const TypeTable *ref = nullptr; - if (ref_idx >= 0) { ref = type_table->type_refs[ref_idx](); } - auto name = type_table->names ? type_table->names[i] : nullptr; - const uint8_t *val = nullptr; - if (type_table->st == ST_TABLE) { - val = reinterpret_cast(obj)->GetAddressOf( - FieldIndexToOffset(static_cast(i))); - } else { - val = obj + type_table->values[i]; - } - visitor->Field(i, set_idx, type, is_vector, ref, name, val); - if (val) { - set_idx++; - if (is_vector) { - val += ReadScalar(val); - auto vec = reinterpret_cast *>(val); - visitor->StartVector(); - auto elem_ptr = vec->Data(); - for (size_t j = 0; j < vec->size(); j++) { - visitor->Element(j, type, ref, elem_ptr); - IterateValue(type, elem_ptr, ref, prev_val, static_cast(j), - visitor); - elem_ptr += InlineSize(type, ref); - } - visitor->EndVector(); - } else { - IterateValue(type, val, ref, prev_val, -1, visitor); - } - } - prev_val = val; - } - visitor->EndSequence(); -} - -inline void IterateFlatBuffer(const uint8_t *buffer, - const TypeTable *type_table, - IterationVisitor *callback) { - IterateObject(GetRoot(buffer), type_table, callback); -} - -// Outputting a Flatbuffer to a string. Tries to conform as close to JSON / -// the output generated by idl_gen_text.cpp. - -struct ToStringVisitor : public IterationVisitor { - std::string s; - std::string d; - bool q; - std::string in; - size_t indent_level; - ToStringVisitor(std::string delimiter, bool quotes, std::string indent) - : d(delimiter), q(quotes), in(indent), indent_level(0) {} - ToStringVisitor(std::string delimiter) - : d(delimiter), q(false), in(""), indent_level(0) {} - - void append_indent() { - for (size_t i = 0; i < indent_level; i++) { s += in; } - } - - void StartSequence() { - s += "{"; - s += d; - indent_level++; - } - void EndSequence() { - s += d; - indent_level--; - append_indent(); - s += "}"; - } - void Field(size_t /*field_idx*/, size_t set_idx, ElementaryType /*type*/, - bool /*is_vector*/, const TypeTable * /*type_table*/, - const char *name, const uint8_t *val) { - if (!val) return; - if (set_idx) { - s += ","; - s += d; - } - append_indent(); - if (name) { - if (q) s += "\""; - s += name; - if (q) s += "\""; - s += ": "; - } - } - template void Named(T x, const char *name) { - if (name) { - if (q) s += "\""; - s += name; - if (q) s += "\""; - } else { - s += NumToString(x); - } - } - void UType(uint8_t x, const char *name) { Named(x, name); } - void Bool(bool x) { s += x ? "true" : "false"; } - void Char(int8_t x, const char *name) { Named(x, name); } - void UChar(uint8_t x, const char *name) { Named(x, name); } - void Short(int16_t x, const char *name) { Named(x, name); } - void UShort(uint16_t x, const char *name) { Named(x, name); } - void Int(int32_t x, const char *name) { Named(x, name); } - void UInt(uint32_t x, const char *name) { Named(x, name); } - void Long(int64_t x) { s += NumToString(x); } - void ULong(uint64_t x) { s += NumToString(x); } - void Float(float x) { s += NumToString(x); } - void Double(double x) { s += NumToString(x); } - void String(const struct String *str) { - EscapeString(str->c_str(), str->size(), &s, true, false); - } - void Unknown(const uint8_t *) { s += "(?)"; } - void StartVector() { - s += "["; - s += d; - indent_level++; - append_indent(); - } - void EndVector() { - s += d; - indent_level--; - append_indent(); - s += "]"; - } - void Element(size_t i, ElementaryType /*type*/, - const TypeTable * /*type_table*/, const uint8_t * /*val*/) { - if (i) { - s += ","; - s += d; - append_indent(); - } - } -}; - -inline std::string FlatBufferToString(const uint8_t *buffer, - const TypeTable *type_table, - bool multi_line = false) { - ToStringVisitor tostring_visitor(multi_line ? "\n" : " "); - IterateFlatBuffer(buffer, type_table, &tostring_visitor); - return tostring_visitor.s; -} - -} // namespace flatbuffers - -#endif // FLATBUFFERS_MINIREFLECT_H_ diff --git a/src/internal/include/flatbuffers/reflection.h b/src/internal/include/flatbuffers/reflection.h deleted file mode 100644 index 580ae62..0000000 --- a/src/internal/include/flatbuffers/reflection.h +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright 2015 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. - */ - -#ifndef FLATBUFFERS_REFLECTION_H_ -#define FLATBUFFERS_REFLECTION_H_ - -// This is somewhat of a circular dependency because flatc (and thus this -// file) is needed to generate this header in the first place. -// Should normally not be a problem since it can be generated by the -// previous version of flatc whenever this code needs to change. -// See reflection/generate_code.sh -#include "flatbuffers/reflection_generated.h" - -// Helper functionality for reflection. - -namespace flatbuffers { - -// ------------------------- GETTERS ------------------------- - -inline bool IsScalar(reflection::BaseType t) { - return t >= reflection::UType && t <= reflection::Double; -} -inline bool IsInteger(reflection::BaseType t) { - return t >= reflection::UType && t <= reflection::ULong; -} -inline bool IsFloat(reflection::BaseType t) { - return t == reflection::Float || t == reflection::Double; -} -inline bool IsLong(reflection::BaseType t) { - return t == reflection::Long || t == reflection::ULong; -} - -// Size of a basic type, don't use with structs. -inline size_t GetTypeSize(reflection::BaseType base_type) { - // This needs to correspond to the BaseType enum. - static size_t sizes[] = { 0, 1, 1, 1, 1, 2, 2, 4, 4, 8, 8, 4, 8, 4, 4, 4, 4 }; - return sizes[base_type]; -} - -// Same as above, but now correctly returns the size of a struct if -// the field (or vector element) is a struct. -inline size_t GetTypeSizeInline(reflection::BaseType base_type, int type_index, - const reflection::Schema &schema) { - if (base_type == reflection::Obj && - schema.objects()->Get(type_index)->is_struct()) { - return schema.objects()->Get(type_index)->bytesize(); - } else { - return GetTypeSize(base_type); - } -} - -// Get the root, regardless of what type it is. -inline Table *GetAnyRoot(uint8_t *flatbuf) { - return GetMutableRoot
(flatbuf); -} -inline const Table *GetAnyRoot(const uint8_t *flatbuf) { - return GetRoot
(flatbuf); -} - -// Get a field's default, if you know it's an integer, and its exact type. -template T GetFieldDefaultI(const reflection::Field &field) { - FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); - return static_cast(field.default_integer()); -} - -// Get a field's default, if you know it's floating point and its exact type. -template T GetFieldDefaultF(const reflection::Field &field) { - FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); - return static_cast(field.default_real()); -} - -// Get a field, if you know it's an integer, and its exact type. -template -T GetFieldI(const Table &table, const reflection::Field &field) { - FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); - return table.GetField(field.offset(), - static_cast(field.default_integer())); -} - -// Get a field, if you know it's floating point and its exact type. -template -T GetFieldF(const Table &table, const reflection::Field &field) { - FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); - return table.GetField(field.offset(), - static_cast(field.default_real())); -} - -// Get a field, if you know it's a string. -inline const String *GetFieldS(const Table &table, - const reflection::Field &field) { - FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::String); - return table.GetPointer(field.offset()); -} - -// Get a field, if you know it's a vector. -template -Vector *GetFieldV(const Table &table, const reflection::Field &field) { - FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Vector && - sizeof(T) == GetTypeSize(field.type()->element())); - return table.GetPointer *>(field.offset()); -} - -// Get a field, if you know it's a vector, generically. -// To actually access elements, use the return value together with -// field.type()->element() in any of GetAnyVectorElemI below etc. -inline VectorOfAny *GetFieldAnyV(const Table &table, - const reflection::Field &field) { - return table.GetPointer(field.offset()); -} - -// Get a field, if you know it's a table. -inline Table *GetFieldT(const Table &table, const reflection::Field &field) { - FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj || - field.type()->base_type() == reflection::Union); - return table.GetPointer
(field.offset()); -} - -// Get a field, if you know it's a struct. -inline const Struct *GetFieldStruct(const Table &table, - const reflection::Field &field) { - // TODO: This does NOT check if the field is a table or struct, but we'd need - // access to the schema to check the is_struct flag. - FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj); - return table.GetStruct(field.offset()); -} - -// Get a structure's field, if you know it's a struct. -inline const Struct *GetFieldStruct(const Struct &structure, - const reflection::Field &field) { - FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj); - return structure.GetStruct(field.offset()); -} - -// Raw helper functions used below: get any value in memory as a 64bit int, a -// double or a string. -// All scalars get static_cast to an int64_t, strings use strtoull, every other -// data type returns 0. -int64_t GetAnyValueI(reflection::BaseType type, const uint8_t *data); -// All scalars static cast to double, strings use strtod, every other data -// type is 0.0. -double GetAnyValueF(reflection::BaseType type, const uint8_t *data); -// All scalars converted using stringstream, strings as-is, and all other -// data types provide some level of debug-pretty-printing. -std::string GetAnyValueS(reflection::BaseType type, const uint8_t *data, - const reflection::Schema *schema, int type_index); - -// Get any table field as a 64bit int, regardless of what type it is. -inline int64_t GetAnyFieldI(const Table &table, - const reflection::Field &field) { - auto field_ptr = table.GetAddressOf(field.offset()); - return field_ptr ? GetAnyValueI(field.type()->base_type(), field_ptr) - : field.default_integer(); -} - -// Get any table field as a double, regardless of what type it is. -inline double GetAnyFieldF(const Table &table, const reflection::Field &field) { - auto field_ptr = table.GetAddressOf(field.offset()); - return field_ptr ? GetAnyValueF(field.type()->base_type(), field_ptr) - : field.default_real(); -} - -// Get any table field as a string, regardless of what type it is. -// You may pass nullptr for the schema if you don't care to have fields that -// are of table type pretty-printed. -inline std::string GetAnyFieldS(const Table &table, - const reflection::Field &field, - const reflection::Schema *schema) { - auto field_ptr = table.GetAddressOf(field.offset()); - return field_ptr ? GetAnyValueS(field.type()->base_type(), field_ptr, schema, - field.type()->index()) - : ""; -} - -// Get any struct field as a 64bit int, regardless of what type it is. -inline int64_t GetAnyFieldI(const Struct &st, const reflection::Field &field) { - return GetAnyValueI(field.type()->base_type(), - st.GetAddressOf(field.offset())); -} - -// Get any struct field as a double, regardless of what type it is. -inline double GetAnyFieldF(const Struct &st, const reflection::Field &field) { - return GetAnyValueF(field.type()->base_type(), - st.GetAddressOf(field.offset())); -} - -// Get any struct field as a string, regardless of what type it is. -inline std::string GetAnyFieldS(const Struct &st, - const reflection::Field &field) { - return GetAnyValueS(field.type()->base_type(), - st.GetAddressOf(field.offset()), nullptr, -1); -} - -// Get any vector element as a 64bit int, regardless of what type it is. -inline int64_t GetAnyVectorElemI(const VectorOfAny *vec, - reflection::BaseType elem_type, size_t i) { - return GetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i); -} - -// Get any vector element as a double, regardless of what type it is. -inline double GetAnyVectorElemF(const VectorOfAny *vec, - reflection::BaseType elem_type, size_t i) { - return GetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i); -} - -// Get any vector element as a string, regardless of what type it is. -inline std::string GetAnyVectorElemS(const VectorOfAny *vec, - reflection::BaseType elem_type, size_t i) { - return GetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i, - nullptr, -1); -} - -// Get a vector element that's a table/string/vector from a generic vector. -// Pass Table/String/VectorOfAny as template parameter. -// Warning: does no typechecking. -template -T *GetAnyVectorElemPointer(const VectorOfAny *vec, size_t i) { - auto elem_ptr = vec->Data() + sizeof(uoffset_t) * i; - return reinterpret_cast(elem_ptr + ReadScalar(elem_ptr)); -} - -// Get the inline-address of a vector element. Useful for Structs (pass Struct -// as template arg), or being able to address a range of scalars in-line. -// Get elem_size from GetTypeSizeInline(). -// Note: little-endian data on all platforms, use EndianScalar() instead of -// raw pointer access with scalars). -template -T *GetAnyVectorElemAddressOf(const VectorOfAny *vec, size_t i, - size_t elem_size) { - return reinterpret_cast(vec->Data() + elem_size * i); -} - -// Similarly, for elements of tables. -template -T *GetAnyFieldAddressOf(const Table &table, const reflection::Field &field) { - return reinterpret_cast(table.GetAddressOf(field.offset())); -} - -// Similarly, for elements of structs. -template -T *GetAnyFieldAddressOf(const Struct &st, const reflection::Field &field) { - return reinterpret_cast(st.GetAddressOf(field.offset())); -} - -// ------------------------- SETTERS ------------------------- - -// Set any scalar field, if you know its exact type. -template -bool SetField(Table *table, const reflection::Field &field, T val) { - reflection::BaseType type = field.type()->base_type(); - if (!IsScalar(type)) { return false; } - FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(type)); - T def; - if (IsInteger(type)) { - def = GetFieldDefaultI(field); - } else { - FLATBUFFERS_ASSERT(IsFloat(type)); - def = GetFieldDefaultF(field); - } - return table->SetField(field.offset(), val, def); -} - -// Raw helper functions used below: set any value in memory as a 64bit int, a -// double or a string. -// These work for all scalar values, but do nothing for other data types. -// To set a string, see SetString below. -void SetAnyValueI(reflection::BaseType type, uint8_t *data, int64_t val); -void SetAnyValueF(reflection::BaseType type, uint8_t *data, double val); -void SetAnyValueS(reflection::BaseType type, uint8_t *data, const char *val); - -// Set any table field as a 64bit int, regardless of type what it is. -inline bool SetAnyFieldI(Table *table, const reflection::Field &field, - int64_t val) { - auto field_ptr = table->GetAddressOf(field.offset()); - if (!field_ptr) return val == GetFieldDefaultI(field); - SetAnyValueI(field.type()->base_type(), field_ptr, val); - return true; -} - -// Set any table field as a double, regardless of what type it is. -inline bool SetAnyFieldF(Table *table, const reflection::Field &field, - double val) { - auto field_ptr = table->GetAddressOf(field.offset()); - if (!field_ptr) return val == GetFieldDefaultF(field); - SetAnyValueF(field.type()->base_type(), field_ptr, val); - return true; -} - -// Set any table field as a string, regardless of what type it is. -inline bool SetAnyFieldS(Table *table, const reflection::Field &field, - const char *val) { - auto field_ptr = table->GetAddressOf(field.offset()); - if (!field_ptr) return false; - SetAnyValueS(field.type()->base_type(), field_ptr, val); - return true; -} - -// Set any struct field as a 64bit int, regardless of type what it is. -inline void SetAnyFieldI(Struct *st, const reflection::Field &field, - int64_t val) { - SetAnyValueI(field.type()->base_type(), st->GetAddressOf(field.offset()), - val); -} - -// Set any struct field as a double, regardless of type what it is. -inline void SetAnyFieldF(Struct *st, const reflection::Field &field, - double val) { - SetAnyValueF(field.type()->base_type(), st->GetAddressOf(field.offset()), - val); -} - -// Set any struct field as a string, regardless of type what it is. -inline void SetAnyFieldS(Struct *st, const reflection::Field &field, - const char *val) { - SetAnyValueS(field.type()->base_type(), st->GetAddressOf(field.offset()), - val); -} - -// Set any vector element as a 64bit int, regardless of type what it is. -inline void SetAnyVectorElemI(VectorOfAny *vec, reflection::BaseType elem_type, - size_t i, int64_t val) { - SetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val); -} - -// Set any vector element as a double, regardless of type what it is. -inline void SetAnyVectorElemF(VectorOfAny *vec, reflection::BaseType elem_type, - size_t i, double val) { - SetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val); -} - -// Set any vector element as a string, regardless of type what it is. -inline void SetAnyVectorElemS(VectorOfAny *vec, reflection::BaseType elem_type, - size_t i, const char *val) { - SetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val); -} - -// ------------------------- RESIZING SETTERS ------------------------- - -// "smart" pointer for use with resizing vectors: turns a pointer inside -// a vector into a relative offset, such that it is not affected by resizes. -template class pointer_inside_vector { - public: - pointer_inside_vector(T *ptr, std::vector &vec) - : offset_(reinterpret_cast(ptr) - - reinterpret_cast(flatbuffers::vector_data(vec))), - vec_(vec) {} - - T *operator*() const { - return reinterpret_cast( - reinterpret_cast(flatbuffers::vector_data(vec_)) + offset_); - } - T *operator->() const { return operator*(); } - void operator=(const pointer_inside_vector &piv); - - private: - size_t offset_; - std::vector &vec_; -}; - -// Helper to create the above easily without specifying template args. -template -pointer_inside_vector piv(T *ptr, std::vector &vec) { - return pointer_inside_vector(ptr, vec); -} - -inline const char *UnionTypeFieldSuffix() { return "_type"; } - -// Helper to figure out the actual table type a union refers to. -inline const reflection::Object &GetUnionType( - const reflection::Schema &schema, const reflection::Object &parent, - const reflection::Field &unionfield, const Table &table) { - auto enumdef = schema.enums()->Get(unionfield.type()->index()); - // TODO: this is clumsy and slow, but no other way to find it? - auto type_field = parent.fields()->LookupByKey( - (unionfield.name()->str() + UnionTypeFieldSuffix()).c_str()); - FLATBUFFERS_ASSERT(type_field); - auto union_type = GetFieldI(table, *type_field); - auto enumval = enumdef->values()->LookupByKey(union_type); - return *enumval->object(); -} - -// Changes the contents of a string inside a FlatBuffer. FlatBuffer must -// live inside a std::vector so we can resize the buffer if needed. -// "str" must live inside "flatbuf" and may be invalidated after this call. -// If your FlatBuffer's root table is not the schema's root table, you should -// pass in your root_table type as well. -void SetString(const reflection::Schema &schema, const std::string &val, - const String *str, std::vector *flatbuf, - const reflection::Object *root_table = nullptr); - -// Resizes a flatbuffers::Vector inside a FlatBuffer. FlatBuffer must -// live inside a std::vector so we can resize the buffer if needed. -// "vec" must live inside "flatbuf" and may be invalidated after this call. -// If your FlatBuffer's root table is not the schema's root table, you should -// pass in your root_table type as well. -uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize, - const VectorOfAny *vec, uoffset_t num_elems, - uoffset_t elem_size, std::vector *flatbuf, - const reflection::Object *root_table = nullptr); - -template -void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val, - const Vector *vec, std::vector *flatbuf, - const reflection::Object *root_table = nullptr) { - auto delta_elem = static_cast(newsize) - static_cast(vec->size()); - auto newelems = ResizeAnyVector( - schema, newsize, reinterpret_cast(vec), vec->size(), - static_cast(sizeof(T)), flatbuf, root_table); - // Set new elements to "val". - for (int i = 0; i < delta_elem; i++) { - auto loc = newelems + i * sizeof(T); - auto is_scalar = flatbuffers::is_scalar::value; - if (is_scalar) { - WriteScalar(loc, val); - } else { // struct - *reinterpret_cast(loc) = val; - } - } -} - -// Adds any new data (in the form of a new FlatBuffer) to an existing -// FlatBuffer. This can be used when any of the above methods are not -// sufficient, in particular for adding new tables and new fields. -// This is potentially slightly less efficient than a FlatBuffer constructed -// in one piece, since the new FlatBuffer doesn't share any vtables with the -// existing one. -// The return value can now be set using Vector::MutateOffset or SetFieldT -// below. -const uint8_t *AddFlatBuffer(std::vector &flatbuf, - const uint8_t *newbuf, size_t newlen); - -inline bool SetFieldT(Table *table, const reflection::Field &field, - const uint8_t *val) { - FLATBUFFERS_ASSERT(sizeof(uoffset_t) == - GetTypeSize(field.type()->base_type())); - return table->SetPointer(field.offset(), val); -} - -// ------------------------- COPYING ------------------------- - -// Generic copying of tables from a FlatBuffer into a FlatBuffer builder. -// Can be used to do any kind of merging/selecting you may want to do out -// of existing buffers. Also useful to reconstruct a whole buffer if the -// above resizing functionality has introduced garbage in a buffer you want -// to remove. -// Note: this does not deal with DAGs correctly. If the table passed forms a -// DAG, the copy will be a tree instead (with duplicates). Strings can be -// shared however, by passing true for use_string_pooling. - -Offset CopyTable(FlatBufferBuilder &fbb, - const reflection::Schema &schema, - const reflection::Object &objectdef, - const Table &table, - bool use_string_pooling = false); - -// Verifies the provided flatbuffer using reflection. -// root should point to the root type for this flatbuffer. -// buf should point to the start of flatbuffer data. -// length specifies the size of the flatbuffer data. -bool Verify(const reflection::Schema &schema, const reflection::Object &root, - const uint8_t *buf, size_t length); - -} // namespace flatbuffers - -#endif // FLATBUFFERS_REFLECTION_H_ diff --git a/src/internal/include/flatbuffers/reflection_generated.h b/src/internal/include/flatbuffers/reflection_generated.h deleted file mode 100644 index fc72059..0000000 --- a/src/internal/include/flatbuffers/reflection_generated.h +++ /dev/null @@ -1,1182 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - - -#ifndef FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ -#define FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ - -#include "flatbuffers/flatbuffers.h" - -namespace reflection { - -struct Type; - -struct KeyValue; - -struct EnumVal; - -struct Enum; - -struct Field; - -struct Object; - -struct RPCCall; - -struct Service; - -struct Schema; - -enum BaseType { - None = 0, - UType = 1, - Bool = 2, - Byte = 3, - UByte = 4, - Short = 5, - UShort = 6, - Int = 7, - UInt = 8, - Long = 9, - ULong = 10, - Float = 11, - Double = 12, - String = 13, - Vector = 14, - Obj = 15, - Union = 16 -}; - -inline const BaseType (&EnumValuesBaseType())[17] { - static const BaseType values[] = { - None, - UType, - Bool, - Byte, - UByte, - Short, - UShort, - Int, - UInt, - Long, - ULong, - Float, - Double, - String, - Vector, - Obj, - Union - }; - return values; -} - -inline const char * const *EnumNamesBaseType() { - static const char * const names[] = { - "None", - "UType", - "Bool", - "Byte", - "UByte", - "Short", - "UShort", - "Int", - "UInt", - "Long", - "ULong", - "Float", - "Double", - "String", - "Vector", - "Obj", - "Union", - nullptr - }; - return names; -} - -inline const char *EnumNameBaseType(BaseType e) { - if (e < None || e > Union) return ""; - const size_t index = static_cast(e); - return EnumNamesBaseType()[index]; -} - -struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_BASE_TYPE = 4, - VT_ELEMENT = 6, - VT_INDEX = 8 - }; - BaseType base_type() const { - return static_cast(GetField(VT_BASE_TYPE, 0)); - } - BaseType element() const { - return static_cast(GetField(VT_ELEMENT, 0)); - } - int32_t index() const { - return GetField(VT_INDEX, -1); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_BASE_TYPE) && - VerifyField(verifier, VT_ELEMENT) && - VerifyField(verifier, VT_INDEX) && - verifier.EndTable(); - } -}; - -struct TypeBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_base_type(BaseType base_type) { - fbb_.AddElement(Type::VT_BASE_TYPE, static_cast(base_type), 0); - } - void add_element(BaseType element) { - fbb_.AddElement(Type::VT_ELEMENT, static_cast(element), 0); - } - void add_index(int32_t index) { - fbb_.AddElement(Type::VT_INDEX, index, -1); - } - explicit TypeBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - TypeBuilder &operator=(const TypeBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateType( - flatbuffers::FlatBufferBuilder &_fbb, - BaseType base_type = None, - BaseType element = None, - int32_t index = -1) { - TypeBuilder builder_(_fbb); - builder_.add_index(index); - builder_.add_element(element); - builder_.add_base_type(base_type); - return builder_.Finish(); -} - -struct KeyValue FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_KEY = 4, - VT_VALUE = 6 - }; - const flatbuffers::String *key() const { - return GetPointer(VT_KEY); - } - bool KeyCompareLessThan(const KeyValue *o) const { - return *key() < *o->key(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(key()->c_str(), val); - } - const flatbuffers::String *value() const { - return GetPointer(VT_VALUE); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_KEY) && - verifier.VerifyString(key()) && - VerifyOffset(verifier, VT_VALUE) && - verifier.VerifyString(value()) && - verifier.EndTable(); - } -}; - -struct KeyValueBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_key(flatbuffers::Offset key) { - fbb_.AddOffset(KeyValue::VT_KEY, key); - } - void add_value(flatbuffers::Offset value) { - fbb_.AddOffset(KeyValue::VT_VALUE, value); - } - explicit KeyValueBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - KeyValueBuilder &operator=(const KeyValueBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, KeyValue::VT_KEY); - return o; - } -}; - -inline flatbuffers::Offset CreateKeyValue( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset key = 0, - flatbuffers::Offset value = 0) { - KeyValueBuilder builder_(_fbb); - builder_.add_value(value); - builder_.add_key(key); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateKeyValueDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *key = nullptr, - const char *value = nullptr) { - auto key__ = key ? _fbb.CreateString(key) : 0; - auto value__ = value ? _fbb.CreateString(value) : 0; - return reflection::CreateKeyValue( - _fbb, - key__, - value__); -} - -struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_VALUE = 6, - VT_OBJECT = 8, - VT_UNION_TYPE = 10, - VT_DOCUMENTATION = 12 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - int64_t value() const { - return GetField(VT_VALUE, 0); - } - bool KeyCompareLessThan(const EnumVal *o) const { - return value() < o->value(); - } - int KeyCompareWithValue(int64_t val) const { - return static_cast(value() > val) - static_cast(value() < val); - } - const Object *object() const { - return GetPointer(VT_OBJECT); - } - const Type *union_type() const { - return GetPointer(VT_UNION_TYPE); - } - const flatbuffers::Vector> *documentation() const { - return GetPointer> *>(VT_DOCUMENTATION); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyField(verifier, VT_VALUE) && - VerifyOffset(verifier, VT_OBJECT) && - verifier.VerifyTable(object()) && - VerifyOffset(verifier, VT_UNION_TYPE) && - verifier.VerifyTable(union_type()) && - VerifyOffset(verifier, VT_DOCUMENTATION) && - verifier.VerifyVector(documentation()) && - verifier.VerifyVectorOfStrings(documentation()) && - verifier.EndTable(); - } -}; - -struct EnumValBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(EnumVal::VT_NAME, name); - } - void add_value(int64_t value) { - fbb_.AddElement(EnumVal::VT_VALUE, value, 0); - } - void add_object(flatbuffers::Offset object) { - fbb_.AddOffset(EnumVal::VT_OBJECT, object); - } - void add_union_type(flatbuffers::Offset union_type) { - fbb_.AddOffset(EnumVal::VT_UNION_TYPE, union_type); - } - void add_documentation(flatbuffers::Offset>> documentation) { - fbb_.AddOffset(EnumVal::VT_DOCUMENTATION, documentation); - } - explicit EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - EnumValBuilder &operator=(const EnumValBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, EnumVal::VT_NAME); - return o; - } -}; - -inline flatbuffers::Offset CreateEnumVal( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - int64_t value = 0, - flatbuffers::Offset object = 0, - flatbuffers::Offset union_type = 0, - flatbuffers::Offset>> documentation = 0) { - EnumValBuilder builder_(_fbb); - builder_.add_value(value); - builder_.add_documentation(documentation); - builder_.add_union_type(union_type); - builder_.add_object(object); - builder_.add_name(name); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateEnumValDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - int64_t value = 0, - flatbuffers::Offset object = 0, - flatbuffers::Offset union_type = 0, - const std::vector> *documentation = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; - return reflection::CreateEnumVal( - _fbb, - name__, - value, - object, - union_type, - documentation__); -} - -struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_VALUES = 6, - VT_IS_UNION = 8, - VT_UNDERLYING_TYPE = 10, - VT_ATTRIBUTES = 12, - VT_DOCUMENTATION = 14 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - bool KeyCompareLessThan(const Enum *o) const { - return *name() < *o->name(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(name()->c_str(), val); - } - const flatbuffers::Vector> *values() const { - return GetPointer> *>(VT_VALUES); - } - bool is_union() const { - return GetField(VT_IS_UNION, 0) != 0; - } - const Type *underlying_type() const { - return GetPointer(VT_UNDERLYING_TYPE); - } - const flatbuffers::Vector> *attributes() const { - return GetPointer> *>(VT_ATTRIBUTES); - } - const flatbuffers::Vector> *documentation() const { - return GetPointer> *>(VT_DOCUMENTATION); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffsetRequired(verifier, VT_VALUES) && - verifier.VerifyVector(values()) && - verifier.VerifyVectorOfTables(values()) && - VerifyField(verifier, VT_IS_UNION) && - VerifyOffsetRequired(verifier, VT_UNDERLYING_TYPE) && - verifier.VerifyTable(underlying_type()) && - VerifyOffset(verifier, VT_ATTRIBUTES) && - verifier.VerifyVector(attributes()) && - verifier.VerifyVectorOfTables(attributes()) && - VerifyOffset(verifier, VT_DOCUMENTATION) && - verifier.VerifyVector(documentation()) && - verifier.VerifyVectorOfStrings(documentation()) && - verifier.EndTable(); - } -}; - -struct EnumBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(Enum::VT_NAME, name); - } - void add_values(flatbuffers::Offset>> values) { - fbb_.AddOffset(Enum::VT_VALUES, values); - } - void add_is_union(bool is_union) { - fbb_.AddElement(Enum::VT_IS_UNION, static_cast(is_union), 0); - } - void add_underlying_type(flatbuffers::Offset underlying_type) { - fbb_.AddOffset(Enum::VT_UNDERLYING_TYPE, underlying_type); - } - void add_attributes(flatbuffers::Offset>> attributes) { - fbb_.AddOffset(Enum::VT_ATTRIBUTES, attributes); - } - void add_documentation(flatbuffers::Offset>> documentation) { - fbb_.AddOffset(Enum::VT_DOCUMENTATION, documentation); - } - explicit EnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - EnumBuilder &operator=(const EnumBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, Enum::VT_NAME); - fbb_.Required(o, Enum::VT_VALUES); - fbb_.Required(o, Enum::VT_UNDERLYING_TYPE); - return o; - } -}; - -inline flatbuffers::Offset CreateEnum( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - flatbuffers::Offset>> values = 0, - bool is_union = false, - flatbuffers::Offset underlying_type = 0, - flatbuffers::Offset>> attributes = 0, - flatbuffers::Offset>> documentation = 0) { - EnumBuilder builder_(_fbb); - builder_.add_documentation(documentation); - builder_.add_attributes(attributes); - builder_.add_underlying_type(underlying_type); - builder_.add_values(values); - builder_.add_name(name); - builder_.add_is_union(is_union); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateEnumDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - const std::vector> *values = nullptr, - bool is_union = false, - flatbuffers::Offset underlying_type = 0, - const std::vector> *attributes = nullptr, - const std::vector> *documentation = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto values__ = values ? _fbb.CreateVector>(*values) : 0; - auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; - auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; - return reflection::CreateEnum( - _fbb, - name__, - values__, - is_union, - underlying_type, - attributes__, - documentation__); -} - -struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_TYPE = 6, - VT_ID = 8, - VT_OFFSET = 10, - VT_DEFAULT_INTEGER = 12, - VT_DEFAULT_REAL = 14, - VT_DEPRECATED = 16, - VT_REQUIRED = 18, - VT_KEY = 20, - VT_ATTRIBUTES = 22, - VT_DOCUMENTATION = 24 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - bool KeyCompareLessThan(const Field *o) const { - return *name() < *o->name(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(name()->c_str(), val); - } - const Type *type() const { - return GetPointer(VT_TYPE); - } - uint16_t id() const { - return GetField(VT_ID, 0); - } - uint16_t offset() const { - return GetField(VT_OFFSET, 0); - } - int64_t default_integer() const { - return GetField(VT_DEFAULT_INTEGER, 0); - } - double default_real() const { - return GetField(VT_DEFAULT_REAL, 0.0); - } - bool deprecated() const { - return GetField(VT_DEPRECATED, 0) != 0; - } - bool required() const { - return GetField(VT_REQUIRED, 0) != 0; - } - bool key() const { - return GetField(VT_KEY, 0) != 0; - } - const flatbuffers::Vector> *attributes() const { - return GetPointer> *>(VT_ATTRIBUTES); - } - const flatbuffers::Vector> *documentation() const { - return GetPointer> *>(VT_DOCUMENTATION); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffsetRequired(verifier, VT_TYPE) && - verifier.VerifyTable(type()) && - VerifyField(verifier, VT_ID) && - VerifyField(verifier, VT_OFFSET) && - VerifyField(verifier, VT_DEFAULT_INTEGER) && - VerifyField(verifier, VT_DEFAULT_REAL) && - VerifyField(verifier, VT_DEPRECATED) && - VerifyField(verifier, VT_REQUIRED) && - VerifyField(verifier, VT_KEY) && - VerifyOffset(verifier, VT_ATTRIBUTES) && - verifier.VerifyVector(attributes()) && - verifier.VerifyVectorOfTables(attributes()) && - VerifyOffset(verifier, VT_DOCUMENTATION) && - verifier.VerifyVector(documentation()) && - verifier.VerifyVectorOfStrings(documentation()) && - verifier.EndTable(); - } -}; - -struct FieldBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(Field::VT_NAME, name); - } - void add_type(flatbuffers::Offset type) { - fbb_.AddOffset(Field::VT_TYPE, type); - } - void add_id(uint16_t id) { - fbb_.AddElement(Field::VT_ID, id, 0); - } - void add_offset(uint16_t offset) { - fbb_.AddElement(Field::VT_OFFSET, offset, 0); - } - void add_default_integer(int64_t default_integer) { - fbb_.AddElement(Field::VT_DEFAULT_INTEGER, default_integer, 0); - } - void add_default_real(double default_real) { - fbb_.AddElement(Field::VT_DEFAULT_REAL, default_real, 0.0); - } - void add_deprecated(bool deprecated) { - fbb_.AddElement(Field::VT_DEPRECATED, static_cast(deprecated), 0); - } - void add_required(bool required) { - fbb_.AddElement(Field::VT_REQUIRED, static_cast(required), 0); - } - void add_key(bool key) { - fbb_.AddElement(Field::VT_KEY, static_cast(key), 0); - } - void add_attributes(flatbuffers::Offset>> attributes) { - fbb_.AddOffset(Field::VT_ATTRIBUTES, attributes); - } - void add_documentation(flatbuffers::Offset>> documentation) { - fbb_.AddOffset(Field::VT_DOCUMENTATION, documentation); - } - explicit FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - FieldBuilder &operator=(const FieldBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, Field::VT_NAME); - fbb_.Required(o, Field::VT_TYPE); - return o; - } -}; - -inline flatbuffers::Offset CreateField( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - flatbuffers::Offset type = 0, - uint16_t id = 0, - uint16_t offset = 0, - int64_t default_integer = 0, - double default_real = 0.0, - bool deprecated = false, - bool required = false, - bool key = false, - flatbuffers::Offset>> attributes = 0, - flatbuffers::Offset>> documentation = 0) { - FieldBuilder builder_(_fbb); - builder_.add_default_real(default_real); - builder_.add_default_integer(default_integer); - builder_.add_documentation(documentation); - builder_.add_attributes(attributes); - builder_.add_type(type); - builder_.add_name(name); - builder_.add_offset(offset); - builder_.add_id(id); - builder_.add_key(key); - builder_.add_required(required); - builder_.add_deprecated(deprecated); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateFieldDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - flatbuffers::Offset type = 0, - uint16_t id = 0, - uint16_t offset = 0, - int64_t default_integer = 0, - double default_real = 0.0, - bool deprecated = false, - bool required = false, - bool key = false, - const std::vector> *attributes = nullptr, - const std::vector> *documentation = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; - auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; - return reflection::CreateField( - _fbb, - name__, - type, - id, - offset, - default_integer, - default_real, - deprecated, - required, - key, - attributes__, - documentation__); -} - -struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_FIELDS = 6, - VT_IS_STRUCT = 8, - VT_MINALIGN = 10, - VT_BYTESIZE = 12, - VT_ATTRIBUTES = 14, - VT_DOCUMENTATION = 16 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - bool KeyCompareLessThan(const Object *o) const { - return *name() < *o->name(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(name()->c_str(), val); - } - const flatbuffers::Vector> *fields() const { - return GetPointer> *>(VT_FIELDS); - } - bool is_struct() const { - return GetField(VT_IS_STRUCT, 0) != 0; - } - int32_t minalign() const { - return GetField(VT_MINALIGN, 0); - } - int32_t bytesize() const { - return GetField(VT_BYTESIZE, 0); - } - const flatbuffers::Vector> *attributes() const { - return GetPointer> *>(VT_ATTRIBUTES); - } - const flatbuffers::Vector> *documentation() const { - return GetPointer> *>(VT_DOCUMENTATION); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffsetRequired(verifier, VT_FIELDS) && - verifier.VerifyVector(fields()) && - verifier.VerifyVectorOfTables(fields()) && - VerifyField(verifier, VT_IS_STRUCT) && - VerifyField(verifier, VT_MINALIGN) && - VerifyField(verifier, VT_BYTESIZE) && - VerifyOffset(verifier, VT_ATTRIBUTES) && - verifier.VerifyVector(attributes()) && - verifier.VerifyVectorOfTables(attributes()) && - VerifyOffset(verifier, VT_DOCUMENTATION) && - verifier.VerifyVector(documentation()) && - verifier.VerifyVectorOfStrings(documentation()) && - verifier.EndTable(); - } -}; - -struct ObjectBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(Object::VT_NAME, name); - } - void add_fields(flatbuffers::Offset>> fields) { - fbb_.AddOffset(Object::VT_FIELDS, fields); - } - void add_is_struct(bool is_struct) { - fbb_.AddElement(Object::VT_IS_STRUCT, static_cast(is_struct), 0); - } - void add_minalign(int32_t minalign) { - fbb_.AddElement(Object::VT_MINALIGN, minalign, 0); - } - void add_bytesize(int32_t bytesize) { - fbb_.AddElement(Object::VT_BYTESIZE, bytesize, 0); - } - void add_attributes(flatbuffers::Offset>> attributes) { - fbb_.AddOffset(Object::VT_ATTRIBUTES, attributes); - } - void add_documentation(flatbuffers::Offset>> documentation) { - fbb_.AddOffset(Object::VT_DOCUMENTATION, documentation); - } - explicit ObjectBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ObjectBuilder &operator=(const ObjectBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, Object::VT_NAME); - fbb_.Required(o, Object::VT_FIELDS); - return o; - } -}; - -inline flatbuffers::Offset CreateObject( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - flatbuffers::Offset>> fields = 0, - bool is_struct = false, - int32_t minalign = 0, - int32_t bytesize = 0, - flatbuffers::Offset>> attributes = 0, - flatbuffers::Offset>> documentation = 0) { - ObjectBuilder builder_(_fbb); - builder_.add_documentation(documentation); - builder_.add_attributes(attributes); - builder_.add_bytesize(bytesize); - builder_.add_minalign(minalign); - builder_.add_fields(fields); - builder_.add_name(name); - builder_.add_is_struct(is_struct); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateObjectDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - const std::vector> *fields = nullptr, - bool is_struct = false, - int32_t minalign = 0, - int32_t bytesize = 0, - const std::vector> *attributes = nullptr, - const std::vector> *documentation = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto fields__ = fields ? _fbb.CreateVector>(*fields) : 0; - auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; - auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; - return reflection::CreateObject( - _fbb, - name__, - fields__, - is_struct, - minalign, - bytesize, - attributes__, - documentation__); -} - -struct RPCCall FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_REQUEST = 6, - VT_RESPONSE = 8, - VT_ATTRIBUTES = 10, - VT_DOCUMENTATION = 12 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - bool KeyCompareLessThan(const RPCCall *o) const { - return *name() < *o->name(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(name()->c_str(), val); - } - const Object *request() const { - return GetPointer(VT_REQUEST); - } - const Object *response() const { - return GetPointer(VT_RESPONSE); - } - const flatbuffers::Vector> *attributes() const { - return GetPointer> *>(VT_ATTRIBUTES); - } - const flatbuffers::Vector> *documentation() const { - return GetPointer> *>(VT_DOCUMENTATION); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffsetRequired(verifier, VT_REQUEST) && - verifier.VerifyTable(request()) && - VerifyOffsetRequired(verifier, VT_RESPONSE) && - verifier.VerifyTable(response()) && - VerifyOffset(verifier, VT_ATTRIBUTES) && - verifier.VerifyVector(attributes()) && - verifier.VerifyVectorOfTables(attributes()) && - VerifyOffset(verifier, VT_DOCUMENTATION) && - verifier.VerifyVector(documentation()) && - verifier.VerifyVectorOfStrings(documentation()) && - verifier.EndTable(); - } -}; - -struct RPCCallBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(RPCCall::VT_NAME, name); - } - void add_request(flatbuffers::Offset request) { - fbb_.AddOffset(RPCCall::VT_REQUEST, request); - } - void add_response(flatbuffers::Offset response) { - fbb_.AddOffset(RPCCall::VT_RESPONSE, response); - } - void add_attributes(flatbuffers::Offset>> attributes) { - fbb_.AddOffset(RPCCall::VT_ATTRIBUTES, attributes); - } - void add_documentation(flatbuffers::Offset>> documentation) { - fbb_.AddOffset(RPCCall::VT_DOCUMENTATION, documentation); - } - explicit RPCCallBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - RPCCallBuilder &operator=(const RPCCallBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, RPCCall::VT_NAME); - fbb_.Required(o, RPCCall::VT_REQUEST); - fbb_.Required(o, RPCCall::VT_RESPONSE); - return o; - } -}; - -inline flatbuffers::Offset CreateRPCCall( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - flatbuffers::Offset request = 0, - flatbuffers::Offset response = 0, - flatbuffers::Offset>> attributes = 0, - flatbuffers::Offset>> documentation = 0) { - RPCCallBuilder builder_(_fbb); - builder_.add_documentation(documentation); - builder_.add_attributes(attributes); - builder_.add_response(response); - builder_.add_request(request); - builder_.add_name(name); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateRPCCallDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - flatbuffers::Offset request = 0, - flatbuffers::Offset response = 0, - const std::vector> *attributes = nullptr, - const std::vector> *documentation = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; - auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; - return reflection::CreateRPCCall( - _fbb, - name__, - request, - response, - attributes__, - documentation__); -} - -struct Service FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_NAME = 4, - VT_CALLS = 6, - VT_ATTRIBUTES = 8, - VT_DOCUMENTATION = 10 - }; - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); - } - bool KeyCompareLessThan(const Service *o) const { - return *name() < *o->name(); - } - int KeyCompareWithValue(const char *val) const { - return strcmp(name()->c_str(), val); - } - const flatbuffers::Vector> *calls() const { - return GetPointer> *>(VT_CALLS); - } - const flatbuffers::Vector> *attributes() const { - return GetPointer> *>(VT_ATTRIBUTES); - } - const flatbuffers::Vector> *documentation() const { - return GetPointer> *>(VT_DOCUMENTATION); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_NAME) && - verifier.VerifyString(name()) && - VerifyOffset(verifier, VT_CALLS) && - verifier.VerifyVector(calls()) && - verifier.VerifyVectorOfTables(calls()) && - VerifyOffset(verifier, VT_ATTRIBUTES) && - verifier.VerifyVector(attributes()) && - verifier.VerifyVectorOfTables(attributes()) && - VerifyOffset(verifier, VT_DOCUMENTATION) && - verifier.VerifyVector(documentation()) && - verifier.VerifyVectorOfStrings(documentation()) && - verifier.EndTable(); - } -}; - -struct ServiceBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_name(flatbuffers::Offset name) { - fbb_.AddOffset(Service::VT_NAME, name); - } - void add_calls(flatbuffers::Offset>> calls) { - fbb_.AddOffset(Service::VT_CALLS, calls); - } - void add_attributes(flatbuffers::Offset>> attributes) { - fbb_.AddOffset(Service::VT_ATTRIBUTES, attributes); - } - void add_documentation(flatbuffers::Offset>> documentation) { - fbb_.AddOffset(Service::VT_DOCUMENTATION, documentation); - } - explicit ServiceBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ServiceBuilder &operator=(const ServiceBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, Service::VT_NAME); - return o; - } -}; - -inline flatbuffers::Offset CreateService( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset name = 0, - flatbuffers::Offset>> calls = 0, - flatbuffers::Offset>> attributes = 0, - flatbuffers::Offset>> documentation = 0) { - ServiceBuilder builder_(_fbb); - builder_.add_documentation(documentation); - builder_.add_attributes(attributes); - builder_.add_calls(calls); - builder_.add_name(name); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateServiceDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const char *name = nullptr, - const std::vector> *calls = nullptr, - const std::vector> *attributes = nullptr, - const std::vector> *documentation = nullptr) { - auto name__ = name ? _fbb.CreateString(name) : 0; - auto calls__ = calls ? _fbb.CreateVector>(*calls) : 0; - auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; - auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; - return reflection::CreateService( - _fbb, - name__, - calls__, - attributes__, - documentation__); -} - -struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_OBJECTS = 4, - VT_ENUMS = 6, - VT_FILE_IDENT = 8, - VT_FILE_EXT = 10, - VT_ROOT_TABLE = 12, - VT_SERVICES = 14 - }; - const flatbuffers::Vector> *objects() const { - return GetPointer> *>(VT_OBJECTS); - } - const flatbuffers::Vector> *enums() const { - return GetPointer> *>(VT_ENUMS); - } - const flatbuffers::String *file_ident() const { - return GetPointer(VT_FILE_IDENT); - } - const flatbuffers::String *file_ext() const { - return GetPointer(VT_FILE_EXT); - } - const Object *root_table() const { - return GetPointer(VT_ROOT_TABLE); - } - const flatbuffers::Vector> *services() const { - return GetPointer> *>(VT_SERVICES); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffsetRequired(verifier, VT_OBJECTS) && - verifier.VerifyVector(objects()) && - verifier.VerifyVectorOfTables(objects()) && - VerifyOffsetRequired(verifier, VT_ENUMS) && - verifier.VerifyVector(enums()) && - verifier.VerifyVectorOfTables(enums()) && - VerifyOffset(verifier, VT_FILE_IDENT) && - verifier.VerifyString(file_ident()) && - VerifyOffset(verifier, VT_FILE_EXT) && - verifier.VerifyString(file_ext()) && - VerifyOffset(verifier, VT_ROOT_TABLE) && - verifier.VerifyTable(root_table()) && - VerifyOffset(verifier, VT_SERVICES) && - verifier.VerifyVector(services()) && - verifier.VerifyVectorOfTables(services()) && - verifier.EndTable(); - } -}; - -struct SchemaBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_objects(flatbuffers::Offset>> objects) { - fbb_.AddOffset(Schema::VT_OBJECTS, objects); - } - void add_enums(flatbuffers::Offset>> enums) { - fbb_.AddOffset(Schema::VT_ENUMS, enums); - } - void add_file_ident(flatbuffers::Offset file_ident) { - fbb_.AddOffset(Schema::VT_FILE_IDENT, file_ident); - } - void add_file_ext(flatbuffers::Offset file_ext) { - fbb_.AddOffset(Schema::VT_FILE_EXT, file_ext); - } - void add_root_table(flatbuffers::Offset root_table) { - fbb_.AddOffset(Schema::VT_ROOT_TABLE, root_table); - } - void add_services(flatbuffers::Offset>> services) { - fbb_.AddOffset(Schema::VT_SERVICES, services); - } - explicit SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - SchemaBuilder &operator=(const SchemaBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - fbb_.Required(o, Schema::VT_OBJECTS); - fbb_.Required(o, Schema::VT_ENUMS); - return o; - } -}; - -inline flatbuffers::Offset CreateSchema( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset>> objects = 0, - flatbuffers::Offset>> enums = 0, - flatbuffers::Offset file_ident = 0, - flatbuffers::Offset file_ext = 0, - flatbuffers::Offset root_table = 0, - flatbuffers::Offset>> services = 0) { - SchemaBuilder builder_(_fbb); - builder_.add_services(services); - builder_.add_root_table(root_table); - builder_.add_file_ext(file_ext); - builder_.add_file_ident(file_ident); - builder_.add_enums(enums); - builder_.add_objects(objects); - return builder_.Finish(); -} - -inline flatbuffers::Offset CreateSchemaDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const std::vector> *objects = nullptr, - const std::vector> *enums = nullptr, - const char *file_ident = nullptr, - const char *file_ext = nullptr, - flatbuffers::Offset root_table = 0, - const std::vector> *services = nullptr) { - auto objects__ = objects ? _fbb.CreateVector>(*objects) : 0; - auto enums__ = enums ? _fbb.CreateVector>(*enums) : 0; - auto file_ident__ = file_ident ? _fbb.CreateString(file_ident) : 0; - auto file_ext__ = file_ext ? _fbb.CreateString(file_ext) : 0; - auto services__ = services ? _fbb.CreateVector>(*services) : 0; - return reflection::CreateSchema( - _fbb, - objects__, - enums__, - file_ident__, - file_ext__, - root_table, - services__); -} - -inline const reflection::Schema *GetSchema(const void *buf) { - return flatbuffers::GetRoot(buf); -} - -inline const reflection::Schema *GetSizePrefixedSchema(const void *buf) { - return flatbuffers::GetSizePrefixedRoot(buf); -} - -inline const char *SchemaIdentifier() { - return "BFBS"; -} - -inline bool SchemaBufferHasIdentifier(const void *buf) { - return flatbuffers::BufferHasIdentifier( - buf, SchemaIdentifier()); -} - -inline bool VerifySchemaBuffer( - flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(SchemaIdentifier()); -} - -inline bool VerifySizePrefixedSchemaBuffer( - flatbuffers::Verifier &verifier) { - return verifier.VerifySizePrefixedBuffer(SchemaIdentifier()); -} - -inline const char *SchemaExtension() { - return "bfbs"; -} - -inline void FinishSchemaBuffer( - flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { - fbb.Finish(root, SchemaIdentifier()); -} - -inline void FinishSizePrefixedSchemaBuffer( - flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { - fbb.FinishSizePrefixed(root, SchemaIdentifier()); -} - -} // namespace reflection - -#endif // FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ diff --git a/src/internal/include/flatbuffers/registry.h b/src/internal/include/flatbuffers/registry.h deleted file mode 100644 index 9ea425b..0000000 --- a/src/internal/include/flatbuffers/registry.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2017 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. - */ - -#ifndef FLATBUFFERS_REGISTRY_H_ -#define FLATBUFFERS_REGISTRY_H_ - -#include "flatbuffers/idl.h" - -namespace flatbuffers { - -// Convenience class to easily parse or generate text for arbitrary FlatBuffers. -// Simply pre-populate it with all schema filenames that may be in use, and -// This class will look them up using the file_identifier declared in the -// schema. -class Registry { - public: - // Call this for all schemas that may be in use. The identifier has - // a function in the generated code, e.g. MonsterIdentifier(). - void Register(const char *file_identifier, const char *schema_path) { - Schema schema; - schema.path_ = schema_path; - schemas_[file_identifier] = schema; - } - - // Generate text from an arbitrary FlatBuffer by looking up its - // file_identifier in the registry. - bool FlatBufferToText(const uint8_t *flatbuf, size_t len, std::string *dest) { - // Get the identifier out of the buffer. - // If the buffer is truncated, exit. - if (len < sizeof(uoffset_t) + FlatBufferBuilder::kFileIdentifierLength) { - lasterror_ = "buffer truncated"; - return false; - } - std::string ident( - reinterpret_cast(flatbuf) + sizeof(uoffset_t), - FlatBufferBuilder::kFileIdentifierLength); - // Load and parse the schema. - Parser parser; - if (!LoadSchema(ident, &parser)) return false; - // Now we're ready to generate text. - if (!GenerateText(parser, flatbuf, dest)) { - lasterror_ = "unable to generate text for FlatBuffer binary"; - return false; - } - return true; - } - - // Converts a binary buffer to text using one of the schemas in the registry, - // use the file_identifier to indicate which. - // If DetachedBuffer::data() is null then parsing failed. - DetachedBuffer TextToFlatBuffer(const char *text, - const char *file_identifier) { - // Load and parse the schema. - Parser parser; - if (!LoadSchema(file_identifier, &parser)) return DetachedBuffer(); - // Parse the text. - if (!parser.Parse(text)) { - lasterror_ = parser.error_; - return DetachedBuffer(); - } - // We have a valid FlatBuffer. Detach it from the builder and return. - return parser.builder_.Release(); - } - - // Modify any parsing / output options used by the other functions. - void SetOptions(const IDLOptions &opts) { opts_ = opts; } - - // If schemas used contain include statements, call this function for every - // directory the parser should search them for. - void AddIncludeDirectory(const char *path) { include_paths_.push_back(path); } - - // Returns a human readable error if any of the above functions fail. - const std::string &GetLastError() { return lasterror_; } - - private: - bool LoadSchema(const std::string &ident, Parser *parser) { - // Find the schema, if not, exit. - auto it = schemas_.find(ident); - if (it == schemas_.end()) { - // Don't attach the identifier, since it may not be human readable. - lasterror_ = "identifier for this buffer not in the registry"; - return false; - } - auto &schema = it->second; - // Load the schema from disk. If not, exit. - std::string schematext; - if (!LoadFile(schema.path_.c_str(), false, &schematext)) { - lasterror_ = "could not load schema: " + schema.path_; - return false; - } - // Parse schema. - parser->opts = opts_; - if (!parser->Parse(schematext.c_str(), vector_data(include_paths_), - schema.path_.c_str())) { - lasterror_ = parser->error_; - return false; - } - return true; - } - - struct Schema { - std::string path_; - // TODO(wvo) optionally cache schema file or parsed schema here. - }; - - std::string lasterror_; - IDLOptions opts_; - std::vector include_paths_; - std::map schemas_; -}; - -} // namespace flatbuffers - -#endif // FLATBUFFERS_REGISTRY_H_ diff --git a/src/internal/include/flatbuffers/stl_emulation.h b/src/internal/include/flatbuffers/stl_emulation.h deleted file mode 100644 index 561a298..0000000 --- a/src/internal/include/flatbuffers/stl_emulation.h +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 2017 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. - */ - -#ifndef FLATBUFFERS_STL_EMULATION_H_ -#define FLATBUFFERS_STL_EMULATION_H_ - -// clang-format off - -#include -#include -#include -#include -#include - -#if defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL) - #define FLATBUFFERS_CPP98_STL -#endif // defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL) - -#if defined(FLATBUFFERS_CPP98_STL) - #include -#endif // defined(FLATBUFFERS_CPP98_STL) - -// Check if we can use template aliases -// Not possible if Microsoft Compiler before 2012 -// Possible is the language feature __cpp_alias_templates is defined well -// Or possible if the C++ std is C+11 or newer -#if (defined(_MSC_VER) && _MSC_VER > 1700 /* MSVC2012 */) \ - || (defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \ - || (defined(__cplusplus) && __cplusplus >= 201103L) - #define FLATBUFFERS_TEMPLATES_ALIASES -#endif - -// This header provides backwards compatibility for C++98 STLs like stlport. -namespace flatbuffers { - -// Retrieve ::back() from a string in a way that is compatible with pre C++11 -// STLs (e.g stlport). -inline char& string_back(std::string &value) { - return value[value.length() - 1]; -} - -inline char string_back(const std::string &value) { - return value[value.length() - 1]; -} - -// Helper method that retrieves ::data() from a vector in a way that is -// compatible with pre C++11 STLs (e.g stlport). -template inline T *vector_data(std::vector &vector) { - // In some debug environments, operator[] does bounds checking, so &vector[0] - // can't be used. - return vector.empty() ? nullptr : &vector[0]; -} - -template inline const T *vector_data( - const std::vector &vector) { - return vector.empty() ? nullptr : &vector[0]; -} - -template -inline void vector_emplace_back(std::vector *vector, V &&data) { - #if defined(FLATBUFFERS_CPP98_STL) - vector->push_back(data); - #else - vector->emplace_back(std::forward(data)); - #endif // defined(FLATBUFFERS_CPP98_STL) -} - -#ifndef FLATBUFFERS_CPP98_STL - #if defined(FLATBUFFERS_TEMPLATES_ALIASES) - template - using numeric_limits = std::numeric_limits; - #else - template class numeric_limits : - public std::numeric_limits {}; - #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) -#else - template class numeric_limits : - public std::numeric_limits { - public: - // Android NDK fix. - static T lowest() { - return std::numeric_limits::min(); - } - }; - - template <> class numeric_limits : - public std::numeric_limits { - public: - static float lowest() { return -FLT_MAX; } - }; - - template <> class numeric_limits : - public std::numeric_limits { - public: - static double lowest() { return -DBL_MAX; } - }; - - template <> class numeric_limits { - public: - static unsigned long long min() { return 0ULL; } - static unsigned long long max() { return ~0ULL; } - static unsigned long long lowest() { - return numeric_limits::min(); - } - }; - - template <> class numeric_limits { - public: - static long long min() { - return static_cast(1ULL << ((sizeof(long long) << 3) - 1)); - } - static long long max() { - return static_cast( - (1ULL << ((sizeof(long long) << 3) - 1)) - 1); - } - static long long lowest() { - return numeric_limits::min(); - } - }; -#endif // FLATBUFFERS_CPP98_STL - -#if defined(FLATBUFFERS_TEMPLATES_ALIASES) - #ifndef FLATBUFFERS_CPP98_STL - template using is_scalar = std::is_scalar; - template using is_same = std::is_same; - template using is_floating_point = std::is_floating_point; - template using is_unsigned = std::is_unsigned; - template using make_unsigned = std::make_unsigned; - #else - // Map C++ TR1 templates defined by stlport. - template using is_scalar = std::tr1::is_scalar; - template using is_same = std::tr1::is_same; - template using is_floating_point = - std::tr1::is_floating_point; - template using is_unsigned = std::tr1::is_unsigned; - // Android NDK doesn't have std::make_unsigned or std::tr1::make_unsigned. - template struct make_unsigned { - static_assert(is_unsigned::value, "Specialization not implemented!"); - using type = T; - }; - template<> struct make_unsigned { using type = unsigned char; }; - template<> struct make_unsigned { using type = unsigned short; }; - template<> struct make_unsigned { using type = unsigned int; }; - template<> struct make_unsigned { using type = unsigned long; }; - template<> - struct make_unsigned { using type = unsigned long long; }; - #endif // !FLATBUFFERS_CPP98_STL -#else - // MSVC 2010 doesn't support C++11 aliases. - template struct is_scalar : public std::is_scalar {}; - template struct is_same : public std::is_same {}; - template struct is_floating_point : - public std::is_floating_point {}; - template struct is_unsigned : public std::is_unsigned {}; - template struct make_unsigned : public std::make_unsigned {}; -#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) - -#ifndef FLATBUFFERS_CPP98_STL - #if defined(FLATBUFFERS_TEMPLATES_ALIASES) - template using unique_ptr = std::unique_ptr; - #else - // MSVC 2010 doesn't support C++11 aliases. - // We're manually "aliasing" the class here as we want to bring unique_ptr - // into the flatbuffers namespace. We have unique_ptr in the flatbuffers - // namespace we have a completely independent implemenation (see below) - // for C++98 STL implementations. - template class unique_ptr : public std::unique_ptr { - public: - unique_ptr() {} - explicit unique_ptr(T* p) : std::unique_ptr(p) {} - unique_ptr(std::unique_ptr&& u) { *this = std::move(u); } - unique_ptr(unique_ptr&& u) { *this = std::move(u); } - unique_ptr& operator=(std::unique_ptr&& u) { - std::unique_ptr::reset(u.release()); - return *this; - } - unique_ptr& operator=(unique_ptr&& u) { - std::unique_ptr::reset(u.release()); - return *this; - } - unique_ptr& operator=(T* p) { - return std::unique_ptr::operator=(p); - } - }; - #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) -#else - // Very limited implementation of unique_ptr. - // This is provided simply to allow the C++ code generated from the default - // settings to function in C++98 environments with no modifications. - template class unique_ptr { - public: - typedef T element_type; - - unique_ptr() : ptr_(nullptr) {} - explicit unique_ptr(T* p) : ptr_(p) {} - unique_ptr(unique_ptr&& u) : ptr_(nullptr) { reset(u.release()); } - unique_ptr(const unique_ptr& u) : ptr_(nullptr) { - reset(const_cast(&u)->release()); - } - ~unique_ptr() { reset(); } - - unique_ptr& operator=(const unique_ptr& u) { - reset(const_cast(&u)->release()); - return *this; - } - - unique_ptr& operator=(unique_ptr&& u) { - reset(u.release()); - return *this; - } - - unique_ptr& operator=(T* p) { - reset(p); - return *this; - } - - const T& operator*() const { return *ptr_; } - T* operator->() const { return ptr_; } - T* get() const noexcept { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - // modifiers - T* release() { - T* value = ptr_; - ptr_ = nullptr; - return value; - } - - void reset(T* p = nullptr) { - T* value = ptr_; - ptr_ = p; - if (value) delete value; - } - - void swap(unique_ptr& u) { - T* temp_ptr = ptr_; - ptr_ = u.ptr_; - u.ptr_ = temp_ptr; - } - - private: - T* ptr_; - }; - - template bool operator==(const unique_ptr& x, - const unique_ptr& y) { - return x.get() == y.get(); - } - - template bool operator==(const unique_ptr& x, - const D* y) { - return static_cast(x.get()) == y; - } - - template bool operator==(const unique_ptr& x, intptr_t y) { - return reinterpret_cast(x.get()) == y; - } -#endif // !FLATBUFFERS_CPP98_STL - -} // namespace flatbuffers - -#endif // FLATBUFFERS_STL_EMULATION_H_ diff --git a/src/internal/include/flatbuffers/util.h b/src/internal/include/flatbuffers/util.h deleted file mode 100644 index 71e1973..0000000 --- a/src/internal/include/flatbuffers/util.h +++ /dev/null @@ -1,651 +0,0 @@ -/* - * 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. - */ - -#ifndef FLATBUFFERS_UTIL_H_ -#define FLATBUFFERS_UTIL_H_ - -#include "flatbuffers/base.h" - -#include - -#ifndef FLATBUFFERS_PREFER_PRINTF -# include -#else // FLATBUFFERS_PREFER_PRINTF -# include -# include -#endif // FLATBUFFERS_PREFER_PRINTF - -#include -#include - -namespace flatbuffers { - -// @locale-independent functions for ASCII characters set. - -// Check that integer scalar is in closed range: (a <= x <= b) -// using one compare (conditional branch) operator. -template inline bool check_in_range(T x, T a, T b) { - // (Hacker's Delight): `a <= x <= b` <=> `(x-a) <={u} (b-a)`. - FLATBUFFERS_ASSERT(a <= b); // static_assert only if 'a' & 'b' templated - typedef typename flatbuffers::make_unsigned::type U; - return (static_cast(x - a) <= static_cast(b - a)); -} - -// Case-insensitive isalpha -inline bool is_alpha(char c) { - // ASCII only: alpha to upper case => reset bit 0x20 (~0x20 = 0xDF). - return check_in_range(c & 0xDF, 'a' & 0xDF, 'z' & 0xDF); -} - -// Check (case-insensitive) that `c` is equal to alpha. -inline bool is_alpha_char(char c, char alpha) { - FLATBUFFERS_ASSERT(is_alpha(alpha)); - // ASCII only: alpha to upper case => reset bit 0x20 (~0x20 = 0xDF). - return ((c & 0xDF) == (alpha & 0xDF)); -} - -// https://en.cppreference.com/w/cpp/string/byte/isxdigit -// isdigit and isxdigit are the only standard narrow character classification -// functions that are not affected by the currently installed C locale. although -// some implementations (e.g. Microsoft in 1252 codepage) may classify -// additional single-byte characters as digits. -inline bool is_digit(char c) { return check_in_range(c, '0', '9'); } - -inline bool is_xdigit(char c) { - // Replace by look-up table. - return is_digit(c) || check_in_range(c & 0xDF, 'a' & 0xDF, 'f' & 0xDF); -} - -// Case-insensitive isalnum -inline bool is_alnum(char c) { return is_alpha(c) || is_digit(c); } - -// @end-locale-independent functions for ASCII character set - -#ifdef FLATBUFFERS_PREFER_PRINTF -template size_t IntToDigitCount(T t) { - size_t digit_count = 0; - // Count the sign for negative numbers - if (t < 0) digit_count++; - // Count a single 0 left of the dot for fractional numbers - if (-1 < t && t < 1) digit_count++; - // Count digits until fractional part - T eps = std::numeric_limits::epsilon(); - while (t <= (-1 + eps) || (1 - eps) <= t) { - t /= 10; - digit_count++; - } - return digit_count; -} - -template size_t NumToStringWidth(T t, int precision = 0) { - size_t string_width = IntToDigitCount(t); - // Count the dot for floating point numbers - if (precision) string_width += (precision + 1); - return string_width; -} - -template -std::string NumToStringImplWrapper(T t, const char *fmt, int precision = 0) { - size_t string_width = NumToStringWidth(t, precision); - std::string s(string_width, 0x00); - // Allow snprintf to use std::string trailing null to detect buffer overflow - snprintf(const_cast(s.data()), (s.size() + 1), fmt, precision, t); - return s; -} -#endif // FLATBUFFERS_PREFER_PRINTF - -// Convert an integer or floating point value to a string. -// In contrast to std::stringstream, "char" values are -// converted to a string of digits, and we don't use scientific notation. -template std::string NumToString(T t) { - // clang-format off - - #ifndef FLATBUFFERS_PREFER_PRINTF - std::stringstream ss; - ss << t; - return ss.str(); - #else // FLATBUFFERS_PREFER_PRINTF - auto v = static_cast(t); - return NumToStringImplWrapper(v, "%.*lld"); - #endif // FLATBUFFERS_PREFER_PRINTF - // clang-format on -} -// Avoid char types used as character data. -template<> inline std::string NumToString(signed char t) { - return NumToString(static_cast(t)); -} -template<> inline std::string NumToString(unsigned char t) { - return NumToString(static_cast(t)); -} -#if defined(FLATBUFFERS_CPP98_STL) -template<> inline std::string NumToString(long long t) { - char buf[21]; // (log((1 << 63) - 1) / log(10)) + 2 - snprintf(buf, sizeof(buf), "%lld", t); - return std::string(buf); -} - -template<> -inline std::string NumToString(unsigned long long t) { - char buf[22]; // (log((1 << 63) - 1) / log(10)) + 1 - snprintf(buf, sizeof(buf), "%llu", t); - return std::string(buf); -} -#endif // defined(FLATBUFFERS_CPP98_STL) - -// Special versions for floats/doubles. -template std::string FloatToString(T t, int precision) { - // clang-format off - - #ifndef FLATBUFFERS_PREFER_PRINTF - // to_string() prints different numbers of digits for floats depending on - // platform and isn't available on Android, so we use stringstream - std::stringstream ss; - // Use std::fixed to suppress scientific notation. - ss << std::fixed; - // Default precision is 6, we want that to be higher for doubles. - ss << std::setprecision(precision); - ss << t; - auto s = ss.str(); - #else // FLATBUFFERS_PREFER_PRINTF - auto v = static_cast(t); - auto s = NumToStringImplWrapper(v, "%0.*f", precision); - #endif // FLATBUFFERS_PREFER_PRINTF - // clang-format on - // Sadly, std::fixed turns "1" into "1.00000", so here we undo that. - auto p = s.find_last_not_of('0'); - if (p != std::string::npos) { - // Strip trailing zeroes. If it is a whole number, keep one zero. - s.resize(p + (s[p] == '.' ? 2 : 1)); - } - return s; -} - -template<> inline std::string NumToString(double t) { - return FloatToString(t, 12); -} -template<> inline std::string NumToString(float t) { - return FloatToString(t, 6); -} - -// Convert an integer value to a hexadecimal string. -// The returned string length is always xdigits long, prefixed by 0 digits. -// For example, IntToStringHex(0x23, 8) returns the string "00000023". -inline std::string IntToStringHex(int i, int xdigits) { - FLATBUFFERS_ASSERT(i >= 0); - // clang-format off - - #ifndef FLATBUFFERS_PREFER_PRINTF - std::stringstream ss; - ss << std::setw(xdigits) << std::setfill('0') << std::hex << std::uppercase - << i; - return ss.str(); - #else // FLATBUFFERS_PREFER_PRINTF - return NumToStringImplWrapper(i, "%.*X", xdigits); - #endif // FLATBUFFERS_PREFER_PRINTF - // clang-format on -} - -// clang-format off -// Use locale independent functions {strtod_l, strtof_l, strtoll_l, strtoull_l}. -#if defined(FLATBUFFERS_LOCALE_INDEPENDENT) && (FLATBUFFERS_LOCALE_INDEPENDENT > 0) - class ClassicLocale { - #ifdef _MSC_VER - typedef _locale_t locale_type; - #else - typedef locale_t locale_type; // POSIX.1-2008 locale_t type - #endif - ClassicLocale(); - ~ClassicLocale(); - locale_type locale_; - static ClassicLocale instance_; - public: - static locale_type Get() { return instance_.locale_; } - }; - - #ifdef _MSC_VER - #define __strtoull_impl(s, pe, b) _strtoui64_l(s, pe, b, ClassicLocale::Get()) - #define __strtoll_impl(s, pe, b) _strtoi64_l(s, pe, b, ClassicLocale::Get()) - #define __strtod_impl(s, pe) _strtod_l(s, pe, ClassicLocale::Get()) - #define __strtof_impl(s, pe) _strtof_l(s, pe, ClassicLocale::Get()) - #else - #define __strtoull_impl(s, pe, b) strtoull_l(s, pe, b, ClassicLocale::Get()) - #define __strtoll_impl(s, pe, b) strtoll_l(s, pe, b, ClassicLocale::Get()) - #define __strtod_impl(s, pe) strtod_l(s, pe, ClassicLocale::Get()) - #define __strtof_impl(s, pe) strtof_l(s, pe, ClassicLocale::Get()) - #endif -#else - #define __strtod_impl(s, pe) strtod(s, pe) - #define __strtof_impl(s, pe) static_cast(strtod(s, pe)) - #ifdef _MSC_VER - #define __strtoull_impl(s, pe, b) _strtoui64(s, pe, b) - #define __strtoll_impl(s, pe, b) _strtoi64(s, pe, b) - #else - #define __strtoull_impl(s, pe, b) strtoull(s, pe, b) - #define __strtoll_impl(s, pe, b) strtoll(s, pe, b) - #endif -#endif - -inline void strtoval_impl(int64_t *val, const char *str, char **endptr, - int base) { - *val = __strtoll_impl(str, endptr, base); -} - -inline void strtoval_impl(uint64_t *val, const char *str, char **endptr, - int base) { - *val = __strtoull_impl(str, endptr, base); -} - -inline void strtoval_impl(double *val, const char *str, char **endptr) { - *val = __strtod_impl(str, endptr); -} - -// UBSAN: double to float is safe if numeric_limits::is_iec559 is true. -__supress_ubsan__("float-cast-overflow") -inline void strtoval_impl(float *val, const char *str, char **endptr) { - *val = __strtof_impl(str, endptr); -} -#undef __strtoull_impl -#undef __strtoll_impl -#undef __strtod_impl -#undef __strtof_impl -// clang-format on - -// Adaptor for strtoull()/strtoll(). -// Flatbuffers accepts numbers with any count of leading zeros (-009 is -9), -// while strtoll with base=0 interprets first leading zero as octal prefix. -// In future, it is possible to add prefixed 0b0101. -// 1) Checks errno code for overflow condition (out of range). -// 2) If base <= 0, function try to detect base of number by prefix. -// -// Return value (like strtoull and strtoll, but reject partial result): -// - If successful, an integer value corresponding to the str is returned. -// - If full string conversion can't be performed, 0 is returned. -// - If the converted value falls out of range of corresponding return type, a -// range error occurs. In this case value MAX(T)/MIN(T) is returned. -template -inline bool StringToIntegerImpl(T *val, const char *const str, - const int base = 0, - const bool check_errno = true) { - // T is int64_t or uint64_T - FLATBUFFERS_ASSERT(str); - if (base <= 0) { - auto s = str; - while (*s && !is_digit(*s)) s++; - if (s[0] == '0' && is_alpha_char(s[1], 'X')) - return StringToIntegerImpl(val, str, 16, check_errno); - // if a prefix not match, try base=10 - return StringToIntegerImpl(val, str, 10, check_errno); - } else { - if (check_errno) errno = 0; // clear thread-local errno - auto endptr = str; - strtoval_impl(val, str, const_cast(&endptr), base); - if ((*endptr != '\0') || (endptr == str)) { - *val = 0; // erase partial result - return false; // invalid string - } - // errno is out-of-range, return MAX/MIN - if (check_errno && errno) return false; - return true; - } -} - -template -inline bool StringToFloatImpl(T *val, const char *const str) { - // Type T must be either float or double. - FLATBUFFERS_ASSERT(str && val); - auto end = str; - strtoval_impl(val, str, const_cast(&end)); - auto done = (end != str) && (*end == '\0'); - if (!done) *val = 0; // erase partial result - return done; -} - -// Convert a string to an instance of T. -// Return value (matched with StringToInteger64Impl and strtod): -// - If successful, a numeric value corresponding to the str is returned. -// - If full string conversion can't be performed, 0 is returned. -// - If the converted value falls out of range of corresponding return type, a -// range error occurs. In this case value MAX(T)/MIN(T) is returned. -template inline bool StringToNumber(const char *s, T *val) { - FLATBUFFERS_ASSERT(s && val); - int64_t i64; - // The errno check isn't needed, will return MAX/MIN on overflow. - if (StringToIntegerImpl(&i64, s, 0, false)) { - const int64_t max = flatbuffers::numeric_limits::max(); - const int64_t min = flatbuffers::numeric_limits::lowest(); - if (i64 > max) { - *val = static_cast(max); - return false; - } - if (i64 < min) { - // For unsigned types return max to distinguish from - // "no conversion can be performed" when 0 is returned. - *val = static_cast(flatbuffers::is_unsigned::value ? max : min); - return false; - } - *val = static_cast(i64); - return true; - } - *val = 0; - return false; -} - -template<> inline bool StringToNumber(const char *str, int64_t *val) { - return StringToIntegerImpl(val, str); -} - -template<> -inline bool StringToNumber(const char *str, uint64_t *val) { - if (!StringToIntegerImpl(val, str)) return false; - // The strtoull accepts negative numbers: - // If the minus sign was part of the input sequence, the numeric value - // calculated from the sequence of digits is negated as if by unary minus - // in the result type, which applies unsigned integer wraparound rules. - // Fix this behaviour (except -0). - if (*val) { - auto s = str; - while (*s && !is_digit(*s)) s++; - s = (s > str) ? (s - 1) : s; // step back to one symbol - if (*s == '-') { - // For unsigned types return the max to distinguish from - // "no conversion can be performed". - *val = flatbuffers::numeric_limits::max(); - return false; - } - } - return true; -} - -template<> inline bool StringToNumber(const char *s, float *val) { - return StringToFloatImpl(val, s); -} - -template<> inline bool StringToNumber(const char *s, double *val) { - return StringToFloatImpl(val, s); -} - -inline int64_t StringToInt(const char *s, int base = 10) { - int64_t val; - return StringToIntegerImpl(&val, s, base) ? val : 0; -} - -inline uint64_t StringToUInt(const char *s, int base = 10) { - uint64_t val; - return StringToIntegerImpl(&val, s, base) ? val : 0; -} - -typedef bool (*LoadFileFunction)(const char *filename, bool binary, - std::string *dest); -typedef bool (*FileExistsFunction)(const char *filename); - -LoadFileFunction SetLoadFileFunction(LoadFileFunction load_file_function); - -FileExistsFunction SetFileExistsFunction( - FileExistsFunction file_exists_function); - -// Check if file "name" exists. -bool FileExists(const char *name); - -// Check if "name" exists and it is also a directory. -bool DirExists(const char *name); - -// Load file "name" into "buf" returning true if successful -// false otherwise. If "binary" is false data is read -// using ifstream's text mode, otherwise data is read with -// no transcoding. -bool LoadFile(const char *name, bool binary, std::string *buf); - -// Save data "buf" of length "len" bytes into a file -// "name" returning true if successful, false otherwise. -// If "binary" is false data is written using ifstream's -// text mode, otherwise data is written with no -// transcoding. -bool SaveFile(const char *name, const char *buf, size_t len, bool binary); - -// Save data "buf" into file "name" returning true if -// successful, false otherwise. If "binary" is false -// data is written using ifstream's text mode, otherwise -// data is written with no transcoding. -inline bool SaveFile(const char *name, const std::string &buf, bool binary) { - return SaveFile(name, buf.c_str(), buf.size(), binary); -} - -// Functionality for minimalistic portable path handling. - -// The functions below behave correctly regardless of whether posix ('/') or -// Windows ('/' or '\\') separators are used. - -// Any new separators inserted are always posix. -FLATBUFFERS_CONSTEXPR char kPathSeparator = '/'; - -// Returns the path with the extension, if any, removed. -std::string StripExtension(const std::string &filepath); - -// Returns the extension, if any. -std::string GetExtension(const std::string &filepath); - -// Return the last component of the path, after the last separator. -std::string StripPath(const std::string &filepath); - -// Strip the last component of the path + separator. -std::string StripFileName(const std::string &filepath); - -// Concatenates a path with a filename, regardless of wether the path -// ends in a separator or not. -std::string ConCatPathFileName(const std::string &path, - const std::string &filename); - -// Replaces any '\\' separators with '/' -std::string PosixPath(const char *path); - -// This function ensure a directory exists, by recursively -// creating dirs for any parts of the path that don't exist yet. -void EnsureDirExists(const std::string &filepath); - -// Obtains the absolute path from any other path. -// Returns the input path if the absolute path couldn't be resolved. -std::string AbsolutePath(const std::string &filepath); - -// To and from UTF-8 unicode conversion functions - -// Convert a unicode code point into a UTF-8 representation by appending it -// to a string. Returns the number of bytes generated. -inline int ToUTF8(uint32_t ucc, std::string *out) { - FLATBUFFERS_ASSERT(!(ucc & 0x80000000)); // Top bit can't be set. - // 6 possible encodings: http://en.wikipedia.org/wiki/UTF-8 - for (int i = 0; i < 6; i++) { - // Max bits this encoding can represent. - uint32_t max_bits = 6 + i * 5 + static_cast(!i); - if (ucc < (1u << max_bits)) { // does it fit? - // Remaining bits not encoded in the first byte, store 6 bits each - uint32_t remain_bits = i * 6; - // Store first byte: - (*out) += static_cast((0xFE << (max_bits - remain_bits)) | - (ucc >> remain_bits)); - // Store remaining bytes: - for (int j = i - 1; j >= 0; j--) { - (*out) += static_cast(((ucc >> (j * 6)) & 0x3F) | 0x80); - } - return i + 1; // Return the number of bytes added. - } - } - FLATBUFFERS_ASSERT(0); // Impossible to arrive here. - return -1; -} - -// Converts whatever prefix of the incoming string corresponds to a valid -// UTF-8 sequence into a unicode code. The incoming pointer will have been -// advanced past all bytes parsed. -// returns -1 upon corrupt UTF-8 encoding (ignore the incoming pointer in -// this case). -inline int FromUTF8(const char **in) { - int len = 0; - // Count leading 1 bits. - for (int mask = 0x80; mask >= 0x04; mask >>= 1) { - if (**in & mask) { - len++; - } else { - break; - } - } - if ((static_cast(**in) << len) & 0x80) - return -1; // Bit after leading 1's must be 0. - if (!len) return *(*in)++; - // UTF-8 encoded values with a length are between 2 and 4 bytes. - if (len < 2 || len > 4) { return -1; } - // Grab initial bits of the code. - int ucc = *(*in)++ & ((1 << (7 - len)) - 1); - for (int i = 0; i < len - 1; i++) { - if ((**in & 0xC0) != 0x80) return -1; // Upper bits must 1 0. - ucc <<= 6; - ucc |= *(*in)++ & 0x3F; // Grab 6 more bits of the code. - } - // UTF-8 cannot encode values between 0xD800 and 0xDFFF (reserved for - // UTF-16 surrogate pairs). - if (ucc >= 0xD800 && ucc <= 0xDFFF) { return -1; } - // UTF-8 must represent code points in their shortest possible encoding. - switch (len) { - case 2: - // Two bytes of UTF-8 can represent code points from U+0080 to U+07FF. - if (ucc < 0x0080 || ucc > 0x07FF) { return -1; } - break; - case 3: - // Three bytes of UTF-8 can represent code points from U+0800 to U+FFFF. - if (ucc < 0x0800 || ucc > 0xFFFF) { return -1; } - break; - case 4: - // Four bytes of UTF-8 can represent code points from U+10000 to U+10FFFF. - if (ucc < 0x10000 || ucc > 0x10FFFF) { return -1; } - break; - } - return ucc; -} - -#ifndef FLATBUFFERS_PREFER_PRINTF -// Wraps a string to a maximum length, inserting new lines where necessary. Any -// existing whitespace will be collapsed down to a single space. A prefix or -// suffix can be provided, which will be inserted before or after a wrapped -// line, respectively. -inline std::string WordWrap(const std::string in, size_t max_length, - const std::string wrapped_line_prefix, - const std::string wrapped_line_suffix) { - std::istringstream in_stream(in); - std::string wrapped, line, word; - - in_stream >> word; - line = word; - - while (in_stream >> word) { - if ((line.length() + 1 + word.length() + wrapped_line_suffix.length()) < - max_length) { - line += " " + word; - } else { - wrapped += line + wrapped_line_suffix + "\n"; - line = wrapped_line_prefix + word; - } - } - wrapped += line; - - return wrapped; -} -#endif // !FLATBUFFERS_PREFER_PRINTF - -inline bool EscapeString(const char *s, size_t length, std::string *_text, - bool allow_non_utf8, bool natural_utf8) { - std::string &text = *_text; - text += "\""; - for (uoffset_t i = 0; i < length; i++) { - char c = s[i]; - switch (c) { - case '\n': text += "\\n"; break; - case '\t': text += "\\t"; break; - case '\r': text += "\\r"; break; - case '\b': text += "\\b"; break; - case '\f': text += "\\f"; break; - case '\"': text += "\\\""; break; - case '\\': text += "\\\\"; break; - default: - if (c >= ' ' && c <= '~') { - text += c; - } else { - // Not printable ASCII data. Let's see if it's valid UTF-8 first: - const char *utf8 = s + i; - int ucc = FromUTF8(&utf8); - if (ucc < 0) { - if (allow_non_utf8) { - text += "\\x"; - text += IntToStringHex(static_cast(c), 2); - } else { - // There are two cases here: - // - // 1) We reached here by parsing an IDL file. In that case, - // we previously checked for non-UTF-8, so we shouldn't reach - // here. - // - // 2) We reached here by someone calling GenerateText() - // on a previously-serialized flatbuffer. The data might have - // non-UTF-8 Strings, or might be corrupt. - // - // In both cases, we have to give up and inform the caller - // they have no JSON. - return false; - } - } else { - if (natural_utf8) { - // utf8 points to past all utf-8 bytes parsed - text.append(s + i, static_cast(utf8 - s - i)); - } else if (ucc <= 0xFFFF) { - // Parses as Unicode within JSON's \uXXXX range, so use that. - text += "\\u"; - text += IntToStringHex(ucc, 4); - } else if (ucc <= 0x10FFFF) { - // Encode Unicode SMP values to a surrogate pair using two \u - // escapes. - uint32_t base = ucc - 0x10000; - auto high_surrogate = (base >> 10) + 0xD800; - auto low_surrogate = (base & 0x03FF) + 0xDC00; - text += "\\u"; - text += IntToStringHex(high_surrogate, 4); - text += "\\u"; - text += IntToStringHex(low_surrogate, 4); - } - // Skip past characters recognized. - i = static_cast(utf8 - s - 1); - } - } - break; - } - } - text += "\""; - return true; -} - -// Remove paired quotes in a string: "text"|'text' -> text. -std::string RemoveStringQuotes(const std::string &s); - -// Change th global C-locale to locale with name . -// Returns an actual locale name in <_value>, useful if locale_name is "" or -// null. -bool SetGlobalTestLocale(const char *locale_name, - std::string *_value = nullptr); - -// Read (or test) a value of environment variable. -bool ReadEnvironmentVariable(const char *var_name, - std::string *_value = nullptr); - -} // namespace flatbuffers - -#endif // FLATBUFFERS_UTIL_H_ diff --git a/src/internal/print_content.hpp b/src/internal/print_content.hpp index 622a294..8c0bef2 100644 --- a/src/internal/print_content.hpp +++ b/src/internal/print_content.hpp @@ -15,7 +15,6 @@ */ #pragma once -#include "include/fb_generated.h" #include "policy.hpp" #include "serialization_traits.hpp" #include "serialized_convert.hpp" diff --git a/src/internal/serialization_backend.hpp b/src/internal/serialization_backend.hpp index 159ae0d..bf02f3b 100644 --- a/src/internal/serialization_backend.hpp +++ b/src/internal/serialization_backend.hpp @@ -25,16 +25,8 @@ #include "serializer_direct.hpp" #include "storage_backend_direct.hpp" -#include "serializer_flatbuffers.hpp" -#include "storage_backend_flatbuffers.hpp" - namespace ldp_serialization { -struct SerializationBackendFlatbuffers { - typedef ldp_serialized::StorageBackendFlatbuffers Storage; - typedef ldp_serializer::SerializerFlatbuffers Serializer; -}; - struct SerializationBackendDirect { typedef ldp_serialized::StorageBackendDirect Storage; typedef ldp_serializer::SerializerDirect Serializer; diff --git a/src/internal/serializer_flatbuffers.cpp b/src/internal/serializer_flatbuffers.cpp deleted file mode 100644 index a253a48..0000000 --- a/src/internal/serializer_flatbuffers.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd 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. -*/ -#include "include/fb_generated.h" -#include "include/flatbuffers/flatbuffers.h" -#include "serializer.hpp" -#include "tslog.hpp" -#include -#include - -using namespace ldp_xml_parser; - -namespace ldp_serializer { - -std::map decisions_map { - { Decision::ANY, FB::Decision_ANY }, - { Decision::DENY, FB::Decision_DENY }, - { Decision::ALLOW, FB::Decision_ALLOW }, - { Decision::CHECK, FB::Decision_CHECK } -}; - -std::map bus_access_map { - { BusAccessType::USER, FB::BusAccessType_USER }, - { BusAccessType::GROUP, FB::BusAccessType_GROUP }, - { BusAccessType::ALL_USERS, FB::BusAccessType_ALL_USERS }, - { BusAccessType::ALL_GROUPS, FB::BusAccessType_ALL_GROUPS }, -}; - -std::map message_type_map { - { MessageType::ANY, FB::MessageType_ANY }, - { MessageType::METHOD_CALL, FB::MessageType_METHOD_CALL }, - { MessageType::METHOD_RETURN, FB::MessageType_METHOD_RETURN }, - { MessageType::ERROR, FB::MessageType_ERROR }, - { MessageType::SIGNAL, FB::MessageType_SIGNAL } -}; - -template <> -struct SerializerFlatbuffers::type_helper { - typedef struct FB::OwnSet set; - typedef struct FB::OwnSetBuilder builder; - typedef struct FB::PolicyOwn policy; - typedef struct FB::PolicyOwnPair pair; - static constexpr auto create_set = &FB::CreateOwnSet; - static constexpr auto create_policy = &FB::CreatePolicyOwn; - static constexpr auto create_policy_pair = &FB::CreatePolicyOwnPair; -}; - -template <> -struct SerializerFlatbuffers::type_helper { - typedef struct FB::SendSet set; - typedef struct FB::SendSetBuilder builder; - typedef struct FB::PolicySend policy; - typedef struct FB::PolicySendPair pair; - typedef struct FB::ItemSend item; - static constexpr auto create_set = &FB::CreateSendSet; - static constexpr auto create_policy = &FB::CreatePolicySend; - static constexpr auto create_policy_pair = &FB::CreatePolicySendPair; - static constexpr auto create_item = &FB::CreateItemSend; -}; - -template <> -struct SerializerFlatbuffers::type_helper { - typedef struct FB::ReceiveSet set; - typedef struct FB::ReceiveSetBuilder builder; - typedef struct FB::PolicyReceive policy; - typedef struct FB::PolicyReceivePair pair; - typedef struct FB::ItemReceive item; - static constexpr auto create_set = &FB::CreateReceiveSet; - static constexpr auto create_policy = &FB::CreatePolicyReceive; - static constexpr auto create_policy_pair = &FB::CreatePolicyReceivePair; - static constexpr auto create_item = &FB::CreateItemReceive; -}; - -template <> -struct SerializerFlatbuffers::type_helper { - typedef struct FB::AccessSet set; - typedef struct FB::AccessSetBuilder builder; - typedef struct FB::PolicyAccess policy; - typedef struct FB::ItemAccess item; - static constexpr auto create_set = &FB::CreateAccessSet; - static constexpr auto create_policy = &FB::CreatePolicyAccess; - static constexpr auto create_item = &FB::CreateItemAccess; -}; - -const uint8_t* SerializerFlatbuffers::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) { - m_db = &db; - - auto own_set = serialize_set(); - auto send_set = serialize_set(); - auto receive_set = serialize_set(); - auto access_set = serialize_set(); - - auto file = FB::CreateFile(m_builder, - own_set, - send_set, - receive_set, - access_set); - - m_builder.Finish(file, FB::FileIdentifier()); - auto buf = m_builder.GetBufferPointer(); - size = m_builder.GetSize(); - - return buf; -} - -template -auto SerializerFlatbuffers::get_create_set() -> decltype(type_helper::create_set) { - return type_helper::create_set; -} - -template -auto SerializerFlatbuffers::get_create_policy() -> decltype(type_helper::create_policy) { - return type_helper::create_policy; -} - -template -auto SerializerFlatbuffers::get_create_policy_pair() -> decltype(type_helper::create_policy_pair) { - return type_helper::create_policy_pair; -} - -template -auto SerializerFlatbuffers::get_create_item() -> decltype(type_helper::create_item) { - return type_helper::create_item; -} - -FbOff SerializerFlatbuffers::serialize_tree(const OwnershipTree &tree) { - auto tree_item = serialize_tree(tree.getRoot()); - auto policy = FB::CreatePolicyOwn(m_builder, tree_item); - - return policy; -} - -FbOff SerializerFlatbuffers::serialize_tree(const std::shared_ptr &node) { - auto prefix_decision_item = serialize_decision(node->getOwnPrefixDecisionItem()); - auto decision_item = serialize_decision(node->getOwnDecisionItem()); - - std::vector> children; - - for (const auto &subnode : node->getChildren()) { - auto child = serialize_tree(subnode.second); - children.push_back(child); - } - - auto policy_own = FB::CreatePolicyOwnNode(m_builder, - m_builder.CreateString(node->getToken()), - prefix_decision_item, - decision_item, - m_builder.CreateVectorOfSortedTables(&children)); - return policy_own; -} - -FbOff SerializerFlatbuffers::serialize_decision(const DecisionItem &item) { - return FB::CreateDecisionItem(m_builder, - decisions_map[item.getDecision()], - m_builder.CreateString(item.getPrivilege())); -} - -template <> -auto SerializerFlatbuffers::serialize_item(const ItemAccess &item) -> FbOff { - auto create_item = get_create_item(); - - return create_item(m_builder, - item.getUid(), - item.getGid(), - serialize_decision(item.getDecision()), - bus_access_map[item.getType()]); -} - -template -auto SerializerFlatbuffers::serialize_item(const P &item) -> FbOff::item> { - auto create_item = get_create_item(); - return create_item(m_builder, - serialize_decision(item.getDecision()), - m_builder.CreateString(item.getName()), - m_builder.CreateString(item.getInterface()), - m_builder.CreateString(item.getMember()), - m_builder.CreateString(item.getPath()), - message_type_map[item.getType()], - item.isNamePrefix()); -} - -template -auto SerializerFlatbuffers::serialize_policy(const std::vector::item>> items) - -> FbOff::policy> { - auto create_policy = get_create_policy(); - return create_policy(m_builder, m_builder.CreateVector(items)); -} - -template <> -auto SerializerFlatbuffers::serialize_policy(const PolicyOwn &policy) - -> FbOff { - return serialize_tree(policy.getTree()); -} - -template <> -auto SerializerFlatbuffers::serialize_policy(const PolicySend &policy) - -> FbOff { - std::vector> items; - - for (const auto &item : policy.getItems()) - items.push_back(serialize_item(item)); - - // serialize main index - std::vector> index; - - for (auto &it: policy.getIndex()) - index.push_back(FB::CreateNameScoresPairDirect(m_builder, - it.first.data(), // name - it.second.m_bestScore, // best_score - &it.second.m_itemRefs)); // vector of scores/ids - - return FB::CreatePolicySend(m_builder, - m_builder.CreateVector(items), - m_builder.CreateVector(index), - m_builder.CreateVector(policy.getPrefixIndex())); -} - -template -auto SerializerFlatbuffers::serialize_policy(const T &policy) -> FbOff::policy> { - std::vector::item>> items; - - for (const auto &item : policy.getItems()) { - items.push_back(serialize_item(item)); - } - - return serialize_policy(items); -} - -template -auto SerializerFlatbuffers::serialize_pair(const long int id, const P policy) - -> FbOff::pair> { - auto create_policy_pair = get_create_policy_pair(); - return create_policy_pair(m_builder, id, serialize_policy(policy)); -} - -template -auto SerializerFlatbuffers::serialize_set() -> FbOff::set> { - auto context_default = serialize_policy(m_db->getPolicyContextDefault()); - auto context_mandatory = serialize_policy(m_db->getPolicyContextMandatory()); - - return serialize_set(context_default, context_mandatory); -} - -template <> -auto SerializerFlatbuffers::serialize_set(FbOff context_default, - FbOff context_mandatory) - -> FbOff::set> -{ - return FB::CreateAccessSet(m_builder, context_default, context_mandatory); -} - -template -auto SerializerFlatbuffers::serialize_set(FbOff context_default, - FbOff context_mandatory) - -> FbOff::set> -{ - std::vector::pair>> user; - std::vector::pair>> group; - std::vector uid; - std::vector gid; - - for (const auto &u : m_db->getPoliciesUser()) - user.push_back(serialize_pair(u.first, u.second)); - - for (const auto &g : m_db->getPoliciesGroup()) - group.push_back(serialize_pair(g.first, g.second)); - - auto func = get_create_set(); - return func(m_builder, context_default, context_mandatory, - m_builder.CreateVectorOfSortedTables(&user), - m_builder.CreateVectorOfSortedTables(&group)); -} - -} diff --git a/src/internal/serializer_flatbuffers.hpp b/src/internal/serializer_flatbuffers.hpp deleted file mode 100644 index c240870..0000000 --- a/src/internal/serializer_flatbuffers.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd 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. -*/ -#ifndef _SERIALIZER_HPP -#define _SERIALIZER_HPP - -#include -#include -#include - -#include "include/flatbuffers/flatbuffers.h" -#include "include/fb_generated.h" - -#include "storage_backend_xml.hpp" -#include "policy_containers.hpp" - -namespace ldp_serializer -{ - template - using FbOff = flatbuffers::Offset; - - class SerializerFlatbuffers { - private: - template - struct type_helper; - - const ldp_xml::StorageBackendXML *m_db; - flatbuffers::FlatBufferBuilder m_builder; - - template - auto get_create_set() -> decltype(type_helper::create_set); - template - auto get_create_policy() -> decltype(type_helper::create_policy); - template - auto get_create_policy_pair() -> decltype(type_helper::create_policy_pair); - template - auto get_create_item() -> decltype(type_helper::create_item); - - FbOff serialize_tree(const ldp_xml_parser::OwnershipTree &tree); - FbOff serialize_tree(const std::shared_ptr &node); - FbOff serialize_decision(const ldp_xml_parser::DecisionItem &item); - - template - auto serialize_item(const P &item) -> FbOff::item>; - - template - auto serialize_policy(const T &policy) -> FbOff::policy>; - - template - auto serialize_policy(const std::vector::item>> items) - -> FbOff::policy>; - - template - auto serialize_pair(const long int id, const P policy) - -> FbOff::pair>; - - template - auto serialize_set() -> FbOff::set>; - - template - auto serialize_set(FbOff context_default, - FbOff context_mandatory) - -> FbOff::set>; - public: - SerializerFlatbuffers() : m_db(nullptr) {} - const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size); - }; -} - - -#endif diff --git a/src/internal/storage_backend_flatbuffers.cpp b/src/internal/storage_backend_flatbuffers.cpp deleted file mode 100644 index f2a5bec..0000000 --- a/src/internal/storage_backend_flatbuffers.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd 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. -*/ -#include "storage_backend_flatbuffers.hpp" - -using namespace FB; -using ldp_xml_parser::MatchItemSend; - -namespace ldp_serialized { - -namespace { - -const unsigned int FB_ID_OFFSET = 4; -const unsigned int FB_ID_SIZE = 4; - -} // anonymous namespace - -void StorageBackendFlatbuffers::release() { - file = nullptr; -} - -bool StorageBackendFlatbuffers::initFromData(const uint8_t *mem, size_t size, bool verify) { - assert(nullptr == file); - - if (verify) { - auto verifier = flatbuffers::Verifier(mem, size); - if (!FB::VerifyFileBuffer(verifier) || !FB::FileBufferHasIdentifier(mem)) { - char fid[FB_ID_SIZE + 1] = {0, }; - strncpy(fid, (const char *)(mem + FB_ID_OFFSET), FB_ID_SIZE); - - if (strcmp(fid, "LDP1") == 0) { - tslog::log_error("verification of serialized data: not available\n"); - tslog::log_error("header ID : ", FB::FileIdentifier(), "\n"); - tslog::log_error("serialized data ID : ", fid, "\n"); - } else { - tslog::log_error("verification of serialized data: failed\n"); - return false; - } - } - } - - file = GetFile(mem); - return file != nullptr; -} - -} diff --git a/src/internal/storage_backend_flatbuffers.hpp b/src/internal/storage_backend_flatbuffers.hpp deleted file mode 100644 index 7d1e4f0..0000000 --- a/src/internal/storage_backend_flatbuffers.hpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd 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. -*/ -#pragma once - -#include "include/fb_generated.h" -#include "policy.hpp" -#include "serialization_traits.hpp" -#include - -namespace ldp_serialized { - -class StorageBackendFlatbuffers { -public: - bool initFromData(const uint8_t *serialized_data, size_t length, bool verify); - void release(); - - const FB::File *getFile() const - { return file; } - - auto fileGetOwnSet(const FB::File *file) const - { return file->m_own_set(); } - auto fileGetSendSet(const FB::File *file) const - { return file->m_send_set(); } - auto fileGetReceiveSet(const FB::File *file) const - { return file->m_receive_set(); } - auto fileGetAccessSet(const FB::File *file) const - { return file->m_access_set(); } - - template - auto setGetContextDefault(const Set *set) const - { return set->context_default(); } - - template - auto setGetContextMandatory(const Set *set) const - { return set->context_mandatory(); } - - template - auto setGetUser(const Set *set) const - { return set->user(); } - - template - auto setGetGroup(const Set *set) const - { return set->group(); } - - template - auto setUserGroupGetId(const SetUserGroup *set_user_group) const - { return set_user_group->id(); } - - template - auto setUserGroupGetPolicy(const SetUserGroup *set_user_group) const - { return set_user_group->policy(); } - - template - auto policyGetTree(const Policy *policy) const - { return policy->tree(); } - - template - auto policyGetItems(const Policy *policy) const - { return policy->items(); } - - template - auto policyHasIndex(const Policy *policy) const - { return policy->index() != nullptr && policy->index()->size() > 0; } - - template - auto policyGetIndex(const Policy *policy) const - { return policy->index(); } - - template - auto policyGetPrefixIndex(const Policy *policy) const - { return policy->prefix_index(); } - - auto policyIndexGetName(const FB::NameScoresPair *p) const - { return p->name(); } - - auto policyIndexGetBestScore(const FB::NameScoresPair *p) const - { return p->best_score(); } - - auto policyIndexGetItemRefs(const FB::NameScoresPair *p) const - { return p->item_refs(); } - - template - auto containerGetReverseIterator(const Container *container) const - { return container->rbegin(); } - - template - auto containerGetReverseIteratorEnd(const Container *container) const - { return container->rend(); } - - template - auto containerGetIterator(const Container *container) const - { return container->begin(); } - - template - auto containerGetIteratorEnd(const Container *container) const - { return container->end(); } - - template - auto containerGetSize(const Container *container) const - { return container->size(); } - - template - auto containerLookupByIndex(const Container *container, size_t index) const - { return container->Get(index); } - - template - auto containerEmpty(const Container *container) const - { return container->size() == 0; } - - template - auto containerLookupByKey(const Container *container, Key key) const { - auto elem = container->LookupByKey(key); - return std::make_pair(elem != nullptr, elem); - } - - auto decisionItemGetDecision(const FB::DecisionItem *item) const - { return item->decision(); } - - auto decisionItemGetPrivilege(const FB::DecisionItem *item) const - { return item->privilege(); } - - auto ownNodeGetToken(const FB::PolicyOwnNode *node) const - { return node->token(); } - - auto ownNodeGetDecisionItem(const FB::PolicyOwnNode *node) const - { return node->decision_item(); } - - auto ownNodeGetPrefixDecisionItem(const FB::PolicyOwnNode *node) const - { return node->prefix_decision_item(); } - - auto ownNodeGetChildren(const FB::PolicyOwnNode *node) const - { return node->children(); } - - auto itemAccessGetType(const FB::ItemAccess *item) const - { return item->type(); } - - auto itemAccessGetUid(const FB::ItemAccess *item) const - { return item->uid(); } - - auto itemAccessGetGid(const FB::ItemAccess *item) const - { return item->gid(); } - - template - auto itemSrGetName(const ItemSR *item) const - { return item->name(); } - - template - auto itemSrGetIsNamePrefix(const ItemSR *item) const - { return item->is_name_prefix(); } - - template - auto itemSrGetInterface(const ItemSR *item) const - { return item->interface(); } - - template - auto itemSrGetMember(const ItemSR *item) const - { return item->member(); } - - template - auto itemSrGetPath(const ItemSR *item) const - { return item->path(); } - - template - auto itemSrGetMessageType(const ItemSR *item) const - { return item->type(); } - - template - auto itemGetDecisionItem(const Item *item) const - { return item->decision(); } - - const char *stringGetCStr(const flatbuffers::String *str) const - { return str->c_str(); } - - size_t stringGetSize(const flatbuffers::String *str) const - { return str->size(); } - -private: - const FB::File *file{nullptr}; -}; - -} - -namespace ldp_serialization { -template <> struct HasUserGroup -{ typedef std::true_type result; }; -template <> struct HasUserGroup -{ typedef std::true_type result; }; -template <> struct HasUserGroup -{ typedef std::true_type result; }; -template <> struct HasUserGroup -{ typedef std::false_type result; }; - -template <> struct PolicyContentType -{ typedef TreeType result; }; -template <> struct PolicyContentType -{ typedef ItemsType result; }; -template <> struct PolicyContentType -{ typedef ItemsType result; }; -template <> struct PolicyContentType -{ typedef ItemsType result; }; - -template <> struct PolicyHasIndex -{ typedef std::true_type result; }; - -template <> struct ItemType -{ typedef SendType result; }; -template <> struct ItemType -{ typedef ReceiveType result; }; -template <> struct ItemType -{ typedef AccessType result; }; -} diff --git a/src/stest_load_perf.cpp b/src/stest_load_perf.cpp index 55c97af..e9c5d6a 100644 --- a/src/stest_load_perf.cpp +++ b/src/stest_load_perf.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" @@ -29,6 +28,7 @@ #include "internal/tslog.hpp" #include "libdbuspolicy1-private.h" #include +#include #include #include #include @@ -66,13 +66,8 @@ bool run_xml_plus_fb(const char *conf_file, bool verify) { size_t size; auto buff = serializer.serialize(conf_file, size); - if (verify) { - auto verifier = flatbuffers::Verifier(buff, size); - if (!FB::VerifyFileBuffer(verifier)) { - std::cout << "verification of serialized data: failed" << std::endl; - return false; - } - } + if (verify) + std::cerr << "verification not supported at the moment" << std::endl; StorageBackendSerialized storage; return storage.initFromData(buff, size); @@ -90,12 +85,12 @@ void run_tests(const char *conf_file, const char *conf_bin, size_t c, Choice ch, } } if (ch == Choice::ALL || ch == Choice::FB) { - if (!measure([&conf_bin, c, verify]() { return run_fb(conf_bin, verify); }, c, "FB")) { + if (!measure([&conf_bin, c, verify]() { return run_fb(conf_bin, verify); }, c, "Serialized")) { std::cout << "ERROR" << std::endl; } } if (ch == Choice::ALL || ch == Choice::XMLplusFB) - if (!measure([&conf_file, c, verify]() { return run_xml_plus_fb(conf_file, verify); }, c, "FB after XML")) { + if (!measure([&conf_file, c, verify]() { return run_xml_plus_fb(conf_file, verify); }, c, "Serialized after XML")) { std::cout << "ERROR" << std::endl; } } @@ -104,9 +99,9 @@ void print_help(const char *name) { std::cout << std::endl; std::cout << "usage: " << name << " {-f |-x|-d|-a } {--system|--session|-c } " << std::endl; std::cout << std::endl; - std::cout << " -f - Flatbuffers" << std::endl; + std::cout << " -f - Serialized" << std::endl; std::cout << " -x - XML" << std::endl; - std::cout << " -d - FB after XML" << std::endl; + std::cout << " -d - Serialized after XML" << std::endl; std::cout << " -a - All tests" << std::endl; std::cout << " -v - Verify" << std::endl; std::cout << std::endl; diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 8d96316..1fe6635 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" @@ -28,6 +27,7 @@ #include "internal/storage_backend_serialized.hpp" #include "internal/tslog.hpp" #include "libdbuspolicy1-private.h" +#include #include #include #include @@ -213,13 +213,8 @@ void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { size_t size; auto buff = serializer.serialize(conf_file, size); - if (verify) { - auto verifier = flatbuffers::Verifier(buff, size); - if (!FB::VerifyFileBuffer(verifier)) { - std::cout << "verification of serialized data: failed" << std::endl; - return; - } - } + if (verify) + std::cerr << "verification not supported at the moment" << std::endl; StorageBackendSerialized storage; storage.initFromData(buff, size); diff --git a/src/test-libdbuspolicy1-access-deny-gdi.cpp b/src/test-libdbuspolicy1-access-deny-gdi.cpp index 515959a..fba4a8b 100644 --- a/src/test-libdbuspolicy1-access-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-access-deny-gdi.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" diff --git a/src/test-libdbuspolicy1-method-gdi.cpp b/src/test-libdbuspolicy1-method-gdi.cpp index eb3b79d..e9d12be 100644 --- a/src/test-libdbuspolicy1-method-gdi.cpp +++ b/src/test-libdbuspolicy1-method-gdi.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" diff --git a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp index c6ea773..85ceeb6 100644 --- a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" diff --git a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp index e42095f..b23e9d1 100644 --- a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" diff --git a/src/test-libdbuspolicy1-signal-gdi.cpp b/src/test-libdbuspolicy1-signal-gdi.cpp index 1627821..71f6d3b 100644 --- a/src/test-libdbuspolicy1-signal-gdi.cpp +++ b/src/test-libdbuspolicy1-signal-gdi.cpp @@ -20,7 +20,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "internal/include/fb_generated.h" #include "internal/naive_policy_checker.hpp" #include "internal/policy.hpp" #include "internal/serializer.hpp" -- 2.7.4 From cdaf39ced4a983e3915e331267598921cd04a6ea Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 29 Oct 2020 09:23:33 +0100 Subject: [PATCH 02/16] license: eliminate dual-licensing in favor of MIT Change-Id: If1cddafdf0f25c7e42120d0ddec1897bf079f4b3 --- LICENSE.APACHE2.0 | 205 ---------------------------------- packaging/libdbuspolicy.spec | 14 +-- src/dbuspolicy1/libdbuspolicy1.h | 30 +++-- src/dbuspolicy_finder.cpp | 30 +++-- src/internal/array_with_size.hpp | 30 +++-- src/internal/bus_names_array.hpp | 30 +++-- src/internal/cynara.cpp | 30 +++-- src/internal/cynara.hpp | 30 +++-- src/internal/cynara_mockup.cpp | 30 +++-- src/internal/global_nodestruct.hpp | 30 +++-- src/internal/groups_mockup.cpp | 30 +++-- src/internal/groups_proxy.cpp | 30 +++-- src/internal/groups_proxy.hpp | 30 +++-- src/internal/naive_policy_checker.cpp | 30 +++-- src/internal/naive_policy_checker.hpp | 30 +++-- src/internal/own_tree.cpp | 30 +++-- src/internal/own_tree.hpp | 30 +++-- src/internal/policy.cpp | 30 +++-- src/internal/policy.hpp | 30 +++-- src/internal/policy_containers.hpp | 30 +++-- src/internal/print_content.cpp | 30 +++-- src/internal/print_content.hpp | 30 +++-- src/internal/serialized_convert.hpp | 30 +++-- src/internal/storage_backend_xml.cpp | 30 +++-- src/internal/storage_backend_xml.hpp | 30 +++-- src/internal/transaction_guard.hpp | 30 +++-- src/internal/tslog.cpp | 30 +++-- src/internal/tslog.hpp | 30 +++-- src/internal/xml_parser.cpp | 30 +++-- src/internal/xml_parser.hpp | 30 +++-- src/kdbus.cpp | 30 +++-- src/kdbus.h | 30 +++-- src/libdbuspolicy1-private.h | 30 +++-- src/libdbuspolicy1.cpp | 30 +++-- src/test_runner.c | 29 +++-- src/test_runner.h | 29 +++-- 36 files changed, 617 insertions(+), 620 deletions(-) delete mode 100644 LICENSE.APACHE2.0 diff --git a/LICENSE.APACHE2.0 b/LICENSE.APACHE2.0 deleted file mode 100644 index 8aa906c..0000000 --- a/LICENSE.APACHE2.0 +++ /dev/null @@ -1,205 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. - - - diff --git a/packaging/libdbuspolicy.spec b/packaging/libdbuspolicy.spec index e7c3c75..ee4d148 100644 --- a/packaging/libdbuspolicy.spec +++ b/packaging/libdbuspolicy.spec @@ -1,6 +1,6 @@ Name: libdbuspolicy Summary: Helper library for fine-grained userspace policy handling -License: Apache-2.0, MIT +License: MIT Group: Base/IPC Version: 1.1.0 Release: 0 @@ -124,13 +124,13 @@ mv %{_unitdir}/.%{name}.backup.default.target %{_unitdir}/default.target %files %manifest %{name}.manifest -%license LICENSE.APACHE2.0 LICENSE.MIT +%license LICENSE.MIT %defattr(-,root,root) %{_libdir}/libdbuspolicy1.so.* %files devel %manifest %{name}.manifest -%license LICENSE.APACHE2.0 LICENSE.MIT +%license LICENSE.MIT %defattr(-,root,root) %{_includedir}/* %{_libdir}/pkgconfig/* @@ -138,7 +138,7 @@ mv %{_unitdir}/.%{name}.backup.default.target %{_unitdir}/default.target %files serializer %manifest %{name}.manifest -%license LICENSE.APACHE2.0 LICENSE.MIT +%license LICENSE.MIT %defattr(-,root,root) %{_bindir}/dbuspolicy-serializer %{_bindir}/dbuspolicy-printer @@ -146,21 +146,21 @@ mv %{_unitdir}/.%{name}.backup.default.target %{_unitdir}/default.target %files assert-data-valid %manifest %{name}.manifest -%license LICENSE.APACHE2.0 LICENSE.MIT +%license LICENSE.MIT %{_unitdir}/libdbuspolicy-verify-data.target %{_unitdir}/libdbuspolicy-verify-data.service %{_bindir}/dbuspolicy-verifier %if 0%{?enable_doxygen:1} %files doc -%license LICENSE.APACHE2.0 LICENSE.MIT +%license LICENSE.MIT %defattr(-,root,root) %{_datadir}/doc/dbuspolicy/* %endif %changelog %files tests -%license LICENSE.APACHE2.0 LICENSE.MIT +%license LICENSE.MIT %defattr(-,root,root) %{testrunnerdir}/%{runnername} %{testsuitedir}/* diff --git a/src/dbuspolicy1/libdbuspolicy1.h b/src/dbuspolicy1/libdbuspolicy1.h index 056d91b..c458b3d 100644 --- a/src/dbuspolicy1/libdbuspolicy1.h +++ b/src/dbuspolicy1/libdbuspolicy1.h @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** API usually used in libdbus/libglib. \defgroup API API */ diff --git a/src/dbuspolicy_finder.cpp b/src/dbuspolicy_finder.cpp index 7089ed0..57db881 100644 --- a/src/dbuspolicy_finder.cpp +++ b/src/dbuspolicy_finder.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. - */ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "internal/policy_containers.hpp" #include "internal/print_content.hpp" #include "internal/storage_backend_xml.hpp" diff --git a/src/internal/array_with_size.hpp b/src/internal/array_with_size.hpp index e8f7220..e057d36 100644 --- a/src/internal/array_with_size.hpp +++ b/src/internal/array_with_size.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include diff --git a/src/internal/bus_names_array.hpp b/src/internal/bus_names_array.hpp index fee3064..35759aa 100644 --- a/src/internal/bus_names_array.hpp +++ b/src/internal/bus_names_array.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include "array_with_size.hpp" diff --git a/src/internal/cynara.cpp b/src/internal/cynara.cpp index 44590c3..dfa64f7 100644 --- a/src/internal/cynara.cpp +++ b/src/internal/cynara.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "cynara.hpp" #include #include diff --git a/src/internal/cynara.hpp b/src/internal/cynara.hpp index fe8bb37..3802d72 100644 --- a/src/internal/cynara.hpp +++ b/src/internal/cynara.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #ifndef _CYNARA_HPP #define _CYNARA_HPP diff --git a/src/internal/cynara_mockup.cpp b/src/internal/cynara_mockup.cpp index 1c63894..0ff9fd3 100644 --- a/src/internal/cynara_mockup.cpp +++ b/src/internal/cynara_mockup.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "cynara.hpp" #include #include diff --git a/src/internal/global_nodestruct.hpp b/src/internal/global_nodestruct.hpp index fc89577..217f500 100644 --- a/src/internal/global_nodestruct.hpp +++ b/src/internal/global_nodestruct.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file diff --git a/src/internal/groups_mockup.cpp b/src/internal/groups_mockup.cpp index 99baa9c..fae3363 100644 --- a/src/internal/groups_mockup.cpp +++ b/src/internal/groups_mockup.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "groups_proxy.hpp" #include diff --git a/src/internal/groups_proxy.cpp b/src/internal/groups_proxy.cpp index 1ed0453..f90e22e 100644 --- a/src/internal/groups_proxy.cpp +++ b/src/internal/groups_proxy.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "groups_proxy.hpp" #include "tslog.hpp" #include diff --git a/src/internal/groups_proxy.hpp b/src/internal/groups_proxy.hpp index 9d2d715..9421d5d 100644 --- a/src/internal/groups_proxy.hpp +++ b/src/internal/groups_proxy.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2018 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file diff --git a/src/internal/naive_policy_checker.cpp b/src/internal/naive_policy_checker.cpp index 4e5b634..de76ca3 100644 --- a/src/internal/naive_policy_checker.cpp +++ b/src/internal/naive_policy_checker.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "cynara.hpp" #include "groups_proxy.hpp" #include "naive_policy_checker.hpp" diff --git a/src/internal/naive_policy_checker.hpp b/src/internal/naive_policy_checker.hpp index 8edc55b..2905659 100644 --- a/src/internal/naive_policy_checker.hpp +++ b/src/internal/naive_policy_checker.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file diff --git a/src/internal/own_tree.cpp b/src/internal/own_tree.cpp index 5eecc06..efe9d4c 100644 --- a/src/internal/own_tree.cpp +++ b/src/internal/own_tree.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2018-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "own_tree.hpp" #include #include diff --git a/src/internal/own_tree.hpp b/src/internal/own_tree.hpp index b65be39..ddc6528 100644 --- a/src/internal/own_tree.hpp +++ b/src/internal/own_tree.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2018-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** diff --git a/src/internal/policy.cpp b/src/internal/policy.cpp index 7815a47..bb4f93e 100644 --- a/src/internal/policy.cpp +++ b/src/internal/policy.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file * \ingroup Implementation diff --git a/src/internal/policy.hpp b/src/internal/policy.hpp index 71fd8ae..9dc7391 100644 --- a/src/internal/policy.hpp +++ b/src/internal/policy.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** diff --git a/src/internal/policy_containers.hpp b/src/internal/policy_containers.hpp index f61473a..566a418 100644 --- a/src/internal/policy_containers.hpp +++ b/src/internal/policy_containers.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include "policy.hpp" diff --git a/src/internal/print_content.cpp b/src/internal/print_content.cpp index 0264e9a..0f19b58 100644 --- a/src/internal/print_content.cpp +++ b/src/internal/print_content.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "policy.hpp" #include "print_content.hpp" #include "serialized_convert.hpp" diff --git a/src/internal/print_content.hpp b/src/internal/print_content.hpp index 8c0bef2..dab435a 100644 --- a/src/internal/print_content.hpp +++ b/src/internal/print_content.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include "policy.hpp" diff --git a/src/internal/serialized_convert.hpp b/src/internal/serialized_convert.hpp index 5d0b8af..c2830d0 100644 --- a/src/internal/serialized_convert.hpp +++ b/src/internal/serialized_convert.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include "policy.hpp" diff --git a/src/internal/storage_backend_xml.cpp b/src/internal/storage_backend_xml.cpp index 69ecf21..dd6f255 100644 --- a/src/internal/storage_backend_xml.cpp +++ b/src/internal/storage_backend_xml.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "policy_containers.hpp" #include "print_content.hpp" #include "storage_backend_xml.hpp" diff --git a/src/internal/storage_backend_xml.hpp b/src/internal/storage_backend_xml.hpp index 46b50f1..7f1caf8 100644 --- a/src/internal/storage_backend_xml.hpp +++ b/src/internal/storage_backend_xml.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include "policy.hpp" diff --git a/src/internal/transaction_guard.hpp b/src/internal/transaction_guard.hpp index 9df2600..c6e0a57 100644 --- a/src/internal/transaction_guard.hpp +++ b/src/internal/transaction_guard.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once #include diff --git a/src/internal/tslog.cpp b/src/internal/tslog.cpp index 9cea129..1f55074 100644 --- a/src/internal/tslog.cpp +++ b/src/internal/tslog.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file * \ingroup Implementation diff --git a/src/internal/tslog.hpp b/src/internal/tslog.hpp index f028601..d52e62b 100644 --- a/src/internal/tslog.hpp +++ b/src/internal/tslog.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file * \ingroup Implementation diff --git a/src/internal/xml_parser.cpp b/src/internal/xml_parser.cpp index 4bcbb1d..b5158fd 100644 --- a/src/internal/xml_parser.cpp +++ b/src/internal/xml_parser.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** return a; * \file diff --git a/src/internal/xml_parser.hpp b/src/internal/xml_parser.hpp index 0b91633..1da41c3 100644 --- a/src/internal/xml_parser.hpp +++ b/src/internal/xml_parser.hpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ /** * \file * \ingroup Implementation diff --git a/src/kdbus.cpp b/src/kdbus.cpp index 32e3257..c0cbe0e 100644 --- a/src/kdbus.cpp +++ b/src/kdbus.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * 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 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * http://www.apache.org/licenses/LICENSE-2.0 + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. * - * 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. -*/ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "kdbus.h" #include "internal/tslog.hpp" diff --git a/src/kdbus.h b/src/kdbus.h index 567b4e8..f3b637c 100644 --- a/src/kdbus.h +++ b/src/kdbus.h @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once diff --git a/src/libdbuspolicy1-private.h b/src/libdbuspolicy1-private.h index 3bea979..29f4ac3 100644 --- a/src/libdbuspolicy1-private.h +++ b/src/libdbuspolicy1-private.h @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License * - * 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 + * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * 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. -*/ + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #ifndef _LIBDBUSPOLICY1_PRIVATE_H_ #define _LIBDBUSPOLICY1_PRIVATE_H_ diff --git a/src/libdbuspolicy1.cpp b/src/libdbuspolicy1.cpp index e1975f8..514354a 100644 --- a/src/libdbuspolicy1.cpp +++ b/src/libdbuspolicy1.cpp @@ -1,18 +1,24 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +/* MIT License + * + * Copyright (c) 2015-2020 Samsung Electronics Co., Ltd * - * 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 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * http://www.apache.org/licenses/LICENSE-2.0 + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. * - * 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. -*/ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include "internal/naive_policy_checker.hpp" diff --git a/src/test_runner.c b/src/test_runner.c index 9e9dbe0..0e61555 100644 --- a/src/test_runner.c +++ b/src/test_runner.c @@ -1,20 +1,25 @@ -/* This file contains test-runner for libdbuspolicy +/* MIT License * - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd * Author: Kazimierz Krosman * - * 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 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * http://www.apache.org/licenses/LICENSE-2.0 + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. * - * 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. -*/ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #include #include diff --git a/src/test_runner.h b/src/test_runner.h index 14f8ec0..4a3e717 100644 --- a/src/test_runner.h +++ b/src/test_runner.h @@ -1,20 +1,25 @@ -/* This file is part of test-runner (see template.c) +/* MIT License * - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2018 Samsung Electronics Co., Ltd * Author: Kazimierz Krosman * - * 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 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * http://www.apache.org/licenses/LICENSE-2.0 + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. * - * 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. -*/ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #ifndef TEST_RUNNER_H #define TEST_RUNNER_H -- 2.7.4 From bf74e4e0524dc0c525340aad3c688e6bf8dadf43 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 3 Nov 2020 10:42:17 +0100 Subject: [PATCH 03/16] serialization: add simple file verification method Change-Id: I95d3501bcfffa0e4601ee2c3738b38c41b366a44 --- src/internal/serializer_direct.cpp | 4 +++- src/internal/storage_backend_direct.cpp | 22 +++++++++++++++++++++- src/internal/storage_backend_direct.hpp | 7 +++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/internal/serializer_direct.cpp b/src/internal/serializer_direct.cpp index d74ce9b..d90387e 100644 --- a/src/internal/serializer_direct.cpp +++ b/src/internal/serializer_direct.cpp @@ -24,6 +24,7 @@ #include "serialization_traits.hpp" #include "serialized.hpp" #include "serializer_direct.hpp" +#include "storage_backend_direct.hpp" using namespace ldp_serializer; using ldp_serializer::Serialized; @@ -154,7 +155,8 @@ const uint8_t *SerializerDirectImpl::serialize(size_t &size) { serializeSet(), serializeSet(), serializeSet(), - serializeSet()}; + serializeSet(), + ldp_serialized::StorageBackendDirect::currentDbVersion}; size = r.size(); return r.releaseData(); diff --git a/src/internal/storage_backend_direct.cpp b/src/internal/storage_backend_direct.cpp index 455f443..5628b52 100644 --- a/src/internal/storage_backend_direct.cpp +++ b/src/internal/storage_backend_direct.cpp @@ -20,12 +20,32 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "tslog.hpp" #include "storage_backend_direct.hpp" +#include using namespace ldp_serialized; -bool StorageBackendDirect::initFromData(const uint8_t *mem, size_t , bool ) { +const boost::string_ref StorageBackendDirect::currentDbVersion{"Libdbuspolicy direct serialization database, v. 1.0"}; +bool StorageBackendDirect::initFromData(const uint8_t *mem, size_t size, bool verify) { + assert(mem); file = reinterpret_cast(mem); + + if (verify) { + bool verified = false; + auto end = mem + size; + auto version = fileGetDbVersion(file); + auto version_uint8 = reinterpret_cast(version); + if (version_uint8 < end) { + auto s = stringGetSize(version); + if (version_uint8 + s < end) + verified = currentDbVersion == stringGetCStr(version); + } + + if (!verified) + file = nullptr; + } + return file != nullptr; } diff --git a/src/internal/storage_backend_direct.hpp b/src/internal/storage_backend_direct.hpp index 4b3b47b..7afb1f7 100644 --- a/src/internal/storage_backend_direct.hpp +++ b/src/internal/storage_backend_direct.hpp @@ -122,6 +122,7 @@ namespace ldp_serialized { * } * } * } + * db_version: string; * * define DecisionItem = { * decision: Decision; @@ -371,6 +372,8 @@ public: { return ptr(2); } const auto *getAccessSet() const { return ptr(3); } + const auto *getDbVersion() const + { return ptr(4); } }; class StorageBackendDirect { @@ -398,6 +401,8 @@ class StorageBackendDirect { return std::make_pair(false, *container->begin()); } public: + static const boost::string_ref currentDbVersion; + bool initFromData(const uint8_t *serialized_data, size_t size, bool verify = false); void release() {} @@ -412,6 +417,8 @@ public: { return file->getReceiveSet(); } auto fileGetAccessSet(const File *file) const { return file->getAccessSet(); } + auto fileGetDbVersion(const File *file) const + { return file->getDbVersion(); } template auto setGetContextDefault(const Set *set) const -- 2.7.4 From 1cc49dae88d9682c5d2dd4119b26630e1805470d Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 13 Nov 2020 13:29:16 +0100 Subject: [PATCH 04/16] Release 1.2.0 Replacing flatbuffers with own serializer really deserves separate version. Change-Id: Ibbcd300c29f3cbc30f6dcede7a346c421f1f31c4 --- packaging/libdbuspolicy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libdbuspolicy.spec b/packaging/libdbuspolicy.spec index ee4d148..5178a71 100644 --- a/packaging/libdbuspolicy.spec +++ b/packaging/libdbuspolicy.spec @@ -2,7 +2,7 @@ Name: libdbuspolicy Summary: Helper library for fine-grained userspace policy handling License: MIT Group: Base/IPC -Version: 1.1.0 +Version: 1.2.0 Release: 0 Source: %{name}-%{version}.tar.gz Source1001: %{name}.manifest -- 2.7.4 From 4d2a744873ec916472f530c0f68c6ca2754ba772 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 1 Dec 2020 14:59:44 +0100 Subject: [PATCH 05/16] refactoring: inline StorageBackendSerialized private methods Change-Id: I0483dceef8afa5ec4d160e6a1a785142490fb01a --- src/internal/storage_backend_serialized.cpp | 28 ++++++++++++++-------------- src/internal/storage_backend_serialized.hpp | 26 +++++++++++++------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index ac3c5bc..53d76dc 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -126,35 +126,35 @@ void StorageBackendSerialized::release() { impl.release(); } -template <> auto StorageBackendSerialized::getPolicySet() const { +template <> inline auto StorageBackendSerialized::getPolicySet() const { return impl.fileGetOwnSet(impl.getFile()); } -template <> auto StorageBackendSerialized::getPolicySet() const { +template <> inline auto StorageBackendSerialized::getPolicySet() const { return impl.fileGetSendSet(impl.getFile()); } -template <> auto StorageBackendSerialized::getPolicySet() const { +template <> inline auto StorageBackendSerialized::getPolicySet() const { return impl.fileGetReceiveSet(impl.getFile()); } -template <> auto StorageBackendSerialized::getPolicySet() const { +template <> inline auto StorageBackendSerialized::getPolicySet() const { return impl.fileGetAccessSet(impl.getFile()); } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::makeDecisionItem(const DI &item) const { +inline ldp_xml_parser::DecisionItem StorageBackendSerialized::makeDecisionItem(const DI &item) const { return ldp_xml_parser::DecisionItem(makeDecision(impl.decisionItemGetDecision(item)), impl.stringGetCStr(impl.decisionItemGetPrivilege(item))); } template -boost::string_ref StorageBackendSerialized::toStringRef(const String &str) const { +inline boost::string_ref StorageBackendSerialized::toStringRef(const String &str) const { return boost::string_ref(impl.stringGetCStr(str), impl.stringGetSize(str)); } template -bool StorageBackendSerialized::match(const T &match, const I &item) const { +inline bool StorageBackendSerialized::match(const T &match, const I &item) const { return match.match(makeMessageType(impl.itemSrGetMessageType(item)), toStringRef(impl.itemSrGetInterface(item)), toStringRef(impl.itemSrGetPath(item)), @@ -165,12 +165,12 @@ bool StorageBackendSerialized::match(const T &match, const I &item) const { } template -bool StorageBackendSerialized::match(const ldp_xml_parser::MatchItemAccess &match, const I &item) const { +inline bool StorageBackendSerialized::match(const ldp_xml_parser::MatchItemAccess &match, const I &item) const { return match.match(makeBusAccessType(impl.itemAccessGetType(item)), impl.itemAccessGetUid(item), impl.itemAccessGetGid(item)); } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T &item, const P &policy, ldp_serialization::ItemsType) const { +inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T &item, const P &policy, ldp_serialization::ItemsType) const { auto v = impl.policyGetItems(policy); auto rend = impl.containerGetReverseIteratorEnd(v); for (auto rit = impl.containerGetReverseIterator(v); rit != rend; ++rit) { @@ -181,7 +181,7 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T & } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const ldp_xml_parser::MatchItemSend &item, const P &policy) const { +inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const ldp_xml_parser::MatchItemSend &item, const P &policy) const { if (!impl.policyHasIndex(policy)) return getDecisionItem(item, policy, ldp_serialization::ItemsType()); // make it old way for old databases @@ -255,7 +255,7 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const ldp } template -auto StorageBackendSerialized::getDecisionItemFromTree(const OwnNode &node, +inline auto StorageBackendSerialized::getDecisionItemFromTree(const OwnNode &node, const tokenizer::iterator &tokens_end, tokenizer::iterator &iterator) const { if (iterator == tokens_end) { @@ -283,7 +283,7 @@ auto StorageBackendSerialized::getDecisionItemFromTree(const OwnNode &node, } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T &item, const P &policy, ldp_serialization::TreeType) const { +inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T &item, const P &policy, ldp_serialization::TreeType) const { if (item.getName().length() == 0) return ldp_xml_parser::Decision::DENY; @@ -296,7 +296,7 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T & } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T &item, const P &policy) const { +inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const T &item, const P &policy) const { return getDecisionItem(item, policy, typename ldp_serialization::PolicyContentType

::result()); } @@ -311,7 +311,7 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDef } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const MatchItem &item, const Map &map, id_t id) const { +inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(const MatchItem &item, const Map &map, id_t id) const { if (impl.containerEmpty(map)) return ldp_xml_parser::Decision::ANY; diff --git a/src/internal/storage_backend_serialized.hpp b/src/internal/storage_backend_serialized.hpp index 4e25978..5e583e8 100644 --- a/src/internal/storage_backend_serialized.hpp +++ b/src/internal/storage_backend_serialized.hpp @@ -75,41 +75,41 @@ private: void releaseFD(); template - auto getPolicySet() const; + inline auto getPolicySet() const; template - ldp_xml_parser::DecisionItem getDecisionItem(const T &item, const P &policy, ldp_serialization::ItemsType) const; + inline ldp_xml_parser::DecisionItem getDecisionItem(const T &item, const P &policy, ldp_serialization::ItemsType) const; template - ldp_xml_parser::DecisionItem getDecisionItem(const T &item, const P &policy, ldp_serialization::TreeType) const; + inline ldp_xml_parser::DecisionItem getDecisionItem(const T &item, const P &policy, ldp_serialization::TreeType) const; template - ldp_xml_parser::DecisionItem getDecisionItem(const T &item, const P &policy) const; + inline ldp_xml_parser::DecisionItem getDecisionItem(const T &item, const P &policy) const; template - ldp_xml_parser::DecisionItem getDecisionItem(const ldp_xml_parser::MatchItemSend &item, const P &policy) const; + inline ldp_xml_parser::DecisionItem getDecisionItem(const ldp_xml_parser::MatchItemSend &item, const P &policy) const; template - ldp_xml_parser::DecisionItem getDecisionItem(const MatchItem &item, const Map &map, id_t id) const; + inline ldp_xml_parser::DecisionItem getDecisionItem(const MatchItem &item, const Map &map, id_t id) const; typedef boost::tokenizer> tokenizer; template - auto getDecisionItemFromTree(const OwnNode &node, - const tokenizer::iterator &tokens, - tokenizer::iterator &iterator) const; + inline auto getDecisionItemFromTree(const OwnNode &node, + const tokenizer::iterator &tokens, + tokenizer::iterator &iterator) const; template - bool match(const T &match, const I &item) const; + inline bool match(const T &match, const I &item) const; template - bool match(const ldp_xml_parser::MatchItemAccess &match, const I &item) const; + inline bool match(const ldp_xml_parser::MatchItemAccess &match, const I &item) const; template - ldp_xml_parser::DecisionItem makeDecisionItem(const DI &item) const; + inline ldp_xml_parser::DecisionItem makeDecisionItem(const DI &item) const; template - boost::string_ref toStringRef(const String &str) const; + inline boost::string_ref toStringRef(const String &str) const; }; } -- 2.7.4 From c97b4b2fc2282f2754e99bc70d00f0b194bbde30 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Wed, 2 Dec 2020 11:58:34 +0100 Subject: [PATCH 06/16] fix: add missing '[]' in declaration of SerializerDirect::_data Change-Id: I161ff679ad19f74d8815554958f8fa0755ac4445 --- src/internal/serializer_direct.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/serializer_direct.hpp b/src/internal/serializer_direct.hpp index 8b75d19..654c1a2 100644 --- a/src/internal/serializer_direct.hpp +++ b/src/internal/serializer_direct.hpp @@ -28,7 +28,7 @@ namespace ldp_serializer { class SerializerDirect { - std::unique_ptr _data; + std::unique_ptr _data; public: SerializerDirect(); const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size); -- 2.7.4 From 7e357b033baac41efed09a4a021ca113b1c280d8 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Fri, 11 Dec 2020 10:06:16 +0100 Subject: [PATCH 07/16] serialized: don't copy strings in policy lookups Direct serialization allows more optimizing. Now, that other backends are gone, we can slightly modify the interface. This commit makes send index searching pass boost::string_ref to the backend instead of copied C-string. The backend interface is modified to accept string_ref. This way we can remove string copying which was necessary for having null-terminated C-string. Change-Id: I5a1f9657efd050d93023b5256f13afd6d150c369 --- src/internal/storage_backend_direct.hpp | 2 +- src/internal/storage_backend_serialized.cpp | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/internal/storage_backend_direct.hpp b/src/internal/storage_backend_direct.hpp index 7afb1f7..022c8d5 100644 --- a/src/internal/storage_backend_direct.hpp +++ b/src/internal/storage_backend_direct.hpp @@ -508,7 +508,7 @@ public: [](const auto *elem) { return static_cast(elem->getId()); }); } - auto containerLookupByKey(const List *container, const char *key) const { + auto containerLookupByKey(const List *container, boost::string_ref key) const { return containerLookupByKey(container, key, [](const auto *elem) { return elem->getName()->toStringRef(); }); } diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 53d76dc..5509e55 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -209,16 +209,11 @@ inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(co }; auto searchAndUpdateCurrentBest = [¤tBest, &index, &updateCurrentBest, this](boost::string_ref name_ref) { - // we need to create C-string for the lookups - // boost::string_ref gives us correct start, but possibly NUL-terminated in a wrong place, as it does not modify - // input string and keeps only the length - std::string name(name_ref.data(), name_ref.size()); - if (impl.containerEmpty(index)) return; // check if there are any rules for the name - auto fit = impl.containerLookupByKey(index, name.c_str()); + auto fit = impl.containerLookupByKey(index, name_ref); if (!fit.first) return; -- 2.7.4 From 55af0a46c935aabc7e8bfcd6822135910fc75085 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 8 Dec 2020 15:52:12 +0100 Subject: [PATCH 08/16] tests: allow reading from file in perf test Change-Id: I1660ed2a0248efe139590ac278fbf29d4db2d44c --- src/stest_performance.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 1fe6635..bda50f8 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -208,16 +208,17 @@ void run_x_times(std::function func, size_t times) { std::cout << "run: " << static_cast(end - begin)/CLOCKS_PER_SEC << std::endl; } -void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { +void run_fb(const char *conf_file, const std::string &serialized, bool verify, size_t count, bool worst) { Serializer serializer; - size_t size; - auto buff = serializer.serialize(conf_file, size); - - if (verify) - std::cerr << "verification not supported at the moment" << std::endl; StorageBackendSerialized storage; - storage.initFromData(buff, size); + if (serialized.empty()) { + size_t size; + auto buff = serializer.serialize(conf_file, size); + storage.initFromData(buff, size, verify); + } else { + storage.init(serialized.c_str(), verify); + } printf("SERIALIZED:\n"); if (!worst) @@ -226,8 +227,8 @@ void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { run_x_times([&storage](){ send_prefix_test(storage, test_send_to_nonexistent); }, count); } -void run_tests(const char *conf_file, bool verify, size_t c, bool worst) { - run_fb(conf_file, verify, c, worst); +void run_tests(const char *conf_file, const std::string &serialized, bool verify, size_t c, bool worst) { + run_fb(conf_file, serialized, verify, c, worst); } void print_help(const char *name) { @@ -248,13 +249,14 @@ int main(int argc, char *argv[]) { int c; std::string input_filename = system_bus_conf_file_primary(); + std::string input_filename_serialized; size_t count = 100; bool verify = false; bool worst = false; while (1) { int option_index; - c = getopt_long(argc, argv, "vwc:", options, &option_index); + c = getopt_long(argc, argv, "vwc:i:", options, &option_index); if (c == -1) break; switch(c) { @@ -271,6 +273,9 @@ int main(int argc, char *argv[]) case 'w': worst = true; break; + case 'i': + input_filename_serialized = optarg; + break; } } @@ -282,7 +287,7 @@ int main(int argc, char *argv[]) } tslog::init(); - run_tests(input_filename.c_str(), verify, count, worst); + run_tests(input_filename.c_str(), input_filename_serialized, verify, count, worst); return 0; } -- 2.7.4 From 3fa6c844dabfcbdee947eb558f526c889965b444 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Fri, 11 Dec 2020 09:06:08 +0100 Subject: [PATCH 09/16] refactoring: move getter out of loop and lambda Change-Id: Iab7e249849a2ae3f61642b4ead9a973071287401 --- src/internal/storage_backend_serialized.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 5509e55..e19fe43 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -186,17 +186,17 @@ inline ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItem(co return getDecisionItem(item, policy, ldp_serialization::ItemsType()); // make it old way for old databases auto index = impl.policyGetIndex(policy); + auto db_items = impl.policyGetItems(policy); uint32_t currentBest = 0; - auto updateCurrentBest = [¤tBest, &item, &policy, this](const auto &vec) { + auto updateCurrentBest = [¤tBest, &item, &db_items, this](const auto &vec) { // look from the back, the rule is the same as for the full database // we now only check among less elements, because the database is indexed to small lists // item_scores are in increasing order in the index, and they serve also as ids of the policy rules for (auto item_score_it = impl.containerGetReverseIterator(vec); item_score_it != impl.containerGetReverseIteratorEnd(vec); item_score_it++) { - auto db_items = impl.policyGetItems(policy); auto db_item = impl.containerLookupByIndex(db_items, *item_score_it - 1); // rules are indexed/scored from 1 if (*item_score_it > currentBest && match(item, db_item)) { currentBest = *item_score_it; -- 2.7.4 From 84f3818bb84e2f51e62f9ac596d1826439fe9a1f Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 15 Dec 2020 08:32:00 +0100 Subject: [PATCH 10/16] stest_performance: add some error checking Change-Id: I95f8ec6be9597d05d5ebb3a847f241d5cb9e8dc9 --- src/stest_performance.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index bda50f8..410cbc7 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -213,8 +213,12 @@ void run_fb(const char *conf_file, const std::string &serialized, bool verify, s StorageBackendSerialized storage; if (serialized.empty()) { - size_t size; + size_t size = 0; auto buff = serializer.serialize(conf_file, size); + if (!buff) { + std::cerr << "Serialization failed" << std::endl; + return; + } storage.initFromData(buff, size, verify); } else { storage.init(serialized.c_str(), verify); -- 2.7.4 From 5e3b761996ec1463115d1d399acf926455179ee2 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Wed, 10 Feb 2021 14:04:09 +0100 Subject: [PATCH 11/16] kdbus: add kernel linux/kdbus.h header Apparently, linux headers package may be not a good place to keep linux kdbus header, as we can't rely on the header being there when packages that optionally use it are built (e.g. systemd, dbus, glib and libdbuspolicy). However, this package, libdbuspolicy, is very tightly coupled with kdbus so far. In fact, it is so tightly coupled that maybe in the future the kdbus bindings will be moved here, and the package will be renamed to libkdbus? Unlikely, there are not many people out there that would like to touch it anymore. Anyway, anyone who wants to use kdbus on Tizen, should also use libdbuspolicy. That's why the kdbus.h header goes here, and nowhere else. Use it with libdbuspolicy or don't use at all. 'devel' package is the one for distribution of kdbus.h. Additionally, kdbus.h has LGPL-2.1 license, so the 'devel' package also gets it. Change-Id: Ie632e7ecff81d54044f2721138fc9656f3af8412 --- LICENSE.LGPL2.1 | 502 ++++++++++++++++++++++ include/linux/kdbus.h | 984 +++++++++++++++++++++++++++++++++++++++++++ packaging/libdbuspolicy.spec | 6 +- 3 files changed, 1491 insertions(+), 1 deletion(-) create mode 100644 LICENSE.LGPL2.1 create mode 100644 include/linux/kdbus.h diff --git a/LICENSE.LGPL2.1 b/LICENSE.LGPL2.1 new file mode 100644 index 0000000..4362b49 --- /dev/null +++ b/LICENSE.LGPL2.1 @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/include/linux/kdbus.h b/include/linux/kdbus.h new file mode 100644 index 0000000..4fc44cb --- /dev/null +++ b/include/linux/kdbus.h @@ -0,0 +1,984 @@ +/* + * kdbus is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. + */ + +#ifndef _UAPI_KDBUS_H_ +#define _UAPI_KDBUS_H_ + +#include +#include + +#define KDBUS_IOCTL_MAGIC 0x95 +#define KDBUS_SRC_ID_KERNEL (0) +#define KDBUS_DST_ID_NAME (0) +#define KDBUS_MATCH_ID_ANY (~0ULL) +#define KDBUS_DST_ID_BROADCAST (~0ULL) +#define KDBUS_FLAG_NEGOTIATE (1ULL << 63) + +/** + * struct kdbus_notify_id_change - name registry change message + * @id: New or former owner of the name + * @flags: flags field from KDBUS_HELLO_* + * + * Sent from kernel to userspace when the owner or activator of + * a well-known name changes. + * + * Attached to: + * KDBUS_ITEM_ID_ADD + * KDBUS_ITEM_ID_REMOVE + */ +struct kdbus_notify_id_change { + __u64 id; + __u64 flags; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_notify_name_change - name registry change message + * @old_id: ID and flags of former owner of a name + * @new_id: ID and flags of new owner of a name + * @name: Well-known name + * + * Sent from kernel to userspace when the owner or activator of + * a well-known name changes. + * + * Attached to: + * KDBUS_ITEM_NAME_ADD + * KDBUS_ITEM_NAME_REMOVE + * KDBUS_ITEM_NAME_CHANGE + */ +struct kdbus_notify_name_change { + struct kdbus_notify_id_change old_id; + struct kdbus_notify_id_change new_id; + char name[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_creds - process credentials + * @uid: User ID + * @euid: Effective UID + * @suid: Saved UID + * @fsuid: Filesystem UID + * @gid: Group ID + * @egid: Effective GID + * @sgid: Saved GID + * @fsgid: Filesystem GID + * + * Attached to: + * KDBUS_ITEM_CREDS + */ +struct kdbus_creds { + __u64 uid; + __u64 euid; + __u64 suid; + __u64 fsuid; + __u64 gid; + __u64 egid; + __u64 sgid; + __u64 fsgid; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_pids - process identifiers + * @pid: Process ID + * @tid: Thread ID + * @ppid: Parent process ID + * + * The PID and TID of a process. + * + * Attached to: + * KDBUS_ITEM_PIDS + */ +struct kdbus_pids { + __u64 pid; + __u64 tid; + __u64 ppid; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_caps - process capabilities + * @last_cap: Highest currently known capability bit + * @caps: Variable number of 32-bit capabilities flags + * + * Contains a variable number of 32-bit capabilities flags. + * + * Attached to: + * KDBUS_ITEM_CAPS + */ +struct kdbus_caps { + __u32 last_cap; + __u32 caps[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_audit - audit information + * @sessionid: The audit session ID + * @loginuid: The audit login uid + * + * Attached to: + * KDBUS_ITEM_AUDIT + */ +struct kdbus_audit { + __u32 sessionid; + __u32 loginuid; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_timestamp + * @seqnum: Global per-domain message sequence number + * @monotonic_ns: Monotonic timestamp, in nanoseconds + * @realtime_ns: Realtime timestamp, in nanoseconds + * + * Attached to: + * KDBUS_ITEM_TIMESTAMP + */ +struct kdbus_timestamp { + __u64 seqnum; + __u64 monotonic_ns; + __u64 realtime_ns; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_vec - I/O vector for kdbus payload items + * @size: The size of the vector + * @address: Memory address of data buffer + * @offset: Offset in the in-message payload memory, + * relative to the message head + * + * Attached to: + * KDBUS_ITEM_PAYLOAD_VEC, KDBUS_ITEM_PAYLOAD_OFF + */ +struct kdbus_vec { + __u64 size; + union { + __u64 address; + __u64 offset; + }; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_bloom_parameter - bus-wide bloom parameters + * @size: Size of the bit field in bytes (m / 8) + * @n_hash: Number of hash functions used (k) + */ +struct kdbus_bloom_parameter { + __u64 size; + __u64 n_hash; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_bloom_filter - bloom filter containing n elements + * @generation: Generation of the element set in the filter + * @data: Bit field, multiple of 8 bytes + */ +struct kdbus_bloom_filter { + __u64 generation; + __u64 data[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_memfd - a kdbus memfd + * @start: The offset into the memfd where the segment starts + * @size: The size of the memfd segment + * @fd: The file descriptor number + * @__pad: Padding to ensure proper alignment and size + * + * Attached to: + * KDBUS_ITEM_PAYLOAD_MEMFD + */ +struct kdbus_memfd { + __u64 start; + __u64 size; + int fd; + __u32 __pad; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_name - a registered well-known name with its flags + * @flags: Flags from KDBUS_NAME_* + * @name: Well-known name + * + * Attached to: + * KDBUS_ITEM_OWNED_NAME + */ +struct kdbus_name { + __u64 flags; + char name[0]; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_policy_access_type - permissions of a policy record + * @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid + * @KDBUS_POLICY_ACCESS_USER: Grant access to a uid + * @KDBUS_POLICY_ACCESS_GROUP: Grant access to gid + * @KDBUS_POLICY_ACCESS_WORLD: World-accessible + */ +enum kdbus_policy_access_type { + _KDBUS_POLICY_ACCESS_NULL, + KDBUS_POLICY_ACCESS_USER, + KDBUS_POLICY_ACCESS_GROUP, + KDBUS_POLICY_ACCESS_WORLD, +}; + +/** + * enum kdbus_policy_access_flags - mode flags + * @KDBUS_POLICY_OWN: Allow to own a well-known name + * Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE + * @KDBUS_POLICY_TALK: Allow communication to a well-known name + * Implies KDBUS_POLICY_SEE + * @KDBUS_POLICY_SEE: Allow to see a well-known name + */ +enum kdbus_policy_type { + KDBUS_POLICY_SEE = 0, + KDBUS_POLICY_TALK, + KDBUS_POLICY_OWN, +}; + +/** + * struct kdbus_policy_access - policy access item + * @type: One of KDBUS_POLICY_ACCESS_* types + * @access: Access to grant + * @id: For KDBUS_POLICY_ACCESS_USER, the uid + * For KDBUS_POLICY_ACCESS_GROUP, the gid + */ +struct kdbus_policy_access { + __u64 type; /* USER, GROUP, WORLD */ + __u64 access; /* OWN, TALK, SEE */ + __u64 id; /* uid, gid, 0 */ +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_attach_flags - flags for metadata attachments + * @KDBUS_ATTACH_TIMESTAMP: Timestamp + * @KDBUS_ATTACH_CREDS: Credentials + * @KDBUS_ATTACH_PIDS: PIDs + * @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups + * @KDBUS_ATTACH_NAMES: Well-known names + * @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID + * @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID + * @KDBUS_ATTACH_EXE: The path of the executable + * @KDBUS_ATTACH_CMDLINE: The process command line + * @KDBUS_ATTACH_CGROUP: The croup membership + * @KDBUS_ATTACH_CAPS: The process capabilities + * @KDBUS_ATTACH_SECLABEL: The security label + * @KDBUS_ATTACH_AUDIT: The audit IDs + * @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name + * @_KDBUS_ATTACH_ALL: All of the above + * @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of + * metatdata. + */ +enum kdbus_attach_flags { + KDBUS_ATTACH_TIMESTAMP = 1ULL << 0, + KDBUS_ATTACH_CREDS = 1ULL << 1, + KDBUS_ATTACH_PIDS = 1ULL << 2, + KDBUS_ATTACH_AUXGROUPS = 1ULL << 3, + KDBUS_ATTACH_NAMES = 1ULL << 4, + KDBUS_ATTACH_TID_COMM = 1ULL << 5, + KDBUS_ATTACH_PID_COMM = 1ULL << 6, + KDBUS_ATTACH_EXE = 1ULL << 7, + KDBUS_ATTACH_CMDLINE = 1ULL << 8, + KDBUS_ATTACH_CGROUP = 1ULL << 9, + KDBUS_ATTACH_CAPS = 1ULL << 10, + KDBUS_ATTACH_SECLABEL = 1ULL << 11, + KDBUS_ATTACH_AUDIT = 1ULL << 12, + KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13, + _KDBUS_ATTACH_ALL = (1ULL << 14) - 1, + _KDBUS_ATTACH_ANY = ~0ULL +}; + +/** + * enum kdbus_item_type - item types to chain data in a list + * @_KDBUS_ITEM_NULL: Uninitialized/invalid + * @_KDBUS_ITEM_USER_BASE: Start of user items + * @KDBUS_ITEM_NEGOTIATE: Negotiate supported items + * @KDBUS_ITEM_PAYLOAD_VEC: Vector to data + * @KDBUS_ITEM_PAYLOAD_OFF: Data at returned offset to message head + * @KDBUS_ITEM_PAYLOAD_MEMFD: Data as sealed memfd + * @KDBUS_ITEM_FDS: Attached file descriptors + * @KDBUS_ITEM_CANCEL_FD: FD used to cancel a synchronous + * operation by writing to it from + * userspace + * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with + * KDBUS_CMD_BUS_MAKE, carries a + * struct kdbus_bloom_parameter + * @KDBUS_ITEM_BLOOM_FILTER: Bloom filter carried with a message, + * used to match against a bloom mask of a + * connection, carries a struct + * kdbus_bloom_filter + * @KDBUS_ITEM_BLOOM_MASK: Bloom mask used to match against a + * message'sbloom filter + * @KDBUS_ITEM_DST_NAME: Destination's well-known name + * @KDBUS_ITEM_MAKE_NAME: Name of domain, bus, endpoint + * @KDBUS_ITEM_ATTACH_FLAGS_SEND: Attach-flags, used for updating which + * metadata a connection opts in to send + * @KDBUS_ITEM_ATTACH_FLAGS_RECV: Attach-flags, used for updating which + * metadata a connection requests to + * receive for each reeceived message + * @KDBUS_ITEM_ID: Connection ID + * @KDBUS_ITEM_NAME: Well-know name with flags + * @_KDBUS_ITEM_ATTACH_BASE: Start of metadata attach items + * @KDBUS_ITEM_TIMESTAMP: Timestamp + * @KDBUS_ITEM_CREDS: Process credentials + * @KDBUS_ITEM_PIDS: Process identifiers + * @KDBUS_ITEM_AUXGROUPS: Auxiliary process groups + * @KDBUS_ITEM_OWNED_NAME: A name owned by the associated + * connection + * @KDBUS_ITEM_TID_COMM: Thread ID "comm" identifier + * (Don't trust this, see below.) + * @KDBUS_ITEM_PID_COMM: Process ID "comm" identifier + * (Don't trust this, see below.) + * @KDBUS_ITEM_EXE: The path of the executable + * (Don't trust this, see below.) + * @KDBUS_ITEM_CMDLINE: The process command line + * (Don't trust this, see below.) + * @KDBUS_ITEM_CGROUP: The croup membership + * @KDBUS_ITEM_CAPS: The process capabilities + * @KDBUS_ITEM_SECLABEL: The security label + * @KDBUS_ITEM_AUDIT: The audit IDs + * @KDBUS_ITEM_CONN_DESCRIPTION: The connection's human-readable name + * (debugging) + * @_KDBUS_ITEM_POLICY_BASE: Start of policy items + * @KDBUS_ITEM_POLICY_ACCESS: Policy access block + * @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items + * @KDBUS_ITEM_NAME_ADD: Notification in kdbus_notify_name_change + * @KDBUS_ITEM_NAME_REMOVE: Notification in kdbus_notify_name_change + * @KDBUS_ITEM_NAME_CHANGE: Notification in kdbus_notify_name_change + * @KDBUS_ITEM_ID_ADD: Notification in kdbus_notify_id_change + * @KDBUS_ITEM_ID_REMOVE: Notification in kdbus_notify_id_change + * @KDBUS_ITEM_REPLY_TIMEOUT: Timeout has been reached + * @KDBUS_ITEM_REPLY_DEAD: Destination died + * + * N.B: The process and thread COMM fields, as well as the CMDLINE and + * EXE fields may be altered by unprivileged processes und should + * hence *not* used for security decisions. Peers should make use of + * these items only for informational purposes, such as generating log + * records. + */ +enum kdbus_item_type { + _KDBUS_ITEM_NULL, + _KDBUS_ITEM_USER_BASE, + KDBUS_ITEM_NEGOTIATE = _KDBUS_ITEM_USER_BASE, + KDBUS_ITEM_PAYLOAD_VEC, + KDBUS_ITEM_PAYLOAD_OFF, + KDBUS_ITEM_PAYLOAD_MEMFD, + KDBUS_ITEM_FDS, + KDBUS_ITEM_CANCEL_FD, + KDBUS_ITEM_BLOOM_PARAMETER, + KDBUS_ITEM_BLOOM_FILTER, + KDBUS_ITEM_BLOOM_MASK, + KDBUS_ITEM_DST_NAME, + KDBUS_ITEM_MAKE_NAME, + KDBUS_ITEM_ATTACH_FLAGS_SEND, + KDBUS_ITEM_ATTACH_FLAGS_RECV, + KDBUS_ITEM_ID, + KDBUS_ITEM_NAME, + KDBUS_ITEM_DST_ID, + + /* keep these item types in sync with KDBUS_ATTACH_* flags */ + _KDBUS_ITEM_ATTACH_BASE = 0x1000, + KDBUS_ITEM_TIMESTAMP = _KDBUS_ITEM_ATTACH_BASE, + KDBUS_ITEM_CREDS, + KDBUS_ITEM_PIDS, + KDBUS_ITEM_AUXGROUPS, + KDBUS_ITEM_OWNED_NAME, + KDBUS_ITEM_TID_COMM, + KDBUS_ITEM_PID_COMM, + KDBUS_ITEM_EXE, + KDBUS_ITEM_CMDLINE, + KDBUS_ITEM_CGROUP, + KDBUS_ITEM_CAPS, + KDBUS_ITEM_SECLABEL, + KDBUS_ITEM_AUDIT, + KDBUS_ITEM_CONN_DESCRIPTION, + + _KDBUS_ITEM_POLICY_BASE = 0x2000, + KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE, + + _KDBUS_ITEM_KERNEL_BASE = 0x8000, + KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE, + KDBUS_ITEM_NAME_REMOVE, + KDBUS_ITEM_NAME_CHANGE, + KDBUS_ITEM_ID_ADD, + KDBUS_ITEM_ID_REMOVE, + KDBUS_ITEM_REPLY_TIMEOUT, + KDBUS_ITEM_REPLY_DEAD, +}; + +/** + * struct kdbus_item - chain of data blocks + * @size: Overall data record size + * @type: Kdbus_item type of data + * @data: Generic bytes + * @data32: Generic 32 bit array + * @data64: Generic 64 bit array + * @str: Generic string + * @id: Connection ID + * @vec: KDBUS_ITEM_PAYLOAD_VEC + * @creds: KDBUS_ITEM_CREDS + * @audit: KDBUS_ITEM_AUDIT + * @timestamp: KDBUS_ITEM_TIMESTAMP + * @name: KDBUS_ITEM_NAME + * @bloom_parameter: KDBUS_ITEM_BLOOM_PARAMETER + * @bloom_filter: KDBUS_ITEM_BLOOM_FILTER + * @memfd: KDBUS_ITEM_PAYLOAD_MEMFD + * @name_change: KDBUS_ITEM_NAME_ADD + * KDBUS_ITEM_NAME_REMOVE + * KDBUS_ITEM_NAME_CHANGE + * @id_change: KDBUS_ITEM_ID_ADD + * KDBUS_ITEM_ID_REMOVE + * @policy: KDBUS_ITEM_POLICY_ACCESS + */ +struct kdbus_item { + __u64 size; + __u64 type; + union { + __u8 data[0]; + __u32 data32[0]; + __u64 data64[0]; + char str[0]; + + __u64 id; + struct kdbus_vec vec; + struct kdbus_creds creds; + struct kdbus_pids pids; + struct kdbus_audit audit; + struct kdbus_caps caps; + struct kdbus_timestamp timestamp; + struct kdbus_name name; + struct kdbus_bloom_parameter bloom_parameter; + struct kdbus_bloom_filter bloom_filter; + struct kdbus_memfd memfd; + int fds[0]; + struct kdbus_notify_name_change name_change; + struct kdbus_notify_id_change id_change; + struct kdbus_policy_access policy_access; + }; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_msg_flags - type of message + * @KDBUS_MSG_EXPECT_REPLY: Expect a reply message, used for + * method calls. The userspace-supplied + * cookie identifies the message and the + * respective reply carries the cookie + * in cookie_reply + * @KDBUS_MSG_NO_AUTO_START: Do not start a service if the addressed + * name is not currently active. This flag is + * not looked at by the kernel but only + * serves as hint for userspace implementations. + * @KDBUS_MSG_SIGNAL: Treat this message as signal + */ +enum kdbus_msg_flags { + KDBUS_MSG_EXPECT_REPLY = 1ULL << 0, + KDBUS_MSG_NO_AUTO_START = 1ULL << 1, + KDBUS_MSG_SIGNAL = 1ULL << 2, +}; + +/** + * enum kdbus_payload_type - type of payload carried by message + * @KDBUS_PAYLOAD_KERNEL: Kernel-generated simple message + * @KDBUS_PAYLOAD_DBUS: D-Bus marshalling "DBusDBus" + * + * Any payload-type is accepted. Common types will get added here once + * established. + */ +enum kdbus_payload_type { + KDBUS_PAYLOAD_KERNEL, + KDBUS_PAYLOAD_DBUS = 0x4442757344427573ULL, +}; + +/** + * struct kdbus_msg - the representation of a kdbus message + * @size: Total size of the message + * @flags: Message flags (KDBUS_MSG_*), userspace → kernel + * @priority: Message queue priority value + * @dst_id: 64-bit ID of the destination connection + * @src_id: 64-bit ID of the source connection + * @payload_type: Payload type (KDBUS_PAYLOAD_*) + * @cookie: Userspace-supplied cookie, for the connection + * to identify its messages + * @timeout_ns: The time to wait for a message reply from the peer. + * If there is no reply, and the send command is + * executed asynchronously, a kernel-generated message + * with an attached KDBUS_ITEM_REPLY_TIMEOUT item + * is sent to @src_id. For synchronously executed send + * command, the value denotes the maximum time the call + * blocks to wait for a reply. The timeout is expected in + * nanoseconds and as absolute CLOCK_MONOTONIC value. + * @cookie_reply: A reply to the requesting message with the same + * cookie. The requesting connection can match its + * request and the reply with this value + * @items: A list of kdbus_items containing the message payload + */ +struct kdbus_msg { + __u64 size; + __u64 flags; + __s64 priority; + __u64 dst_id; + __u64 src_id; + __u64 payload_type; + __u64 cookie; + union { + __u64 timeout_ns; + __u64 cookie_reply; + }; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_msg_info - returned message container + * @offset: Offset of kdbus_msg slice in pool + * @msg_size: Copy of the kdbus_msg.size field + * @return_flags: Command return flags, kernel → userspace + */ +struct kdbus_msg_info { + __u64 offset; + __u64 msg_size; + __u64 return_flags; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_send_flags - flags for sending messages + * @KDBUS_SEND_SYNC_REPLY: Wait for destination connection to + * reply to this message. The + * KDBUS_CMD_SEND ioctl() will block + * until the reply is received, and + * reply in struct kdbus_cmd_send will + * yield the offset in the sender's pool + * where the reply can be found. + * This flag is only valid if + * @KDBUS_MSG_EXPECT_REPLY is set as well. + */ +enum kdbus_send_flags { + KDBUS_SEND_SYNC_REPLY = 1ULL << 0, +}; + +/** + * struct kdbus_cmd_send - send message + * @size: Overall size of this structure + * @flags: Flags to change send behavior (KDBUS_SEND_*) + * @return_flags: Command return flags, kernel → userspace + * @msg_address: Storage address of the kdbus_msg to send + * @reply: Storage for message reply if KDBUS_SEND_SYNC_REPLY + * was given + * @items: Additional items for this command + */ +struct kdbus_cmd_send { + __u64 size; + __u64 flags; + __u64 return_flags; + __u64 msg_address; + struct kdbus_msg_info reply; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_recv_flags - flags for de-queuing messages + * @KDBUS_RECV_PEEK: Return the next queued message without + * actually de-queuing it, and without installing + * any file descriptors or other resources. It is + * usually used to determine the activating + * connection of a bus name. + * @KDBUS_RECV_DROP: Drop and free the next queued message and all + * its resources without actually receiving it. + * @KDBUS_RECV_USE_PRIORITY: Only de-queue messages with the specified or + * higher priority (lowest values); if not set, + * the priority value is ignored. + */ +enum kdbus_recv_flags { + KDBUS_RECV_PEEK = 1ULL << 0, + KDBUS_RECV_DROP = 1ULL << 1, + KDBUS_RECV_USE_PRIORITY = 1ULL << 2, +}; + +/** + * enum kdbus_recv_return_flags - return flags for message receive commands + * @KDBUS_RECV_RETURN_INCOMPLETE_FDS: One or more file descriptors could not + * be installed. These descriptors in + * KDBUS_ITEM_FDS will carry the value -1. + * @KDBUS_RECV_RETURN_DROPPED_MSGS: There have been dropped messages since + * the last time a message was received. + * The 'dropped_msgs' counter contains the + * number of messages dropped pool + * overflows or other missed broadcasts. + */ +enum kdbus_recv_return_flags { + KDBUS_RECV_RETURN_INCOMPLETE_FDS = 1ULL << 0, + KDBUS_RECV_RETURN_DROPPED_MSGS = 1ULL << 1, +}; + +/** + * struct kdbus_cmd_recv - struct to de-queue a buffered message + * @size: Overall size of this object + * @flags: KDBUS_RECV_* flags, userspace → kernel + * @return_flags: Command return flags, kernel → userspace + * @priority: Minimum priority of the messages to de-queue. Lowest + * values have the highest priority. + * @dropped_msgs: In case there were any dropped messages since the last + * time a message was received, this will be set to the + * number of lost messages and + * KDBUS_RECV_RETURN_DROPPED_MSGS will be set in + * 'return_flags'. This can only happen if the ioctl + * returns 0 or EAGAIN. + * @msg: Return storage for received message. + * @items: Additional items for this command. + * + * This struct is used with the KDBUS_CMD_RECV ioctl. + */ +struct kdbus_cmd_recv { + __u64 size; + __u64 flags; + __u64 return_flags; + __s64 priority; + __u64 dropped_msgs; + struct kdbus_msg_info msg; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_cmd_free - struct to free a slice of memory in the pool + * @size: Overall size of this structure + * @flags: Flags for the free command, userspace → kernel + * @return_flags: Command return flags, kernel → userspace + * @offset: The offset of the memory slice, as returned by other + * ioctls + * @items: Additional items to modify the behavior + * + * This struct is used with the KDBUS_CMD_FREE ioctl. + */ +struct kdbus_cmd_free { + __u64 size; + __u64 flags; + __u64 return_flags; + __u64 offset; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello + * @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception of + * any passed file descriptors + * @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers + * a well-know name for a process to be started + * when traffic arrives + * @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers + * policy entries for a name. The provided name + * is not activated and not registered with the + * name database, it only allows unprivileged + * connections to acquire a name, talk or discover + * a service + * @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor + * bus traffic + */ +enum kdbus_hello_flags { + KDBUS_HELLO_ACCEPT_FD = 1ULL << 0, + KDBUS_HELLO_ACTIVATOR = 1ULL << 1, + KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2, + KDBUS_HELLO_MONITOR = 1ULL << 3, +}; + +/** + * struct kdbus_cmd_hello - struct to say hello to kdbus + * @size: The total size of the structure + * @flags: Connection flags (KDBUS_HELLO_*), userspace → kernel + * @return_flags: Command return flags, kernel → userspace + * @attach_flags_send: Mask of metadata to attach to each message sent + * off by this connection (KDBUS_ATTACH_*) + * @attach_flags_recv: Mask of metadata to attach to each message receieved + * by the new connection (KDBUS_ATTACH_*) + * @bus_flags: The flags field copied verbatim from the original + * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful + * to do negotiation of features of the payload that is + * transferred (kernel → userspace) + * @id: The ID of this connection (kernel → userspace) + * @pool_size: Size of the connection's buffer where the received + * messages are placed + * @offset: Pool offset where items are returned to report + * additional information about the bus and the newly + * created connection. + * @items_size: Size of buffer returned in the pool slice at @offset. + * @id128: Unique 128-bit ID of the bus (kernel → userspace) + * @items: A list of items + * + * This struct is used with the KDBUS_CMD_HELLO ioctl. + */ +struct kdbus_cmd_hello { + __u64 size; + __u64 flags; + __u64 return_flags; + __u64 attach_flags_send; + __u64 attach_flags_recv; + __u64 bus_flags; + __u64 id; + __u64 pool_size; + __u64 offset; + __u64 items_size; + __u8 id128[16]; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_info - connection information + * @size: total size of the struct + * @id: 64bit object ID + * @flags: object creation flags + * @items: list of items + * + * Note that the user is responsible for freeing the allocated memory with + * the KDBUS_CMD_FREE ioctl. + */ +struct kdbus_info { + __u64 size; + __u64 id; + __u64 flags; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_list_flags - what to include into the returned list + * @KDBUS_LIST_UNIQUE: active connections + * @KDBUS_LIST_ACTIVATORS: activator connections + * @KDBUS_LIST_NAMES: known well-known names + * @KDBUS_LIST_QUEUED: queued-up names + */ +enum kdbus_list_flags { + KDBUS_LIST_UNIQUE = 1ULL << 0, + KDBUS_LIST_NAMES = 1ULL << 1, + KDBUS_LIST_ACTIVATORS = 1ULL << 2, + KDBUS_LIST_QUEUED = 1ULL << 3, +}; + +/** + * struct kdbus_cmd_list - list connections + * @size: overall size of this object + * @flags: flags for the query (KDBUS_LIST_*), userspace → kernel + * @return_flags: command return flags, kernel → userspace + * @offset: Offset in the caller's pool buffer where an array of + * kdbus_info objects is stored. + * The user must use KDBUS_CMD_FREE to free the + * allocated memory. + * @list_size: size of returned list in bytes + * @items: Items for the command. Reserved for future use. + * + * This structure is used with the KDBUS_CMD_LIST ioctl. + */ +struct kdbus_cmd_list { + __u64 size; + __u64 flags; + __u64 return_flags; + __u64 offset; + __u64 list_size; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * struct kdbus_cmd_info - struct used for KDBUS_CMD_CONN_INFO ioctl + * @size: The total size of the struct + * @flags: Flags for this ioctl, userspace → kernel + * @return_flags: Command return flags, kernel → userspace + * @id: The 64-bit ID of the connection. If set to zero, passing + * @name is required. kdbus will look up the name to + * determine the ID in this case. + * @attach_flags: Set of attach flags to specify the set of information + * to receive, userspace → kernel + * @offset: Returned offset in the caller's pool buffer where the + * kdbus_info struct result is stored. The user must + * use KDBUS_CMD_FREE to free the allocated memory. + * @info_size: Output buffer to report size of data at @offset. + * @items: The optional item list, containing the + * well-known name to look up as a KDBUS_ITEM_NAME. + * Only needed in case @id is zero. + * + * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will + * tell the user the offset in the connection pool buffer at which to find the + * result in a struct kdbus_info. + */ +struct kdbus_cmd_info { + __u64 size; + __u64 flags; + __u64 return_flags; + __u64 id; + __u64 attach_flags; + __u64 offset; + __u64 info_size; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_cmd_match_flags - flags to control the KDBUS_CMD_MATCH_ADD ioctl + * @KDBUS_MATCH_REPLACE: If entries with the supplied cookie already + * exists, remove them before installing the new + * matches. + */ +enum kdbus_cmd_match_flags { + KDBUS_MATCH_REPLACE = 1ULL << 0, +}; + +/** + * struct kdbus_cmd_match - struct to add or remove matches + * @size: The total size of the struct + * @flags: Flags for match command (KDBUS_MATCH_*), + * userspace → kernel + * @return_flags: Command return flags, kernel → userspace + * @cookie: Userspace supplied cookie. When removing, the cookie + * identifies the match to remove + * @items: A list of items for additional information + * + * This structure is used with the KDBUS_CMD_MATCH_ADD and + * KDBUS_CMD_MATCH_REMOVE ioctl. + */ +struct kdbus_cmd_match { + __u64 size; + __u64 flags; + __u64 return_flags; + __u64 cookie; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,ENDPOINT}_MAKE + * @KDBUS_MAKE_ACCESS_GROUP: Make the bus or endpoint node group-accessible + * @KDBUS_MAKE_ACCESS_WORLD: Make the bus or endpoint node world-accessible + */ +enum kdbus_make_flags { + KDBUS_MAKE_ACCESS_GROUP = 1ULL << 0, + KDBUS_MAKE_ACCESS_WORLD = 1ULL << 1, +}; + +/** + * enum kdbus_name_flags - flags for KDBUS_CMD_NAME_ACQUIRE + * @KDBUS_NAME_REPLACE_EXISTING: Try to replace name of other connections + * @KDBUS_NAME_ALLOW_REPLACEMENT: Allow the replacement of the name + * @KDBUS_NAME_QUEUE: Name should be queued if busy + * @KDBUS_NAME_IN_QUEUE: Name is queued + * @KDBUS_NAME_ACTIVATOR: Name is owned by a activator connection + * @KDBUS_NAME_PRIMARY: Primary owner of the name + * @KDBUS_NAME_ACQUIRED: Name was acquired/queued _now_ + */ +enum kdbus_name_flags { + KDBUS_NAME_REPLACE_EXISTING = 1ULL << 0, + KDBUS_NAME_ALLOW_REPLACEMENT = 1ULL << 1, + KDBUS_NAME_QUEUE = 1ULL << 2, + KDBUS_NAME_IN_QUEUE = 1ULL << 3, + KDBUS_NAME_ACTIVATOR = 1ULL << 4, + KDBUS_NAME_PRIMARY = 1ULL << 5, + KDBUS_NAME_ACQUIRED = 1ULL << 6, +}; + +/** + * struct kdbus_cmd - generic ioctl payload + * @size: Overall size of this structure + * @flags: Flags for this ioctl, userspace → kernel + * @return_flags: Ioctl return flags, kernel → userspace + * @items: Additional items to modify the behavior + * + * This is a generic ioctl payload object. It's used by all ioctls that only + * take flags and items as input. + */ +struct kdbus_cmd { + __u64 size; + __u64 flags; + __u64 return_flags; + struct kdbus_item items[0]; +} __attribute__((__aligned__(8))); + +/** + * Ioctl API + * + * KDBUS_CMD_BUS_MAKE: After opening the "control" node, this command + * creates a new bus with the specified + * name. The bus is immediately shut down and + * cleaned up when the opened file descriptor is + * closed. + * + * KDBUS_CMD_ENDPOINT_MAKE: Creates a new named special endpoint to talk to + * the bus. Such endpoints usually carry a more + * restrictive policy and grant restricted access + * to specific applications. + * KDBUS_CMD_ENDPOINT_UPDATE: Update the properties of a custom enpoint. Used + * to update the policy. + * + * KDBUS_CMD_HELLO: By opening the bus node, a connection is + * created. After a HELLO the opened connection + * becomes an active peer on the bus. + * KDBUS_CMD_UPDATE: Update the properties of a connection. Used to + * update the metadata subscription mask and + * policy. + * KDBUS_CMD_BYEBYE: Disconnect a connection. If there are no + * messages queued up in the connection's pool, + * the call succeeds, and the handle is rendered + * unusable. Otherwise, -EBUSY is returned without + * any further side-effects. + * KDBUS_CMD_FREE: Release the allocated memory in the receiver's + * pool. + * KDBUS_CMD_CONN_INFO: Retrieve credentials and properties of the + * initial creator of the connection. The data was + * stored at registration time and does not + * necessarily represent the connected process or + * the actual state of the process. + * KDBUS_CMD_BUS_CREATOR_INFO: Retrieve information of the creator of the bus + * a connection is attached to. + * + * KDBUS_CMD_SEND: Send a message and pass data from userspace to + * the kernel. + * KDBUS_CMD_RECV: Receive a message from the kernel which is + * placed in the receiver's pool. + * + * KDBUS_CMD_NAME_ACQUIRE: Request a well-known bus name to associate with + * the connection. Well-known names are used to + * address a peer on the bus. + * KDBUS_CMD_NAME_RELEASE: Release a well-known name the connection + * currently owns. + * KDBUS_CMD_LIST: Retrieve the list of all currently registered + * well-known and unique names. + * + * KDBUS_CMD_MATCH_ADD: Install a match which broadcast messages should + * be delivered to the connection. + * KDBUS_CMD_MATCH_REMOVE: Remove a current match for broadcast messages. + */ +enum kdbus_ioctl_type { + /* bus owner (00-0f) */ + KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x00, + struct kdbus_cmd), + + /* endpoint owner (10-1f) */ + KDBUS_CMD_ENDPOINT_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x10, + struct kdbus_cmd), + KDBUS_CMD_ENDPOINT_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x11, + struct kdbus_cmd), + + /* connection owner (80-ff) */ + KDBUS_CMD_HELLO = _IOWR(KDBUS_IOCTL_MAGIC, 0x80, + struct kdbus_cmd_hello), + KDBUS_CMD_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x81, + struct kdbus_cmd), + KDBUS_CMD_BYEBYE = _IOW(KDBUS_IOCTL_MAGIC, 0x82, + struct kdbus_cmd), + KDBUS_CMD_FREE = _IOW(KDBUS_IOCTL_MAGIC, 0x83, + struct kdbus_cmd_free), + KDBUS_CMD_CONN_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x84, + struct kdbus_cmd_info), + KDBUS_CMD_BUS_CREATOR_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x85, + struct kdbus_cmd_info), + KDBUS_CMD_LIST = _IOR(KDBUS_IOCTL_MAGIC, 0x86, + struct kdbus_cmd_list), + + KDBUS_CMD_SEND = _IOW(KDBUS_IOCTL_MAGIC, 0x90, + struct kdbus_cmd_send), + KDBUS_CMD_RECV = _IOR(KDBUS_IOCTL_MAGIC, 0x91, + struct kdbus_cmd_recv), + + KDBUS_CMD_NAME_ACQUIRE = _IOW(KDBUS_IOCTL_MAGIC, 0xa0, + struct kdbus_cmd), + KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOCTL_MAGIC, 0xa1, + struct kdbus_cmd), + + KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOCTL_MAGIC, 0xb0, + struct kdbus_cmd_match), + KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOCTL_MAGIC, 0xb1, + struct kdbus_cmd_match), +}; + +#endif /* _UAPI_KDBUS_H_ */ diff --git a/packaging/libdbuspolicy.spec b/packaging/libdbuspolicy.spec index 5178a71..087c42a 100644 --- a/packaging/libdbuspolicy.spec +++ b/packaging/libdbuspolicy.spec @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(dlog) Requires: %{name}-serializer %package devel +License: MIT and LGPL-2.1+ Summary: Helper library for fine-grained userspace policy handling-development package %package serializer @@ -110,6 +111,9 @@ mkdir -p -m755 %{buildroot}%{_unitdir} install -m644 libdbuspolicy-verify-data.target %{buildroot}/%{_unitdir}/ install -m644 libdbuspolicy-verify-data.service %{buildroot}/%{_unitdir}/ +mkdir -p -m755 %{buildroot}%{_includedir}/linux/ +install -m644 include/linux/kdbus.h %{buildroot}%{_includedir}/linux/ + %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -130,7 +134,7 @@ mv %{_unitdir}/.%{name}.backup.default.target %{_unitdir}/default.target %files devel %manifest %{name}.manifest -%license LICENSE.MIT +%license LICENSE.MIT LICENSE.LGPL2.1 %defattr(-,root,root) %{_includedir}/* %{_libdir}/pkgconfig/* -- 2.7.4 From 0c4d6fb5fed30d5310958eb22ffba9c6ed231cfa Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 3 Mar 2021 18:04:25 +0900 Subject: [PATCH 12/16] Fix build errors - kdbus.h Change-Id: Iecea09838198402eef2bac6cffd672a0e3702609 Signed-off-by: Hyotaek Shim --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index e68e740..51e41f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,6 +11,7 @@ AM_CPPFLAGS = \ $(CYNARA_CFLAGS) \ $(DLOG_CFLAGS) \ -I${top_srcdir}/src \ + -Iinclude \ -Isrc/internal/include AM_CFLAGS = ${my_CFLAGS} \ -- 2.7.4 From 11f4e6917e7849b5848bfea0fb4f6df68760a46d Mon Sep 17 00:00:00 2001 From: Kushagra K Date: Thu, 29 Apr 2021 16:30:00 +0530 Subject: [PATCH 13/16] tests: add generated performance tests Enhancing performance test by incorporating VD Tizen image specific Item Send rules in default context to performance test at runtime. Verification Results: sh-3.2# ./stest_performance --system -r 10 SERIALIZED: Default ItemSend Rule Count: 578 run: 0.001137 Change-Id: I7050d19a3ef50119254e417a2ef05b5bf4ecd911 --- src/stest_performance.cpp | 86 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 410cbc7..d4dce04 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -173,9 +173,28 @@ struct Test test_send_to_nonexistent[]={ "no.such.interface", "no_such_method", ldp_xml_parser::MessageType::METHOD_CALL} }; -void test_print(const struct Test* t, Decision result) { - printf("uid = %lu, gid = %lu, label = %s, destination = %s, expected = %s, result = %s", - (unsigned long)t->user, (unsigned long)t->group, t->label, t->destination, DECISIONS[t->expected_result], DECISIONS[result]); +void create_test(const StorageBackendSerialized &storage, std::vector &tests) { + const auto &backend = storage.getBackend(); + const auto &file = backend.getFile(); + const auto &send_set = backend.fileGetSendSet(file); + const auto &context_default = backend.setGetContextDefault(send_set); + const auto &items = backend.policyGetItems(context_default); + for (auto iterator = backend.containerGetIterator(items); + iterator != backend.containerGetIteratorEnd(items); + iterator++) { + const auto &item = *iterator; + backend.itemSrGetName(item); + Test t{backend.decisionItemGetDecision(backend.itemGetDecisionItem(item)), + 0, 0, "User::Shell", + backend.stringGetCStr(backend.itemSrGetName(item)), + backend.stringGetCStr(backend.itemSrGetPath(item)), + backend.stringGetCStr(backend.itemSrGetInterface(item)), + backend.stringGetCStr(backend.itemSrGetMember(item)), + backend.itemSrGetMessageType(item)}; + tests.push_back(t); + } + + std::cout << "Default ItemSend Rule Count: " << tests.size() << std::endl; } template @@ -199,6 +218,19 @@ void send_prefix_test(const DB &db, const Array &tests) } } +template +void send_performance_test(const DB &db, const std::vector &r_tests) +{ + for (const auto &test : r_tests) { + KdbusBusNames names; + MatchItemSend m_item(test.interface, test.member, test.path, test.type, + names.addSpaceSeparatedNames(test.destination)); + + /* Just find the decision from the default context, no need to check for validity */ + db.getDecisionItemContextDefault(m_item); + } +} + void run_x_times(std::function func, size_t times) { clock_t begin = clock(); for (size_t i = 0; i < times; i++) @@ -208,7 +240,7 @@ void run_x_times(std::function func, size_t times) { std::cout << "run: " << static_cast(end - begin)/CLOCKS_PER_SEC << std::endl; } -void run_fb(const char *conf_file, const std::string &serialized, bool verify, size_t count, bool worst) { +void run_tests(const char *conf_file, const std::string &serialized, bool real, bool verify, size_t count, bool worst) { Serializer serializer; StorageBackendSerialized storage; @@ -224,22 +256,24 @@ void run_fb(const char *conf_file, const std::string &serialized, bool verify, s storage.init(serialized.c_str(), verify); } - printf("SERIALIZED:\n"); - if (!worst) - run_x_times([&storage](){ send_prefix_test(storage, tests); }, count); - else + std::cout << "SERIALIZED:" << std::endl; + if (worst) { run_x_times([&storage](){ send_prefix_test(storage, test_send_to_nonexistent); }, count); -} - -void run_tests(const char *conf_file, const std::string &serialized, bool verify, size_t c, bool worst) { - run_fb(conf_file, serialized, verify, c, worst); + } else if (real) { + std::vector r_tests; + create_test(storage, r_tests); + run_x_times([&storage, &r_tests](){ send_performance_test(storage, r_tests); }, count); + } else { + run_x_times([&storage](){ send_prefix_test(storage, tests); }, count); + } } void print_help(const char *name) { std::cout << std::endl; - std::cout << "usage: " << name << " [-v] {--system|--session|-c } " << std::endl; + std::cout << "usage: " << name << " [-v] [-r] {--system|--session|-c } " << std::endl; std::cout << std::endl; std::cout << " -v - Verify" << std::endl; + std::cout << " -r - Generate test from the actual policy rules" << std::endl; std::cout << std::endl; } @@ -257,10 +291,11 @@ int main(int argc, char *argv[]) size_t count = 100; bool verify = false; bool worst = false; + bool real = false; while (1) { int option_index; - c = getopt_long(argc, argv, "vwc:i:", options, &option_index); + c = getopt_long(argc, argv, "rvwc:i:", options, &option_index); if (c == -1) break; switch(c) { @@ -269,21 +304,24 @@ int main(int argc, char *argv[]) input_filename = session_bus_conf_file_primary(); break; case 'c': - input_filename = optarg; - break; + input_filename = optarg; + break; case 'v': - verify = true; - break; + verify = true; + break; case 'w': - worst = true; - break; + worst = true; + break; case 'i': - input_filename_serialized = optarg; - break; + input_filename_serialized = optarg; + break; + case 'r': + real = true; + break; } } - if (optind < argc) { + if (optind < argc && !(real && worst)) { count = std::stoi(argv[optind]); } else { print_help(argv[0]); @@ -291,7 +329,7 @@ int main(int argc, char *argv[]) } tslog::init(); - run_tests(input_filename.c_str(), input_filename_serialized, verify, count, worst); + run_tests(input_filename.c_str(), input_filename_serialized, real, verify, count, worst); return 0; } -- 2.7.4 From d3b7391b77ad0f9680412c004a5275d75188b8d6 Mon Sep 17 00:00:00 2001 From: Mateusz Majewski Date: Fri, 31 Dec 2021 10:21:40 +0100 Subject: [PATCH 14/16] packaging: use linux-tizen-modules-headers Change-Id: I07e4534ca1e152201e97be447a608f88f6f58352 --- include/linux/kdbus.h | 984 ------------------------------------------- packaging/libdbuspolicy.spec | 7 +- 2 files changed, 4 insertions(+), 987 deletions(-) delete mode 100644 include/linux/kdbus.h diff --git a/include/linux/kdbus.h b/include/linux/kdbus.h deleted file mode 100644 index 4fc44cb..0000000 --- a/include/linux/kdbus.h +++ /dev/null @@ -1,984 +0,0 @@ -/* - * kdbus is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at - * your option) any later version. - */ - -#ifndef _UAPI_KDBUS_H_ -#define _UAPI_KDBUS_H_ - -#include -#include - -#define KDBUS_IOCTL_MAGIC 0x95 -#define KDBUS_SRC_ID_KERNEL (0) -#define KDBUS_DST_ID_NAME (0) -#define KDBUS_MATCH_ID_ANY (~0ULL) -#define KDBUS_DST_ID_BROADCAST (~0ULL) -#define KDBUS_FLAG_NEGOTIATE (1ULL << 63) - -/** - * struct kdbus_notify_id_change - name registry change message - * @id: New or former owner of the name - * @flags: flags field from KDBUS_HELLO_* - * - * Sent from kernel to userspace when the owner or activator of - * a well-known name changes. - * - * Attached to: - * KDBUS_ITEM_ID_ADD - * KDBUS_ITEM_ID_REMOVE - */ -struct kdbus_notify_id_change { - __u64 id; - __u64 flags; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_notify_name_change - name registry change message - * @old_id: ID and flags of former owner of a name - * @new_id: ID and flags of new owner of a name - * @name: Well-known name - * - * Sent from kernel to userspace when the owner or activator of - * a well-known name changes. - * - * Attached to: - * KDBUS_ITEM_NAME_ADD - * KDBUS_ITEM_NAME_REMOVE - * KDBUS_ITEM_NAME_CHANGE - */ -struct kdbus_notify_name_change { - struct kdbus_notify_id_change old_id; - struct kdbus_notify_id_change new_id; - char name[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_creds - process credentials - * @uid: User ID - * @euid: Effective UID - * @suid: Saved UID - * @fsuid: Filesystem UID - * @gid: Group ID - * @egid: Effective GID - * @sgid: Saved GID - * @fsgid: Filesystem GID - * - * Attached to: - * KDBUS_ITEM_CREDS - */ -struct kdbus_creds { - __u64 uid; - __u64 euid; - __u64 suid; - __u64 fsuid; - __u64 gid; - __u64 egid; - __u64 sgid; - __u64 fsgid; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_pids - process identifiers - * @pid: Process ID - * @tid: Thread ID - * @ppid: Parent process ID - * - * The PID and TID of a process. - * - * Attached to: - * KDBUS_ITEM_PIDS - */ -struct kdbus_pids { - __u64 pid; - __u64 tid; - __u64 ppid; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_caps - process capabilities - * @last_cap: Highest currently known capability bit - * @caps: Variable number of 32-bit capabilities flags - * - * Contains a variable number of 32-bit capabilities flags. - * - * Attached to: - * KDBUS_ITEM_CAPS - */ -struct kdbus_caps { - __u32 last_cap; - __u32 caps[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_audit - audit information - * @sessionid: The audit session ID - * @loginuid: The audit login uid - * - * Attached to: - * KDBUS_ITEM_AUDIT - */ -struct kdbus_audit { - __u32 sessionid; - __u32 loginuid; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_timestamp - * @seqnum: Global per-domain message sequence number - * @monotonic_ns: Monotonic timestamp, in nanoseconds - * @realtime_ns: Realtime timestamp, in nanoseconds - * - * Attached to: - * KDBUS_ITEM_TIMESTAMP - */ -struct kdbus_timestamp { - __u64 seqnum; - __u64 monotonic_ns; - __u64 realtime_ns; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_vec - I/O vector for kdbus payload items - * @size: The size of the vector - * @address: Memory address of data buffer - * @offset: Offset in the in-message payload memory, - * relative to the message head - * - * Attached to: - * KDBUS_ITEM_PAYLOAD_VEC, KDBUS_ITEM_PAYLOAD_OFF - */ -struct kdbus_vec { - __u64 size; - union { - __u64 address; - __u64 offset; - }; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_bloom_parameter - bus-wide bloom parameters - * @size: Size of the bit field in bytes (m / 8) - * @n_hash: Number of hash functions used (k) - */ -struct kdbus_bloom_parameter { - __u64 size; - __u64 n_hash; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_bloom_filter - bloom filter containing n elements - * @generation: Generation of the element set in the filter - * @data: Bit field, multiple of 8 bytes - */ -struct kdbus_bloom_filter { - __u64 generation; - __u64 data[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_memfd - a kdbus memfd - * @start: The offset into the memfd where the segment starts - * @size: The size of the memfd segment - * @fd: The file descriptor number - * @__pad: Padding to ensure proper alignment and size - * - * Attached to: - * KDBUS_ITEM_PAYLOAD_MEMFD - */ -struct kdbus_memfd { - __u64 start; - __u64 size; - int fd; - __u32 __pad; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_name - a registered well-known name with its flags - * @flags: Flags from KDBUS_NAME_* - * @name: Well-known name - * - * Attached to: - * KDBUS_ITEM_OWNED_NAME - */ -struct kdbus_name { - __u64 flags; - char name[0]; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_policy_access_type - permissions of a policy record - * @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid - * @KDBUS_POLICY_ACCESS_USER: Grant access to a uid - * @KDBUS_POLICY_ACCESS_GROUP: Grant access to gid - * @KDBUS_POLICY_ACCESS_WORLD: World-accessible - */ -enum kdbus_policy_access_type { - _KDBUS_POLICY_ACCESS_NULL, - KDBUS_POLICY_ACCESS_USER, - KDBUS_POLICY_ACCESS_GROUP, - KDBUS_POLICY_ACCESS_WORLD, -}; - -/** - * enum kdbus_policy_access_flags - mode flags - * @KDBUS_POLICY_OWN: Allow to own a well-known name - * Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE - * @KDBUS_POLICY_TALK: Allow communication to a well-known name - * Implies KDBUS_POLICY_SEE - * @KDBUS_POLICY_SEE: Allow to see a well-known name - */ -enum kdbus_policy_type { - KDBUS_POLICY_SEE = 0, - KDBUS_POLICY_TALK, - KDBUS_POLICY_OWN, -}; - -/** - * struct kdbus_policy_access - policy access item - * @type: One of KDBUS_POLICY_ACCESS_* types - * @access: Access to grant - * @id: For KDBUS_POLICY_ACCESS_USER, the uid - * For KDBUS_POLICY_ACCESS_GROUP, the gid - */ -struct kdbus_policy_access { - __u64 type; /* USER, GROUP, WORLD */ - __u64 access; /* OWN, TALK, SEE */ - __u64 id; /* uid, gid, 0 */ -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_attach_flags - flags for metadata attachments - * @KDBUS_ATTACH_TIMESTAMP: Timestamp - * @KDBUS_ATTACH_CREDS: Credentials - * @KDBUS_ATTACH_PIDS: PIDs - * @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups - * @KDBUS_ATTACH_NAMES: Well-known names - * @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID - * @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID - * @KDBUS_ATTACH_EXE: The path of the executable - * @KDBUS_ATTACH_CMDLINE: The process command line - * @KDBUS_ATTACH_CGROUP: The croup membership - * @KDBUS_ATTACH_CAPS: The process capabilities - * @KDBUS_ATTACH_SECLABEL: The security label - * @KDBUS_ATTACH_AUDIT: The audit IDs - * @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name - * @_KDBUS_ATTACH_ALL: All of the above - * @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of - * metatdata. - */ -enum kdbus_attach_flags { - KDBUS_ATTACH_TIMESTAMP = 1ULL << 0, - KDBUS_ATTACH_CREDS = 1ULL << 1, - KDBUS_ATTACH_PIDS = 1ULL << 2, - KDBUS_ATTACH_AUXGROUPS = 1ULL << 3, - KDBUS_ATTACH_NAMES = 1ULL << 4, - KDBUS_ATTACH_TID_COMM = 1ULL << 5, - KDBUS_ATTACH_PID_COMM = 1ULL << 6, - KDBUS_ATTACH_EXE = 1ULL << 7, - KDBUS_ATTACH_CMDLINE = 1ULL << 8, - KDBUS_ATTACH_CGROUP = 1ULL << 9, - KDBUS_ATTACH_CAPS = 1ULL << 10, - KDBUS_ATTACH_SECLABEL = 1ULL << 11, - KDBUS_ATTACH_AUDIT = 1ULL << 12, - KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13, - _KDBUS_ATTACH_ALL = (1ULL << 14) - 1, - _KDBUS_ATTACH_ANY = ~0ULL -}; - -/** - * enum kdbus_item_type - item types to chain data in a list - * @_KDBUS_ITEM_NULL: Uninitialized/invalid - * @_KDBUS_ITEM_USER_BASE: Start of user items - * @KDBUS_ITEM_NEGOTIATE: Negotiate supported items - * @KDBUS_ITEM_PAYLOAD_VEC: Vector to data - * @KDBUS_ITEM_PAYLOAD_OFF: Data at returned offset to message head - * @KDBUS_ITEM_PAYLOAD_MEMFD: Data as sealed memfd - * @KDBUS_ITEM_FDS: Attached file descriptors - * @KDBUS_ITEM_CANCEL_FD: FD used to cancel a synchronous - * operation by writing to it from - * userspace - * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with - * KDBUS_CMD_BUS_MAKE, carries a - * struct kdbus_bloom_parameter - * @KDBUS_ITEM_BLOOM_FILTER: Bloom filter carried with a message, - * used to match against a bloom mask of a - * connection, carries a struct - * kdbus_bloom_filter - * @KDBUS_ITEM_BLOOM_MASK: Bloom mask used to match against a - * message'sbloom filter - * @KDBUS_ITEM_DST_NAME: Destination's well-known name - * @KDBUS_ITEM_MAKE_NAME: Name of domain, bus, endpoint - * @KDBUS_ITEM_ATTACH_FLAGS_SEND: Attach-flags, used for updating which - * metadata a connection opts in to send - * @KDBUS_ITEM_ATTACH_FLAGS_RECV: Attach-flags, used for updating which - * metadata a connection requests to - * receive for each reeceived message - * @KDBUS_ITEM_ID: Connection ID - * @KDBUS_ITEM_NAME: Well-know name with flags - * @_KDBUS_ITEM_ATTACH_BASE: Start of metadata attach items - * @KDBUS_ITEM_TIMESTAMP: Timestamp - * @KDBUS_ITEM_CREDS: Process credentials - * @KDBUS_ITEM_PIDS: Process identifiers - * @KDBUS_ITEM_AUXGROUPS: Auxiliary process groups - * @KDBUS_ITEM_OWNED_NAME: A name owned by the associated - * connection - * @KDBUS_ITEM_TID_COMM: Thread ID "comm" identifier - * (Don't trust this, see below.) - * @KDBUS_ITEM_PID_COMM: Process ID "comm" identifier - * (Don't trust this, see below.) - * @KDBUS_ITEM_EXE: The path of the executable - * (Don't trust this, see below.) - * @KDBUS_ITEM_CMDLINE: The process command line - * (Don't trust this, see below.) - * @KDBUS_ITEM_CGROUP: The croup membership - * @KDBUS_ITEM_CAPS: The process capabilities - * @KDBUS_ITEM_SECLABEL: The security label - * @KDBUS_ITEM_AUDIT: The audit IDs - * @KDBUS_ITEM_CONN_DESCRIPTION: The connection's human-readable name - * (debugging) - * @_KDBUS_ITEM_POLICY_BASE: Start of policy items - * @KDBUS_ITEM_POLICY_ACCESS: Policy access block - * @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items - * @KDBUS_ITEM_NAME_ADD: Notification in kdbus_notify_name_change - * @KDBUS_ITEM_NAME_REMOVE: Notification in kdbus_notify_name_change - * @KDBUS_ITEM_NAME_CHANGE: Notification in kdbus_notify_name_change - * @KDBUS_ITEM_ID_ADD: Notification in kdbus_notify_id_change - * @KDBUS_ITEM_ID_REMOVE: Notification in kdbus_notify_id_change - * @KDBUS_ITEM_REPLY_TIMEOUT: Timeout has been reached - * @KDBUS_ITEM_REPLY_DEAD: Destination died - * - * N.B: The process and thread COMM fields, as well as the CMDLINE and - * EXE fields may be altered by unprivileged processes und should - * hence *not* used for security decisions. Peers should make use of - * these items only for informational purposes, such as generating log - * records. - */ -enum kdbus_item_type { - _KDBUS_ITEM_NULL, - _KDBUS_ITEM_USER_BASE, - KDBUS_ITEM_NEGOTIATE = _KDBUS_ITEM_USER_BASE, - KDBUS_ITEM_PAYLOAD_VEC, - KDBUS_ITEM_PAYLOAD_OFF, - KDBUS_ITEM_PAYLOAD_MEMFD, - KDBUS_ITEM_FDS, - KDBUS_ITEM_CANCEL_FD, - KDBUS_ITEM_BLOOM_PARAMETER, - KDBUS_ITEM_BLOOM_FILTER, - KDBUS_ITEM_BLOOM_MASK, - KDBUS_ITEM_DST_NAME, - KDBUS_ITEM_MAKE_NAME, - KDBUS_ITEM_ATTACH_FLAGS_SEND, - KDBUS_ITEM_ATTACH_FLAGS_RECV, - KDBUS_ITEM_ID, - KDBUS_ITEM_NAME, - KDBUS_ITEM_DST_ID, - - /* keep these item types in sync with KDBUS_ATTACH_* flags */ - _KDBUS_ITEM_ATTACH_BASE = 0x1000, - KDBUS_ITEM_TIMESTAMP = _KDBUS_ITEM_ATTACH_BASE, - KDBUS_ITEM_CREDS, - KDBUS_ITEM_PIDS, - KDBUS_ITEM_AUXGROUPS, - KDBUS_ITEM_OWNED_NAME, - KDBUS_ITEM_TID_COMM, - KDBUS_ITEM_PID_COMM, - KDBUS_ITEM_EXE, - KDBUS_ITEM_CMDLINE, - KDBUS_ITEM_CGROUP, - KDBUS_ITEM_CAPS, - KDBUS_ITEM_SECLABEL, - KDBUS_ITEM_AUDIT, - KDBUS_ITEM_CONN_DESCRIPTION, - - _KDBUS_ITEM_POLICY_BASE = 0x2000, - KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE, - - _KDBUS_ITEM_KERNEL_BASE = 0x8000, - KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE, - KDBUS_ITEM_NAME_REMOVE, - KDBUS_ITEM_NAME_CHANGE, - KDBUS_ITEM_ID_ADD, - KDBUS_ITEM_ID_REMOVE, - KDBUS_ITEM_REPLY_TIMEOUT, - KDBUS_ITEM_REPLY_DEAD, -}; - -/** - * struct kdbus_item - chain of data blocks - * @size: Overall data record size - * @type: Kdbus_item type of data - * @data: Generic bytes - * @data32: Generic 32 bit array - * @data64: Generic 64 bit array - * @str: Generic string - * @id: Connection ID - * @vec: KDBUS_ITEM_PAYLOAD_VEC - * @creds: KDBUS_ITEM_CREDS - * @audit: KDBUS_ITEM_AUDIT - * @timestamp: KDBUS_ITEM_TIMESTAMP - * @name: KDBUS_ITEM_NAME - * @bloom_parameter: KDBUS_ITEM_BLOOM_PARAMETER - * @bloom_filter: KDBUS_ITEM_BLOOM_FILTER - * @memfd: KDBUS_ITEM_PAYLOAD_MEMFD - * @name_change: KDBUS_ITEM_NAME_ADD - * KDBUS_ITEM_NAME_REMOVE - * KDBUS_ITEM_NAME_CHANGE - * @id_change: KDBUS_ITEM_ID_ADD - * KDBUS_ITEM_ID_REMOVE - * @policy: KDBUS_ITEM_POLICY_ACCESS - */ -struct kdbus_item { - __u64 size; - __u64 type; - union { - __u8 data[0]; - __u32 data32[0]; - __u64 data64[0]; - char str[0]; - - __u64 id; - struct kdbus_vec vec; - struct kdbus_creds creds; - struct kdbus_pids pids; - struct kdbus_audit audit; - struct kdbus_caps caps; - struct kdbus_timestamp timestamp; - struct kdbus_name name; - struct kdbus_bloom_parameter bloom_parameter; - struct kdbus_bloom_filter bloom_filter; - struct kdbus_memfd memfd; - int fds[0]; - struct kdbus_notify_name_change name_change; - struct kdbus_notify_id_change id_change; - struct kdbus_policy_access policy_access; - }; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_msg_flags - type of message - * @KDBUS_MSG_EXPECT_REPLY: Expect a reply message, used for - * method calls. The userspace-supplied - * cookie identifies the message and the - * respective reply carries the cookie - * in cookie_reply - * @KDBUS_MSG_NO_AUTO_START: Do not start a service if the addressed - * name is not currently active. This flag is - * not looked at by the kernel but only - * serves as hint for userspace implementations. - * @KDBUS_MSG_SIGNAL: Treat this message as signal - */ -enum kdbus_msg_flags { - KDBUS_MSG_EXPECT_REPLY = 1ULL << 0, - KDBUS_MSG_NO_AUTO_START = 1ULL << 1, - KDBUS_MSG_SIGNAL = 1ULL << 2, -}; - -/** - * enum kdbus_payload_type - type of payload carried by message - * @KDBUS_PAYLOAD_KERNEL: Kernel-generated simple message - * @KDBUS_PAYLOAD_DBUS: D-Bus marshalling "DBusDBus" - * - * Any payload-type is accepted. Common types will get added here once - * established. - */ -enum kdbus_payload_type { - KDBUS_PAYLOAD_KERNEL, - KDBUS_PAYLOAD_DBUS = 0x4442757344427573ULL, -}; - -/** - * struct kdbus_msg - the representation of a kdbus message - * @size: Total size of the message - * @flags: Message flags (KDBUS_MSG_*), userspace → kernel - * @priority: Message queue priority value - * @dst_id: 64-bit ID of the destination connection - * @src_id: 64-bit ID of the source connection - * @payload_type: Payload type (KDBUS_PAYLOAD_*) - * @cookie: Userspace-supplied cookie, for the connection - * to identify its messages - * @timeout_ns: The time to wait for a message reply from the peer. - * If there is no reply, and the send command is - * executed asynchronously, a kernel-generated message - * with an attached KDBUS_ITEM_REPLY_TIMEOUT item - * is sent to @src_id. For synchronously executed send - * command, the value denotes the maximum time the call - * blocks to wait for a reply. The timeout is expected in - * nanoseconds and as absolute CLOCK_MONOTONIC value. - * @cookie_reply: A reply to the requesting message with the same - * cookie. The requesting connection can match its - * request and the reply with this value - * @items: A list of kdbus_items containing the message payload - */ -struct kdbus_msg { - __u64 size; - __u64 flags; - __s64 priority; - __u64 dst_id; - __u64 src_id; - __u64 payload_type; - __u64 cookie; - union { - __u64 timeout_ns; - __u64 cookie_reply; - }; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_msg_info - returned message container - * @offset: Offset of kdbus_msg slice in pool - * @msg_size: Copy of the kdbus_msg.size field - * @return_flags: Command return flags, kernel → userspace - */ -struct kdbus_msg_info { - __u64 offset; - __u64 msg_size; - __u64 return_flags; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_send_flags - flags for sending messages - * @KDBUS_SEND_SYNC_REPLY: Wait for destination connection to - * reply to this message. The - * KDBUS_CMD_SEND ioctl() will block - * until the reply is received, and - * reply in struct kdbus_cmd_send will - * yield the offset in the sender's pool - * where the reply can be found. - * This flag is only valid if - * @KDBUS_MSG_EXPECT_REPLY is set as well. - */ -enum kdbus_send_flags { - KDBUS_SEND_SYNC_REPLY = 1ULL << 0, -}; - -/** - * struct kdbus_cmd_send - send message - * @size: Overall size of this structure - * @flags: Flags to change send behavior (KDBUS_SEND_*) - * @return_flags: Command return flags, kernel → userspace - * @msg_address: Storage address of the kdbus_msg to send - * @reply: Storage for message reply if KDBUS_SEND_SYNC_REPLY - * was given - * @items: Additional items for this command - */ -struct kdbus_cmd_send { - __u64 size; - __u64 flags; - __u64 return_flags; - __u64 msg_address; - struct kdbus_msg_info reply; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_recv_flags - flags for de-queuing messages - * @KDBUS_RECV_PEEK: Return the next queued message without - * actually de-queuing it, and without installing - * any file descriptors or other resources. It is - * usually used to determine the activating - * connection of a bus name. - * @KDBUS_RECV_DROP: Drop and free the next queued message and all - * its resources without actually receiving it. - * @KDBUS_RECV_USE_PRIORITY: Only de-queue messages with the specified or - * higher priority (lowest values); if not set, - * the priority value is ignored. - */ -enum kdbus_recv_flags { - KDBUS_RECV_PEEK = 1ULL << 0, - KDBUS_RECV_DROP = 1ULL << 1, - KDBUS_RECV_USE_PRIORITY = 1ULL << 2, -}; - -/** - * enum kdbus_recv_return_flags - return flags for message receive commands - * @KDBUS_RECV_RETURN_INCOMPLETE_FDS: One or more file descriptors could not - * be installed. These descriptors in - * KDBUS_ITEM_FDS will carry the value -1. - * @KDBUS_RECV_RETURN_DROPPED_MSGS: There have been dropped messages since - * the last time a message was received. - * The 'dropped_msgs' counter contains the - * number of messages dropped pool - * overflows or other missed broadcasts. - */ -enum kdbus_recv_return_flags { - KDBUS_RECV_RETURN_INCOMPLETE_FDS = 1ULL << 0, - KDBUS_RECV_RETURN_DROPPED_MSGS = 1ULL << 1, -}; - -/** - * struct kdbus_cmd_recv - struct to de-queue a buffered message - * @size: Overall size of this object - * @flags: KDBUS_RECV_* flags, userspace → kernel - * @return_flags: Command return flags, kernel → userspace - * @priority: Minimum priority of the messages to de-queue. Lowest - * values have the highest priority. - * @dropped_msgs: In case there were any dropped messages since the last - * time a message was received, this will be set to the - * number of lost messages and - * KDBUS_RECV_RETURN_DROPPED_MSGS will be set in - * 'return_flags'. This can only happen if the ioctl - * returns 0 or EAGAIN. - * @msg: Return storage for received message. - * @items: Additional items for this command. - * - * This struct is used with the KDBUS_CMD_RECV ioctl. - */ -struct kdbus_cmd_recv { - __u64 size; - __u64 flags; - __u64 return_flags; - __s64 priority; - __u64 dropped_msgs; - struct kdbus_msg_info msg; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_cmd_free - struct to free a slice of memory in the pool - * @size: Overall size of this structure - * @flags: Flags for the free command, userspace → kernel - * @return_flags: Command return flags, kernel → userspace - * @offset: The offset of the memory slice, as returned by other - * ioctls - * @items: Additional items to modify the behavior - * - * This struct is used with the KDBUS_CMD_FREE ioctl. - */ -struct kdbus_cmd_free { - __u64 size; - __u64 flags; - __u64 return_flags; - __u64 offset; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello - * @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception of - * any passed file descriptors - * @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers - * a well-know name for a process to be started - * when traffic arrives - * @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers - * policy entries for a name. The provided name - * is not activated and not registered with the - * name database, it only allows unprivileged - * connections to acquire a name, talk or discover - * a service - * @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor - * bus traffic - */ -enum kdbus_hello_flags { - KDBUS_HELLO_ACCEPT_FD = 1ULL << 0, - KDBUS_HELLO_ACTIVATOR = 1ULL << 1, - KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2, - KDBUS_HELLO_MONITOR = 1ULL << 3, -}; - -/** - * struct kdbus_cmd_hello - struct to say hello to kdbus - * @size: The total size of the structure - * @flags: Connection flags (KDBUS_HELLO_*), userspace → kernel - * @return_flags: Command return flags, kernel → userspace - * @attach_flags_send: Mask of metadata to attach to each message sent - * off by this connection (KDBUS_ATTACH_*) - * @attach_flags_recv: Mask of metadata to attach to each message receieved - * by the new connection (KDBUS_ATTACH_*) - * @bus_flags: The flags field copied verbatim from the original - * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful - * to do negotiation of features of the payload that is - * transferred (kernel → userspace) - * @id: The ID of this connection (kernel → userspace) - * @pool_size: Size of the connection's buffer where the received - * messages are placed - * @offset: Pool offset where items are returned to report - * additional information about the bus and the newly - * created connection. - * @items_size: Size of buffer returned in the pool slice at @offset. - * @id128: Unique 128-bit ID of the bus (kernel → userspace) - * @items: A list of items - * - * This struct is used with the KDBUS_CMD_HELLO ioctl. - */ -struct kdbus_cmd_hello { - __u64 size; - __u64 flags; - __u64 return_flags; - __u64 attach_flags_send; - __u64 attach_flags_recv; - __u64 bus_flags; - __u64 id; - __u64 pool_size; - __u64 offset; - __u64 items_size; - __u8 id128[16]; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_info - connection information - * @size: total size of the struct - * @id: 64bit object ID - * @flags: object creation flags - * @items: list of items - * - * Note that the user is responsible for freeing the allocated memory with - * the KDBUS_CMD_FREE ioctl. - */ -struct kdbus_info { - __u64 size; - __u64 id; - __u64 flags; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_list_flags - what to include into the returned list - * @KDBUS_LIST_UNIQUE: active connections - * @KDBUS_LIST_ACTIVATORS: activator connections - * @KDBUS_LIST_NAMES: known well-known names - * @KDBUS_LIST_QUEUED: queued-up names - */ -enum kdbus_list_flags { - KDBUS_LIST_UNIQUE = 1ULL << 0, - KDBUS_LIST_NAMES = 1ULL << 1, - KDBUS_LIST_ACTIVATORS = 1ULL << 2, - KDBUS_LIST_QUEUED = 1ULL << 3, -}; - -/** - * struct kdbus_cmd_list - list connections - * @size: overall size of this object - * @flags: flags for the query (KDBUS_LIST_*), userspace → kernel - * @return_flags: command return flags, kernel → userspace - * @offset: Offset in the caller's pool buffer where an array of - * kdbus_info objects is stored. - * The user must use KDBUS_CMD_FREE to free the - * allocated memory. - * @list_size: size of returned list in bytes - * @items: Items for the command. Reserved for future use. - * - * This structure is used with the KDBUS_CMD_LIST ioctl. - */ -struct kdbus_cmd_list { - __u64 size; - __u64 flags; - __u64 return_flags; - __u64 offset; - __u64 list_size; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * struct kdbus_cmd_info - struct used for KDBUS_CMD_CONN_INFO ioctl - * @size: The total size of the struct - * @flags: Flags for this ioctl, userspace → kernel - * @return_flags: Command return flags, kernel → userspace - * @id: The 64-bit ID of the connection. If set to zero, passing - * @name is required. kdbus will look up the name to - * determine the ID in this case. - * @attach_flags: Set of attach flags to specify the set of information - * to receive, userspace → kernel - * @offset: Returned offset in the caller's pool buffer where the - * kdbus_info struct result is stored. The user must - * use KDBUS_CMD_FREE to free the allocated memory. - * @info_size: Output buffer to report size of data at @offset. - * @items: The optional item list, containing the - * well-known name to look up as a KDBUS_ITEM_NAME. - * Only needed in case @id is zero. - * - * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will - * tell the user the offset in the connection pool buffer at which to find the - * result in a struct kdbus_info. - */ -struct kdbus_cmd_info { - __u64 size; - __u64 flags; - __u64 return_flags; - __u64 id; - __u64 attach_flags; - __u64 offset; - __u64 info_size; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_cmd_match_flags - flags to control the KDBUS_CMD_MATCH_ADD ioctl - * @KDBUS_MATCH_REPLACE: If entries with the supplied cookie already - * exists, remove them before installing the new - * matches. - */ -enum kdbus_cmd_match_flags { - KDBUS_MATCH_REPLACE = 1ULL << 0, -}; - -/** - * struct kdbus_cmd_match - struct to add or remove matches - * @size: The total size of the struct - * @flags: Flags for match command (KDBUS_MATCH_*), - * userspace → kernel - * @return_flags: Command return flags, kernel → userspace - * @cookie: Userspace supplied cookie. When removing, the cookie - * identifies the match to remove - * @items: A list of items for additional information - * - * This structure is used with the KDBUS_CMD_MATCH_ADD and - * KDBUS_CMD_MATCH_REMOVE ioctl. - */ -struct kdbus_cmd_match { - __u64 size; - __u64 flags; - __u64 return_flags; - __u64 cookie; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,ENDPOINT}_MAKE - * @KDBUS_MAKE_ACCESS_GROUP: Make the bus or endpoint node group-accessible - * @KDBUS_MAKE_ACCESS_WORLD: Make the bus or endpoint node world-accessible - */ -enum kdbus_make_flags { - KDBUS_MAKE_ACCESS_GROUP = 1ULL << 0, - KDBUS_MAKE_ACCESS_WORLD = 1ULL << 1, -}; - -/** - * enum kdbus_name_flags - flags for KDBUS_CMD_NAME_ACQUIRE - * @KDBUS_NAME_REPLACE_EXISTING: Try to replace name of other connections - * @KDBUS_NAME_ALLOW_REPLACEMENT: Allow the replacement of the name - * @KDBUS_NAME_QUEUE: Name should be queued if busy - * @KDBUS_NAME_IN_QUEUE: Name is queued - * @KDBUS_NAME_ACTIVATOR: Name is owned by a activator connection - * @KDBUS_NAME_PRIMARY: Primary owner of the name - * @KDBUS_NAME_ACQUIRED: Name was acquired/queued _now_ - */ -enum kdbus_name_flags { - KDBUS_NAME_REPLACE_EXISTING = 1ULL << 0, - KDBUS_NAME_ALLOW_REPLACEMENT = 1ULL << 1, - KDBUS_NAME_QUEUE = 1ULL << 2, - KDBUS_NAME_IN_QUEUE = 1ULL << 3, - KDBUS_NAME_ACTIVATOR = 1ULL << 4, - KDBUS_NAME_PRIMARY = 1ULL << 5, - KDBUS_NAME_ACQUIRED = 1ULL << 6, -}; - -/** - * struct kdbus_cmd - generic ioctl payload - * @size: Overall size of this structure - * @flags: Flags for this ioctl, userspace → kernel - * @return_flags: Ioctl return flags, kernel → userspace - * @items: Additional items to modify the behavior - * - * This is a generic ioctl payload object. It's used by all ioctls that only - * take flags and items as input. - */ -struct kdbus_cmd { - __u64 size; - __u64 flags; - __u64 return_flags; - struct kdbus_item items[0]; -} __attribute__((__aligned__(8))); - -/** - * Ioctl API - * - * KDBUS_CMD_BUS_MAKE: After opening the "control" node, this command - * creates a new bus with the specified - * name. The bus is immediately shut down and - * cleaned up when the opened file descriptor is - * closed. - * - * KDBUS_CMD_ENDPOINT_MAKE: Creates a new named special endpoint to talk to - * the bus. Such endpoints usually carry a more - * restrictive policy and grant restricted access - * to specific applications. - * KDBUS_CMD_ENDPOINT_UPDATE: Update the properties of a custom enpoint. Used - * to update the policy. - * - * KDBUS_CMD_HELLO: By opening the bus node, a connection is - * created. After a HELLO the opened connection - * becomes an active peer on the bus. - * KDBUS_CMD_UPDATE: Update the properties of a connection. Used to - * update the metadata subscription mask and - * policy. - * KDBUS_CMD_BYEBYE: Disconnect a connection. If there are no - * messages queued up in the connection's pool, - * the call succeeds, and the handle is rendered - * unusable. Otherwise, -EBUSY is returned without - * any further side-effects. - * KDBUS_CMD_FREE: Release the allocated memory in the receiver's - * pool. - * KDBUS_CMD_CONN_INFO: Retrieve credentials and properties of the - * initial creator of the connection. The data was - * stored at registration time and does not - * necessarily represent the connected process or - * the actual state of the process. - * KDBUS_CMD_BUS_CREATOR_INFO: Retrieve information of the creator of the bus - * a connection is attached to. - * - * KDBUS_CMD_SEND: Send a message and pass data from userspace to - * the kernel. - * KDBUS_CMD_RECV: Receive a message from the kernel which is - * placed in the receiver's pool. - * - * KDBUS_CMD_NAME_ACQUIRE: Request a well-known bus name to associate with - * the connection. Well-known names are used to - * address a peer on the bus. - * KDBUS_CMD_NAME_RELEASE: Release a well-known name the connection - * currently owns. - * KDBUS_CMD_LIST: Retrieve the list of all currently registered - * well-known and unique names. - * - * KDBUS_CMD_MATCH_ADD: Install a match which broadcast messages should - * be delivered to the connection. - * KDBUS_CMD_MATCH_REMOVE: Remove a current match for broadcast messages. - */ -enum kdbus_ioctl_type { - /* bus owner (00-0f) */ - KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x00, - struct kdbus_cmd), - - /* endpoint owner (10-1f) */ - KDBUS_CMD_ENDPOINT_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x10, - struct kdbus_cmd), - KDBUS_CMD_ENDPOINT_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x11, - struct kdbus_cmd), - - /* connection owner (80-ff) */ - KDBUS_CMD_HELLO = _IOWR(KDBUS_IOCTL_MAGIC, 0x80, - struct kdbus_cmd_hello), - KDBUS_CMD_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x81, - struct kdbus_cmd), - KDBUS_CMD_BYEBYE = _IOW(KDBUS_IOCTL_MAGIC, 0x82, - struct kdbus_cmd), - KDBUS_CMD_FREE = _IOW(KDBUS_IOCTL_MAGIC, 0x83, - struct kdbus_cmd_free), - KDBUS_CMD_CONN_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x84, - struct kdbus_cmd_info), - KDBUS_CMD_BUS_CREATOR_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x85, - struct kdbus_cmd_info), - KDBUS_CMD_LIST = _IOR(KDBUS_IOCTL_MAGIC, 0x86, - struct kdbus_cmd_list), - - KDBUS_CMD_SEND = _IOW(KDBUS_IOCTL_MAGIC, 0x90, - struct kdbus_cmd_send), - KDBUS_CMD_RECV = _IOR(KDBUS_IOCTL_MAGIC, 0x91, - struct kdbus_cmd_recv), - - KDBUS_CMD_NAME_ACQUIRE = _IOW(KDBUS_IOCTL_MAGIC, 0xa0, - struct kdbus_cmd), - KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOCTL_MAGIC, 0xa1, - struct kdbus_cmd), - - KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOCTL_MAGIC, 0xb0, - struct kdbus_cmd_match), - KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOCTL_MAGIC, 0xb1, - struct kdbus_cmd_match), -}; - -#endif /* _UAPI_KDBUS_H_ */ diff --git a/packaging/libdbuspolicy.spec b/packaging/libdbuspolicy.spec index 087c42a..13ee4bb 100644 --- a/packaging/libdbuspolicy.spec +++ b/packaging/libdbuspolicy.spec @@ -12,11 +12,15 @@ BuildRequires: boost-devel BuildRequires: libexpat-devel BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(dlog) +BuildRequires: linux-tizen-modules-headers Requires: %{name}-serializer %package devel License: MIT and LGPL-2.1+ Summary: Helper library for fine-grained userspace policy handling-development package +# NB: The following is because we want libdbuspolicy-devel to provide the Tizen kernel headers directly. +# This way, installing this package provides a complete kdbus development environment. +Requires: linux-tizen-modules-headers %package serializer Summary: Tool to serialize dbus policy @@ -111,9 +115,6 @@ mkdir -p -m755 %{buildroot}%{_unitdir} install -m644 libdbuspolicy-verify-data.target %{buildroot}/%{_unitdir}/ install -m644 libdbuspolicy-verify-data.service %{buildroot}/%{_unitdir}/ -mkdir -p -m755 %{buildroot}%{_includedir}/linux/ -install -m644 include/linux/kdbus.h %{buildroot}%{_includedir}/linux/ - %post -p /sbin/ldconfig %postun -p /sbin/ldconfig -- 2.7.4 From b6cb601927f19a2cba9c4accf151bd55f2798300 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 20 Jul 2023 00:56:08 +0200 Subject: [PATCH 15/16] Switch to openssl3 Change-Id: I320c21c7434c748fda55928af06c4fbcee1ac323 --- packaging/libdbuspolicy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libdbuspolicy.spec b/packaging/libdbuspolicy.spec index 13ee4bb..899cc32 100644 --- a/packaging/libdbuspolicy.spec +++ b/packaging/libdbuspolicy.spec @@ -13,6 +13,7 @@ BuildRequires: libexpat-devel BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(dlog) BuildRequires: linux-tizen-modules-headers +BuildRequires: pkgconfig(openssl3) Requires: %{name}-serializer %package devel @@ -24,7 +25,6 @@ Requires: linux-tizen-modules-headers %package serializer Summary: Tool to serialize dbus policy -BuildRequires: pkgconfig(openssl1.1) %package assert-data-valid Requires: %{name}-serializer -- 2.7.4 From 8caa586db582d2eb0c2da95890d4fb7453036295 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 26 Jun 2023 15:56:32 +0200 Subject: [PATCH 16/16] Fix GCC 13 incompatibilities Change-Id: I4a1f4098a3fadba81c9c44801f1ec80dc8ce2c41 --- src/internal/array_with_size.hpp | 1 + src/internal/cynara.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/internal/array_with_size.hpp b/src/internal/array_with_size.hpp index e057d36..21903c5 100644 --- a/src/internal/array_with_size.hpp +++ b/src/internal/array_with_size.hpp @@ -22,6 +22,7 @@ #pragma once #include +#include template class ArrayWithSize : public std::array { diff --git a/src/internal/cynara.hpp b/src/internal/cynara.hpp index 3802d72..d6afefa 100644 --- a/src/internal/cynara.hpp +++ b/src/internal/cynara.hpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace ldp_cynara { enum class CynaraResult : uint8_t { -- 2.7.4