chromium/third_party/flatbuffers/src/include/flatbuffers/flexbuffers.h

/*
 * 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 <algorithm>
#include <map>
// 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 <intrin.h>
#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 {};

// These are used as the upper 6 bits of a type field to indicate the actual
// type.
enum Type {};

inline bool IsInline(Type t) {}

inline bool IsTypedVectorElementType(Type t) {}

inline bool IsTypedVector(Type t) {}

inline bool IsFixedTypedVector(Type t) {}

inline Type ToTypedVector(Type t, size_t fixed_len = 0) {}

inline Type ToTypedVectorElementType(Type t) {}

inline Type ToFixedTypedVectorElementType(Type t, uint8_t *len) {}

// TODO: implement proper support for 8/16bit floats, or decide not to
// support them.
half;
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<typename R, typename T1, typename T2, typename T4, typename T8>
R ReadSizedScalar(const uint8_t *data, uint8_t byte_width) {}

inline int64_t ReadInt64(const uint8_t *data, uint8_t byte_width) {}

inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) {}

inline double ReadDouble(const uint8_t *data, uint8_t byte_width) {}

inline const uint8_t *Indirect(const uint8_t *offset, uint8_t byte_width) {}

template<typename T> const uint8_t *Indirect(const uint8_t *offset) {}

inline BitWidth WidthU(uint64_t u) {}

inline BitWidth WidthI(int64_t i) {}

inline BitWidth WidthF(double f) {}

// Base class of all types below.
// Points into the data buffer and allows access to one type.
class Object {};

// Object that has a size, obtained either from size prefix, or elsewhere.
class Sized : public Object {};

class String : public Sized {};

class Blob : public Sized {};

class Vector : public Sized {};

class TypedVector : public Sized {};

class FixedTypedVector : public Object {};

class Map : public Vector {};

inline void IndentString(std::string &s, int indent,
                         const char *indent_string) {}

template<typename T>
void AppendToString(std::string &s, T &&v, bool keys_quoted, bool indented,
                    int cur_indent, const char *indent_string) {}

template<typename T>
void AppendToString(std::string &s, T &&v, bool keys_quoted) {}


class Reference {};

// Template specialization for As().
template<> inline bool Reference::As<bool>() const {}

template<> inline int8_t Reference::As<int8_t>() const {}
template<> inline int16_t Reference::As<int16_t>() const {}
template<> inline int32_t Reference::As<int32_t>() const {}
template<> inline int64_t Reference::As<int64_t>() const {}

template<> inline uint8_t Reference::As<uint8_t>() const {}
template<> inline uint16_t Reference::As<uint16_t>() const {}
template<> inline uint32_t Reference::As<uint32_t>() const {}
template<> inline uint64_t Reference::As<uint64_t>() const {}

template<> inline double Reference::As<double>() const {}
template<> inline float Reference::As<float>() const {}

template<> inline String Reference::As<String>() const {}
template<> inline std::string Reference::As<std::string>() const {}

template<> inline Blob Reference::As<Blob>() const {}
template<> inline Vector Reference::As<Vector>() const {}
template<> inline TypedVector Reference::As<TypedVector>() const {}
template<> inline FixedTypedVector Reference::As<FixedTypedVector>() const {}
template<> inline Map Reference::As<Map>() const {}

inline uint8_t PackedType(BitWidth bit_width, Type type) {}

inline uint8_t NullPackedType() {}

// 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 {}

inline Reference TypedVector::operator[](size_t i) const {}

inline Reference FixedTypedVector::operator[](size_t i) const {}

template<typename T> int KeyCompare(const void *key, const void *elem) {}

inline Reference Map::operator[](const char *key) const {}

inline Reference Map::operator[](const std::string &key) const {}

inline Reference GetRoot(const uint8_t *buffer, size_t size) {}

inline Reference GetRoot(const std::vector<uint8_t> &buffer) {}

// 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 {};

class Builder FLATBUFFERS_FINAL_CLASS {};

// Helper class to verify the integrity of a FlexBuffer
class Verifier FLATBUFFERS_FINAL_CLASS {};

// Utility function that constructs the Verifier for you, see above for
// parameters.
inline bool VerifyBuffer(const uint8_t *buf, size_t buf_len,
                         std::vector<uint8_t> *reuse_tracker = nullptr) {}

}  // namespace flexbuffers

#if defined(_MSC_VER)
#  pragma warning(pop)
#endif

#endif  // FLATBUFFERS_FLEXBUFFERS_H_