Skip to content
Snippets Groups Projects
Commit 6923946c authored by Tim Übelhör's avatar Tim Übelhör
Browse files

switching to grpc.

unresolved linker issues!
parent 68f07397
Branches main
No related tags found
No related merge requests found
Showing
with 47 additions and 7012 deletions
[submodule "FMU-Core"] [submodule "FMU-Core"]
path = FMU-Core path = FMU-Core
url = https://tim.uebelhoer@git.rwth-aachen.de/ModeliChart/FMU-Core.git url = https://tim.uebelhoer@git.rwth-aachen.de/ModeliChart/FMU-Core.git
[submodule "AdditionalIncludes/MC_Protocol"] [submodule "ModeliProtocol"]
path = AdditionalIncludes/MC_Protocol path = ModeliProtocol
url = https://tim.uebelhoer@git.rwth-aachen.de/ModeliChart/ModeliProtocol.git url = git@git.rwth-aachen.de:ModeliChart/ModeliProtocol.git
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\base.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\code_generators.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\flatbuffers.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\flatc.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\flexbuffers.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\grpc.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\hash.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\idl.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\reflection.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\reflection_generated.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\registry.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\util.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MC_Protocol\ModeliProtocol_generated.h" />
</ItemGroup>
</Project>
\ No newline at end of file
MC_Protocol @ 90d03175
Subproject commit 90d03175c540b263c7e6f3e7efabf741524a9869
#ifndef FLATBUFFERS_BASE_H_
#define FLATBUFFERS_BASE_H_
#include <assert.h>
#ifndef ARDUINO
#include <cstdint>
#endif
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <string>
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
#include <utility.h>
#else
#include <utility>
#endif
#include <type_traits>
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <memory>
#ifdef _STLPORT_VERSION
#define FLATBUFFERS_CPP98_STL
#endif
#ifndef FLATBUFFERS_CPP98_STL
#include <functional>
#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<class T> 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 7
#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))
#define FLATBUFFERS_FINAL_CLASS final
#define FLATBUFFERS_OVERRIDE override
#else
#define FLATBUFFERS_FINAL_CLASS
#define FLATBUFFERS_OVERRIDE
#endif
#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
#define FLATBUFFERS_CONSTEXPR constexpr
#else
#define FLATBUFFERS_CONSTEXPR
#endif
#if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026
#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))
#define FLATBUFFERS_DELETE_FUNC(func) func = delete;
#else
#define FLATBUFFERS_DELETE_FUNC(func) private: func;
#endif
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4127) // C4127: conditional expression is constant
#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
template<typename T> T EndianScalar(T t) {
#if FLATBUFFERS_LITTLEENDIAN
return t;
#else
return EndianSwap(t);
#endif
}
template<typename T> T ReadScalar(const void *p) {
return EndianScalar(*reinterpret_cast<const T *>(p));
}
template<typename T> void WriteScalar(void *p, T t) {
*reinterpret_cast<T *>(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);
}
}
#endif // FLATBUFFERS_BASE_H_
/*
* 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 <map>
#include <sstream>
#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<std::string, std::string> 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<std::string> &dc,
std::string *code_ptr,
const CommentConfig *config,
const char *prefix = "");
} // namespace flatbuffers
#endif // FLATBUFFERS_CODE_GENERATORS_H_
This diff is collapsed.
/*
* 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 "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
#include <functional>
#include <limits>
#include <string>
#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& params) : 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<const char *> &include_directories) const;
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_
This diff is collapsed.
/*
* 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 T>
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<T>(nullptr);
}
T *GetMutableRoot() { return flatbuffers::GetMutableRoot<T>(mutable_data()); }
const T *GetRoot() const { return flatbuffers::GetRoot<T>(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;
virtual ~SliceAllocator() { grpc_slice_unref(slice_); }
virtual uint8_t *allocate(size_t size) override {
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 {
assert(p == GRPC_SLICE_START_PTR(slice_));
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) override {
assert(old_p == GRPC_SLICE_START_PTR(slice_));
assert(old_size == GRPC_SLICE_LENGTH(slice_));
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(new_p + (new_size - old_size), old_p, old_size);
slice_ = new_slice;
grpc_slice_unref(old_slice);
return new_p;
}
private:
grpc_slice &get_slice(uint8_t *p, size_t size) {
assert(p == GRPC_SLICE_START_PTR(slice_));
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_;
};
}
// 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() {}
// GetMessage extracts the subslice of the buffer corresponding to the
// flatbuffers-encoded region and wraps it in a `Message<T>` to handle buffer
// ownership.
template <class T>
Message<T> GetMessage() {
auto buf_data = buf_.buf(); // 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
assert(msg_data);
assert(msg_size);
assert(msg_data >= buf_data);
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<T>`, but don't increment refcount
Message<T> msg(subslice, false);
return msg;
}
template <class T>
Message<T> ReleaseMessage() {
Message<T> msg = GetMessage<T>();
Reset();
return msg;
}
private:
// SliceAllocator slice_allocator_; // part of SliceAllocatorMember
};
} // namespace grpc
} // namespace flatbuffers
namespace grpc {
template <class T>
class SerializationTraits<flatbuffers::grpc::Message<T>> {
public:
static grpc::Status Serialize(const flatbuffers::grpc::Message<T> &msg,
grpc_byte_buffer **buffer, bool *own_buffer) {
// We are passed in a `Message<T>`, 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<grpc_slice *>(&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<T> *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<T>` around the slice, incrementing the refcount.
*msg = flatbuffers::grpc::Message<T>(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<T>` around the slice, but dont increment refcount
*msg = flatbuffers::grpc::Message<T>(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_
/*
* 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 <cstdint>
#include <cstring>
#include "flatbuffers/flatbuffers.h"
namespace flatbuffers {
template <typename T>
struct FnvTraits {
static const T kFnvPrime;
static const T kOffsetBasis;
};
template <>
struct FnvTraits<uint32_t> {
static const uint32_t kFnvPrime = 0x01000193;
static const uint32_t kOffsetBasis = 0x811C9DC5;
};
template <>
struct FnvTraits<uint64_t> {
static const uint64_t kFnvPrime = 0x00000100000001b3ULL;
static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL;
};
template <typename T>
T HashFnv1(const char *input) {
T hash = FnvTraits<T>::kOffsetBasis;
for (const char *c = input; *c; ++c) {
hash *= FnvTraits<T>::kFnvPrime;
hash ^= static_cast<unsigned char>(*c);
}
return hash;
}
template <typename T>
T HashFnv1a(const char *input) {
T hash = FnvTraits<T>::kOffsetBasis;
for (const char *c = input; *c; ++c) {
hash ^= static_cast<unsigned char>(*c);
hash *= FnvTraits<T>::kFnvPrime;
}
return hash;
}
template <typename T>
struct NamedHashFunction {
const char *name;
typedef T (*HashFunction)(const char*);
HashFunction function;
};
const NamedHashFunction<uint32_t> kHashFunctions32[] = {
{ "fnv1_32", HashFnv1<uint32_t> },
{ "fnv1a_32", HashFnv1a<uint32_t> },
};
const NamedHashFunction<uint64_t> kHashFunctions64[] = {
{ "fnv1_64", HashFnv1<uint64_t> },
{ "fnv1a_64", HashFnv1a<uint64_t> },
};
inline NamedHashFunction<uint32_t>::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<uint64_t>::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_
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* 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<const char *>(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_.ReleaseBufferPointer();
}
// 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(), include_paths_.data(),
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<const char *> include_paths_;
std::map<std::string, Schema> schemas_;
};
} // namespace flatbuffers
#endif // FLATBUFFERS_REGISTRY_H_
This diff is collapsed.
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
<ImportGroup Label="Shared"> <ImportGroup Label="Shared">
<Import Project="..\Simulation\Simulation.vcxitems" Label="Shared" /> <Import Project="..\Simulation\Simulation.vcxitems" Label="Shared" />
<Import Project="..\Files\Files.vcxitems" Label="Shared" /> <Import Project="..\Files\Files.vcxitems" Label="Shared" />
<Import Project="..\AdditionalIncludes\AdditionalIncludes.vcxitems" Label="Shared" />
<Import Project="..\Main\Main.vcxitems" Label="Shared" /> <Import Project="..\Main\Main.vcxitems" Label="Shared" />
<Import Project="..\FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems" Label="Shared" /> <Import Project="..\FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems" Label="Shared" />
<Import Project="..\Network\Network.vcxitems" Label="Shared" /> <Import Project="..\Network\Network.vcxitems" Label="Shared" />
... ...
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems> <HasSharedItems>true</HasSharedItems>
<ItemsProjectGuid>{9ff0dfd0-39ec-429c-bd7b-7935bb340006}</ItemsProjectGuid> <ItemsProjectGuid>{9c78546c-04b5-45bb-99c4-9ffbaf846bfe}</ItemsProjectGuid>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup> <ItemDefinitionGroup>
<ClCompile> <ClCompile>
...@@ -14,18 +14,11 @@ ...@@ -14,18 +14,11 @@
<ProjectCapability Include="SourceItemsFromImports" /> <ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\base.h" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\ModeliProtocol\ModeliRpc_Cpp\ModeliRpc.grpc.pb.cc" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\code_generators.h" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\ModeliProtocol\ModeliRpc_Cpp\ModeliRpc.pb.cc" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\flatbuffers.h" /> </ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\flatc.h" /> <ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\flexbuffers.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\ModeliProtocol\ModeliRpc_Cpp\ModeliRpc.grpc.pb.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\grpc.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\ModeliProtocol\ModeliRpc_Cpp\ModeliRpc.pb.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\hash.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\idl.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\reflection.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\reflection_generated.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\registry.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)flatbuffers\util.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MC_Protocol\ModeliProtocol_generated.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26711.1 VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MC_Backend_Linux", "MC_Backend_Linux\MC_Backend_Linux.vcxproj", "{661905CE-1EFD-4D2B-8CC8-0A8BAFB5242F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MC_Backend_Linux", "MC_Backend_Linux\MC_Backend_Linux.vcxproj", "{661905CE-1EFD-4D2B-8CC8-0A8BAFB5242F}"
EndProject EndProject
...@@ -10,8 +10,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MC_Backend_Win", "MC_Backen ...@@ -10,8 +10,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MC_Backend_Win", "MC_Backen
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Files", "Files\Files.vcxitems", "{600C8D4E-39A2-40DD-B779-AC823CD2F5CC}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Files", "Files\Files.vcxitems", "{600C8D4E-39A2-40DD-B779-AC823CD2F5CC}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdditionalIncludes", "AdditionalIncludes\AdditionalIncludes.vcxitems", "{9FF0DFD0-39EC-429C-BD7B-7935BB340006}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeFmuTests", "FMU-Core\NativeFmuTests\NativeFmuTests.vcxproj", "{F31EEB13-5399-4E96-AF1F-B0BCF3119B5F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeFmuTests", "FMU-Core\NativeFmuTests\NativeFmuTests.vcxproj", "{F31EEB13-5399-4E96-AF1F-B0BCF3119B5F}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Network", "Network\Network.vcxitems", "{059B87B7-3153-4B08-B4DB-12F671328EBB}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Network", "Network\Network.vcxitems", "{059B87B7-3153-4B08-B4DB-12F671328EBB}"
...@@ -22,30 +20,29 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Main", "Main\Main.vcxitems" ...@@ -22,30 +20,29 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Main", "Main\Main.vcxitems"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BackendTests", "BackendTests\BackendTests.vcxproj", "{500F1104-28C6-4BE4-A180-8028843972AC}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BackendTests", "BackendTests\BackendTests.vcxproj", "{500F1104-28C6-4BE4-A180-8028843972AC}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CreatedGrpc", "CreatedGrpc\CreatedGrpc.vcxitems", "{9C78546C-04B5-45BB-99C4-9FFBAF846BFE}"
EndProject
Global Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution GlobalSection(SharedMSBuildProjectFiles) = preSolution
Network\Network.vcxitems*{059b87b7-3153-4b08-b4db-12f671328ebb}*SharedItemsImports = 9 Network\Network.vcxitems*{059b87b7-3153-4b08-b4db-12f671328ebb}*SharedItemsImports = 9
AdditionalIncludes\AdditionalIncludes.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4
Files\Files.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4 Files\Files.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4
FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4 FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4
Main\Main.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4 Main\Main.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4
Network\Network.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4 Network\Network.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4
Simulation\Simulation.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4 Simulation\Simulation.vcxitems*{500f1104-28c6-4be4-a180-8028843972ac}*SharedItemsImports = 4
Files\Files.vcxitems*{600c8d4e-39a2-40dd-b779-ac823cd2f5cc}*SharedItemsImports = 9 Files\Files.vcxitems*{600c8d4e-39a2-40dd-b779-ac823cd2f5cc}*SharedItemsImports = 9
AdditionalIncludes\AdditionalIncludes.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4
Files\Files.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4 Files\Files.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4
FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4 FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4
Main\Main.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4 Main\Main.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4
Network\Network.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4 Network\Network.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4
Simulation\Simulation.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4 Simulation\Simulation.vcxitems*{661905ce-1efd-4d2b-8cc8-0a8bafb5242f}*SharedItemsImports = 4
Simulation\Simulation.vcxitems*{8510328c-8540-419b-96d9-1e5ff396366f}*SharedItemsImports = 9 Simulation\Simulation.vcxitems*{8510328c-8540-419b-96d9-1e5ff396366f}*SharedItemsImports = 9
AdditionalIncludes\AdditionalIncludes.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4
Files\Files.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4 Files\Files.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4
FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4 FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4
Main\Main.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4 Main\Main.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4
Network\Network.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4 Network\Network.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4
Simulation\Simulation.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4 Simulation\Simulation.vcxitems*{87f7a408-7c05-47a8-a1d7-4a53ca350666}*SharedItemsImports = 4
AdditionalIncludes\AdditionalIncludes.vcxitems*{9ff0dfd0-39ec-429c-bd7b-7935bb340006}*SharedItemsImports = 9 CreatedGrpc\CreatedGrpc.vcxitems*{9c78546c-04b5-45bb-99c4-9ffbaf846bfe}*SharedItemsImports = 9
FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{b23eb13a-9d85-4f36-8327-543fa7b6a01e}*SharedItemsImports = 9 FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{b23eb13a-9d85-4f36-8327-543fa7b6a01e}*SharedItemsImports = 9
Main\Main.vcxitems*{de14bb19-25d6-4ec9-8878-d5fc8ec737bb}*SharedItemsImports = 9 Main\Main.vcxitems*{de14bb19-25d6-4ec9-8878-d5fc8ec737bb}*SharedItemsImports = 9
FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{f31eeb13-5399-4e96-af1f-b0bcf3119b5f}*SharedItemsImports = 4 FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems*{f31eeb13-5399-4e96-af1f-b0bcf3119b5f}*SharedItemsImports = 4
... ...
......
...@@ -64,7 +64,6 @@ ...@@ -64,7 +64,6 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared"> <ImportGroup Label="Shared">
<Import Project="..\AdditionalIncludes\AdditionalIncludes.vcxitems" Label="Shared" />
<Import Project="..\Files\Files.vcxitems" Label="Shared" /> <Import Project="..\Files\Files.vcxitems" Label="Shared" />
<Import Project="..\FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems" Label="Shared" /> <Import Project="..\FMU-Core\NativeFmuShared\NativeFmuShared.vcxitems" Label="Shared" />
<Import Project="..\Network\Network.vcxitems" Label="Shared" /> <Import Project="..\Network\Network.vcxitems" Label="Shared" />
... ...
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment