1 #ifndef ZSERIO_ARRAY_TRAITS_H_INC 2 #define ZSERIO_ARRAY_TRAITS_H_INC 24 T read_bits(BitStreamReader& in, uint8_t
numBits);
27 inline int8_t read_bits<int8_t>(BitStreamReader& in, uint8_t
numBits)
29 return static_cast<int8_t
>(in.readSignedBits(
numBits));
33 inline int16_t read_bits<int16_t>(BitStreamReader& in, uint8_t
numBits)
35 return static_cast<int16_t
>(in.readSignedBits(
numBits));
39 inline int32_t read_bits<int32_t>(BitStreamReader& in, uint8_t
numBits)
41 return in.readSignedBits(
numBits);
45 inline int64_t read_bits<int64_t>(BitStreamReader& in, uint8_t
numBits)
47 return in.readSignedBits64(
numBits);
51 inline uint8_t read_bits<uint8_t>(BitStreamReader& in, uint8_t
numBits)
53 return static_cast<uint8_t
>(in.readBits(
numBits));
57 inline uint16_t read_bits<uint16_t>(BitStreamReader& in, uint8_t
numBits)
59 return static_cast<uint16_t
>(in.readBits(
numBits));
63 inline uint32_t read_bits<uint32_t>(BitStreamReader& in, uint8_t
numBits)
69 inline uint64_t read_bits<uint64_t>(BitStreamReader& in, uint8_t
numBits)
75 void write_bits(BitStreamWriter& out, T value, uint8_t
numBits);
78 inline void write_bits<int8_t>(BitStreamWriter& out, int8_t value, uint8_t
numBits)
80 out.writeSignedBits(static_cast<int32_t>(value),
numBits);
84 inline void write_bits<int16_t>(BitStreamWriter& out, int16_t value, uint8_t
numBits)
86 out.writeSignedBits(static_cast<int32_t>(value),
numBits);
90 inline void write_bits<int32_t>(BitStreamWriter& out, int32_t value, uint8_t
numBits)
92 out.writeSignedBits(value,
numBits);
96 inline void write_bits<int64_t>(BitStreamWriter& out, int64_t value, uint8_t
numBits)
98 out.writeSignedBits64(value,
numBits);
102 inline void write_bits<uint8_t>(BitStreamWriter& out, uint8_t value, uint8_t
numBits)
104 out.writeBits(static_cast<uint32_t>(value),
numBits);
108 inline void write_bits<uint16_t>(BitStreamWriter& out, uint16_t value, uint8_t
numBits)
110 out.writeBits(static_cast<uint32_t>(value),
numBits);
114 inline void write_bits<uint32_t>(BitStreamWriter& out, uint32_t value, uint8_t
numBits)
120 inline void write_bits<uint64_t>(BitStreamWriter& out, uint64_t value, uint8_t
numBits)
122 out.writeBits64(value,
numBits);
133 template <
typename T, u
int8_t NUM_BITS>
179 return bitPosition + NUM_BITS;
191 return detail::read_bits<T>(in, NUM_BITS);
202 detail::write_bits(out, element, NUM_BITS);
206 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
215 template <
typename T,
typename ELEMENT_BIT_SIZE,
typename =
void>
229 return ELEMENT_BIT_SIZE::get();
273 return detail::read_bits<T>(in, ELEMENT_BIT_SIZE::get());
284 detail::write_bits(out, element, ELEMENT_BIT_SIZE::get());
288 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
297 template <
typename T,
typename ELEMENT_BIT_SIZE>
299 typename std::enable_if<has_owner_type<ELEMENT_BIT_SIZE>::value>::type>
317 return ELEMENT_BIT_SIZE::get(owner);
367 return detail::read_bits<T>(in, ELEMENT_BIT_SIZE::get(owner));
379 detail::write_bits(out, element, ELEMENT_BIT_SIZE::get(owner));
383 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
389 template <
typename T>
434 return bitPosition + NUM_BITS;
446 return detail::read_bits<T>(in, NUM_BITS);
457 detail::write_bits(out, element, NUM_BITS);
461 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
464 static constexpr uint8_t NUM_BITS =
sizeof(T) * 8;
470 template <
typename T>
516 return bitPosition +
bitSizeOf(bitPosition, element);
543 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
589 return bitPosition +
bitSizeOf(bitPosition, element);
616 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
662 return bitPosition +
bitSizeOf(bitPosition, element);
689 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
735 return bitPosition +
bitSizeOf(bitPosition, element);
762 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
808 return bitPosition +
bitSizeOf(bitPosition, element);
835 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
881 return bitPosition +
bitSizeOf(bitPosition, element);
908 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
914 template <
typename T>
960 return bitPosition +
bitSizeOf(bitPosition, element);
987 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1033 return bitPosition +
bitSizeOf(bitPosition, element);
1060 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1105 return bitPosition +
bitSizeOf(bitPosition, element);
1132 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1173 return bitPosition +
bitSizeOf(bitPosition, element);
1200 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
1241 return bitPosition +
bitSizeOf(bitPosition, element);
1268 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
1309 return bitPosition +
bitSizeOf(bitPosition, element);
1336 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
1377 return bitPosition +
bitSizeOf(bitPosition, element);
1404 static constexpr
bool IS_BITSIZEOF_CONSTANT =
true;
1410 template <
template <
typename>
class ALLOC = std::allocator>
1441 return bitPosition +
bitSizeOf(bitPosition, element);
1450 template <
typename RAW_ARRAY>
1453 rawArray.emplace_back(in.
readBytes(rawArray.get_allocator()));
1468 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1476 template <
template <
typename>
class ALLOC = std::allocator>
1507 return bitPosition +
bitSizeOf(bitPosition, element);
1516 template <
typename RAW_ARRAY>
1519 rawArray.emplace_back(in.
readString(rawArray.get_allocator()));
1534 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1542 template <
template <
typename>
class ALLOC = std::allocator>
1573 return bitPosition +
bitSizeOf(bitPosition, element);
1582 template <
typename RAW_ARRAY>
1585 rawArray.emplace_back(in.
readBitBuffer(rawArray.get_allocator()));
1600 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1608 template <
typename T>
1648 return zserio::read<ElementType>(in);
1664 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1670 template <
typename T>
1685 return element.bitSizeOf();
1698 return element.initializeOffsets(bitPosition);
1726 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1732 template <
typename T,
typename ELEMENT_FACTORY>
1755 return element.bitSizeOf(bitPosition);
1768 return element.initializeOffsets(bitPosition);
1779 template <
typename RAW_ARRAY>
1783 ELEMENT_FACTORY::create(owner, rawArray, in, index);
1798 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1804 template <
typename ARRAY_TRAITS>
1805 struct packed_array_traits_overloaded : std::false_type
1808 template <
typename T,
typename ELEMENT_FACTORY>
1809 struct packed_array_traits_overloaded<ObjectArrayTraits<T, ELEMENT_FACTORY>> : std::true_type
1819 template <
typename ARRAY_TRAITS,
typename =
void>
1839 deltaContext.template init<ArrayTraits>(element);
1854 return deltaContext.template bitSizeOf<ArrayTraits>(element);
1870 return bitPosition +
bitSizeOf(deltaContext, bitPosition, element);
1885 return deltaContext.template read<ArrayTraits>(in);
1899 deltaContext.template write<ArrayTraits>(out, element);
1908 template <
typename ARRAY_TRAITS>
1909 class PackedArrayTraits<ARRAY_TRAITS, typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value>::type>
1932 deltaContext.template init<ArrayTraits>(owner, element);
1949 return deltaContext.template bitSizeOf<ArrayTraits>(owner, element);
1967 return bitPosition +
bitSizeOf(owner, deltaContext, bitPosition, element);
1983 return deltaContext.template read<ArrayTraits>(owner, in);
1999 deltaContext.template write<ArrayTraits>(owner, out, element);
2006 template <
typename T>
2065 return zserio::read<ElementType>(deltaContext, in);
2084 template <
typename T>
2101 element.initPackingContext(deltaContext);
2115 return element.bitSizeOf(deltaContext, bitPosition);
2129 return element.initializeOffsets(deltaContext, bitPosition);
2154 element.write(deltaContext, out);
2162 template <
typename T,
typename ELEMENT_FACTORY>
2164 typename std::enable_if<has_owner_type<ObjectArrayTraits<T, ELEMENT_FACTORY>>::value>::type>
2184 template <
typename PACKING_CONTEXT>
2186 PACKING_CONTEXT& packingContext,
const ElementType& element)
2188 element.initPackingContext(packingContext);
2200 template <
typename PACKING_CONTEXT>
2202 PACKING_CONTEXT& packingContext,
size_t bitPosition,
const ElementType& element)
2204 return element.bitSizeOf(packingContext, bitPosition);
2216 template <
typename PACKING_CONTEXT>
2218 PACKING_CONTEXT& packingContext,
size_t bitPosition,
ElementType& element)
2220 return element.initializeOffsets(packingContext, bitPosition);
2233 template <
typename RAW_ARRAY,
typename PACKING_CONTEXT>
2237 ELEMENT_FACTORY::create(owner, rawArray, packingContext, in, index);
2247 template <
typename PACKING_CONTEXT>
2251 element.write(packingContext, out);
2257 #endif // ZSERIO_ARRAY_TRAITS_H_INC void writeVarInt64(int64_t data)
static size_t bitSizeOf(DeltaContext &deltaContext, size_t bitPosition, const ElementType &element)
void writeVarUInt16(uint16_t data)
static ElementType read(const OwnerType &owner, DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
static ElementType read(BitStreamReader &in, size_t=0)
void writeBytes(Span< const uint8_t > data)
void writeFloat16(float data)
static size_t bitSizeOf(size_t, ElementType element)
static void initContext(DeltaContext &deltaContext, ElementType element)
static size_t bitSizeOf(ElementType element)
typename ELEMENT_FACTORY::OwnerType OwnerType
static size_t initializeOffsets(size_t bitPosition, ElementType element)
void writeVarUInt64(uint64_t data)
void writeVarInt16(int16_t data)
size_t bitSizeOfVarUInt64(uint64_t value)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType)
static void write(BitStreamWriter &out, ElementType element)
typename ElementType::allocator_type allocator_type
static size_t bitSizeOf(ElementType element)
uint8_t numBits(uint64_t numValues)
BasicBitBuffer< RebindAlloc< ALLOC, uint8_t > > readBitBuffer(const ALLOC &allocator=ALLOC())
static size_t bitSizeOf(ElementType element)
static size_t bitSizeOf(ElementType element)
static size_t bitSizeOf(ElementType)
typename ARRAY_TRAITS::ElementType ElementType
static size_t initializeOffsets(size_t bitPosition, ElementType)
static void write(BitStreamWriter &out, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
void writeFloat32(float data)
static void read(typename ArrayTraits::OwnerType &owner, RAW_ARRAY &rawArray, PACKING_CONTEXT &packingContext, BitStreamReader &in, size_t index)
static void write(const OwnerType &, BitStreamWriter &out, const ElementType &element)
static size_t bitSizeOf(size_t, ElementType)
static void write(BitStreamWriter &out, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
zserio::string< ALLOC< char >> ElementType
static size_t initializeOffsets(size_t bitPosition, ElementType)
static void write(const OwnerType &owner, DeltaContext &deltaContext, BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(ElementType element)
static size_t bitSizeOf(ElementType)
static void initContext(DeltaContext &deltaContext, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static size_t bitSizeOf(ElementType element)
void writeBitBuffer(const BasicBitBuffer< ALLOC > &bitBuffer)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
void writeVarInt(int64_t data)
static size_t bitSizeOf(size_t, ElementType)
typename ARRAY_TRAITS::ElementType ElementType
void writeVarInt32(int32_t data)
static ElementType read(BitStreamReader &in, size_t=0)
void writeVarUInt32(uint32_t data)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static void initContext(DeltaContext &deltaContext, const ElementType &element)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
void writeString(StringView data)
static void initContext(const OwnerType &owner, DeltaContext &deltaContext, ElementType element)
typename ElementType::allocator_type allocator_type
static size_t bitSizeOf(size_t, ElementType element)
static size_t initializeOffsets(OwnerType &, size_t bitPosition, ElementType &element)
static size_t initializeOffsets(const OwnerType &owner, DeltaContext &deltaContext, size_t bitPosition, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
size_t bitSizeOfBytes(Span< const uint8_t > bytesValue)
static void write(DeltaContext &deltaContext, BitStreamWriter &out, const ElementType &element)
void writeVarSize(uint32_t data)
static size_t bitSizeOf(size_t, ElementType)
static size_t bitSizeOf(const OwnerType &owner, ElementType)
static ElementType read(BitStreamReader &in, size_t=0)
size_t bitSizeOfVarSize(uint32_t value)
static void read(RAW_ARRAY &rawArray, BitStreamReader &in, size_t=0)
static size_t bitSizeOf(size_t, const ElementType &element)
static size_t bitSizeOf(ElementType element)
static void read(OwnerType &owner, RAW_ARRAY &rawArray, BitStreamReader &in, size_t index)
static ElementType read(BitStreamReader &in, size_t=0)
size_t bitSizeOfVarInt64(int64_t value)
size_t bitSizeOfVarInt16(int16_t value)
static size_t bitSizeOf()
static size_t bitSizeOf(size_t, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static ElementType read(const OwnerType &owner, BitStreamReader &in, size_t=0)
size_t bitSizeOfVarUInt16(uint16_t value)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf()
static size_t initializeOffsets(size_t bitPosition, ElementType element)
size_t bitSizeOfBitBuffer(const BasicBitBuffer< ALLOC > &bitBuffer)
void write(BitStreamWriter &out, T value)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t initializeOffsets(size_t bitPosition, const ElementType &element)
static size_t bitSizeOf(DeltaContext &deltaContext, size_t, ElementType element)
static void write(const OwnerType &owner, BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(ElementType element)
static void write(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, BitStreamWriter &out, const ElementType &element)
static size_t bitSizeOf(const OwnerType &, size_t bitPosition, const ElementType &element)
static size_t bitSizeOf(size_t, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(DeltaContext &deltaContext, size_t bitPosition, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static size_t initializeOffsets(const OwnerType &owner, size_t bitPosition, ElementType)
void writeFloat64(double data)
size_t bitSizeOfVarUInt32(uint32_t value)
static size_t bitSizeOf(ElementType element)
static size_t bitSizeOf()
static void write(BitStreamWriter &out, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf(size_t, ElementType element)
static size_t bitSizeOf(DeltaContext &deltaContext, size_t, ElementType element)
void writeVarUInt(uint64_t data)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf(size_t, const ElementType &element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
typename ArrayTraits::OwnerType OwnerType
static ElementType read(BitStreamReader &in, size_t=0)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(const OwnerType &owner)
std::vector< T, RebindAlloc< ALLOC, T >> vector
static size_t bitSizeOf(size_t, ElementType)
static size_t bitSizeOf(size_t, ElementType element)
static void write(BitStreamWriter &out, const ElementType &element)
size_t bitSizeOfVarUInt(uint64_t value)
static size_t bitSizeOf(size_t, ElementType)
static void initContext(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, const ElementType &element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf()
static ElementType read(DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
static ElementType read(BitStreamReader &in, size_t=0)
size_t bitSizeOfVarInt(int64_t value)
static void write(DeltaContext &deltaContext, BitStreamWriter &out, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(DeltaContext &deltaContext, size_t bitPosition, ElementType element)
static void read(RAW_ARRAY &rawArray, BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
size_t bitSizeOfString(StringView stringValue)
typename ElementType::allocator_type allocator_type
static size_t bitSizeOf(size_t, ElementType)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
vector< uint8_t, ALLOC > readBytes(const ALLOC &alloc=ALLOC())
static size_t bitSizeOf(const OwnerType &owner, size_t, ElementType)
static ElementType read(BitStreamReader &in, size_t=0)
static void read(RAW_ARRAY &rawArray, BitStreamReader &in, size_t=0)
size_t initializeOffsets(size_t bitPosition, T value)
static void write(BitStreamWriter &out, ElementType element)
static void write(BitStreamWriter &out, const ElementType &element)
static void write(BitStreamWriter &out, ElementType element)
zserio::vector< uint8_t, ALLOC< uint8_t >> ElementType
void writeBool(bool data)
typename ARRAY_TRAITS::OwnerType OwnerType
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char >> string
static size_t bitSizeOf(ElementType)
typename T::allocator_type allocator_type
static ElementType read(DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
void initPackingContext(PACKING_CONTEXT &context, T value)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(size_t, const ElementType &element)
size_t bitSizeOfVarInt32(int32_t value)
static size_t bitSizeOf()
static size_t bitSizeOf()
size_t bitSizeOf(T value)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
typename ELEMENT_BIT_SIZE::OwnerType OwnerType
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, size_t bitPosition, const ElementType &element)
static size_t initializeOffsets(DeltaContext &deltaContext, size_t bitPosition, const ElementType &element)
static size_t bitSizeOf(size_t, ElementType element)
static void write(BitStreamWriter &out, const ElementType &element)
static size_t bitSizeOf()
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(const OwnerType &owner, DeltaContext &deltaContext, size_t, ElementType element)
static ElementType read(DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
typename ElementType::allocator_type allocator_type
static void write(DeltaContext &deltaContext, BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType)
static size_t initializeOffsets(size_t bitPosition, const ElementType &element)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, const ElementType &element)
static size_t initializeOffsets(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, size_t bitPosition, ElementType &element)
string< ALLOC > readString(const ALLOC &alloc=ALLOC())
static void write(BitStreamWriter &out, ElementType element)