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);
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());
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));
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);
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);
1173 return bitPosition +
bitSizeOf(bitPosition, element);
1241 return bitPosition +
bitSizeOf(bitPosition, element);
1309 return bitPosition +
bitSizeOf(bitPosition, element);
1377 return bitPosition +
bitSizeOf(bitPosition, element);
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()));
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()));
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()));
1608 template <
typename T>
1648 return zserio::read<ElementType>(in);
1670 template <
typename T>
1685 return element.bitSizeOf();
1698 return element.initializeOffsets(bitPosition);
1732 template <
typename T,
typename ELEMENT_FACTORY>
1755 return element.bitSizeOf(bitPosition);
1768 return element.initializeOffsets(bitPosition);
1779 template <
typename RAW_ARRAY>
1782 ELEMENT_FACTORY::create(owner, rawArray, in, index);
1803 template <
typename ARRAY_TRAITS>
1804 struct packed_array_traits_overloaded : std::false_type
1807 template <
typename T,
typename ELEMENT_FACTORY>
1808 struct packed_array_traits_overloaded<ObjectArrayTraits<T, ELEMENT_FACTORY>> : std::true_type
1818 template <
typename ARRAY_TRAITS,
typename =
void>
1838 deltaContext.template init<ArrayTraits>(element);
1853 return deltaContext.template bitSizeOf<ArrayTraits>(element);
1869 return bitPosition +
bitSizeOf(deltaContext, bitPosition, element);
1884 return deltaContext.template read<ArrayTraits>(in);
1898 deltaContext.template write<ArrayTraits>(out, element);
1907 template <
typename ARRAY_TRAITS>
1908 class PackedArrayTraits<ARRAY_TRAITS, typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value>::type>
1931 deltaContext.template init<ArrayTraits>(owner, element);
1947 return deltaContext.template bitSizeOf<ArrayTraits>(owner, element);
1965 return bitPosition +
bitSizeOf(owner, deltaContext, bitPosition, element);
1981 return deltaContext.template read<ArrayTraits>(owner, in);
1997 deltaContext.template write<ArrayTraits>(owner, out, element);
2004 template <
typename T>
2062 return zserio::read<ElementType>(deltaContext, in);
2081 template <
typename T>
2098 element.initPackingContext(deltaContext);
2112 return element.bitSizeOf(deltaContext, bitPosition);
2126 return element.initializeOffsets(deltaContext, bitPosition);
2151 element.write(deltaContext, out);
2159 template <
typename T,
typename ELEMENT_FACTORY>
2161 typename std::enable_if<has_owner_type<ObjectArrayTraits<T, ELEMENT_FACTORY>>::value>::type>
2181 template <
typename PACKING_CONTEXT>
2185 element.initPackingContext(packingContext);
2197 template <
typename PACKING_CONTEXT>
2201 return element.bitSizeOf(packingContext, bitPosition);
2213 template <
typename PACKING_CONTEXT>
2217 return element.initializeOffsets(packingContext, bitPosition);
2230 template <
typename RAW_ARRAY,
typename PACKING_CONTEXT>
2234 ELEMENT_FACTORY::create(owner, rawArray, packingContext, in, index);
2244 template <
typename PACKING_CONTEXT>
2248 element.write(packingContext, out);
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf()
static size_t bitSizeOf(ElementType)
static constexpr bool IS_BITSIZEOF_CONSTANT
static ElementType read(BitStreamReader &in, size_t=0)
static size_t initializeOffsets(size_t bitPosition, ElementType)
static size_t bitSizeOf(size_t, ElementType)
BasicBitBuffer< RebindAlloc< ALLOC, uint8_t > > readBitBuffer(const ALLOC &allocator=ALLOC())
string< ALLOC > readString(const ALLOC &alloc=ALLOC())
vector< uint8_t, ALLOC > readBytes(const ALLOC &alloc=ALLOC())
void writeFloat64(double data)
void writeVarInt64(int64_t data)
void writeVarInt16(int16_t data)
void writeString(StringView data)
void writeFloat32(float data)
void writeVarUInt64(uint64_t data)
void writeVarUInt16(uint16_t data)
void writeVarInt32(int32_t data)
void writeVarSize(uint32_t data)
void writeVarUInt32(uint32_t data)
void writeVarUInt(uint64_t data)
void writeVarInt(int64_t data)
void writeFloat16(float data)
void writeBytes(Span< const uint8_t > data)
void writeBool(bool data)
void writeBitBuffer(const BasicBitBuffer< ALLOC > &bitBuffer)
static ElementType read(const OwnerType &owner, BitStreamReader &in, size_t=0)
typename ELEMENT_BIT_SIZE::OwnerType OwnerType
static size_t bitSizeOf(const OwnerType &owner)
static size_t initializeOffsets(const OwnerType &owner, size_t bitPosition, ElementType)
static void write(const OwnerType &owner, BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(const OwnerType &owner, size_t, ElementType)
static size_t bitSizeOf(const OwnerType &owner, ElementType)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType)
static size_t bitSizeOf(size_t, ElementType)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf()
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf(ElementType)
typename ELEMENT_FACTORY::OwnerType OwnerType
static size_t bitSizeOf(const OwnerType &, size_t bitPosition, const ElementType &element)
static constexpr bool IS_BITSIZEOF_CONSTANT
static void write(const OwnerType &, BitStreamWriter &out, const ElementType &element)
static void read(OwnerType &owner, RAW_ARRAY &rawArray, BitStreamReader &in, size_t index)
typename ElementType::allocator_type allocator_type
static size_t initializeOffsets(OwnerType &, size_t bitPosition, ElementType &element)
typename ARRAY_TRAITS::ElementType ElementType
static void write(const OwnerType &owner, DeltaContext &deltaContext, BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(const OwnerType &owner, DeltaContext &deltaContext, size_t bitPosition, ElementType element)
static void initContext(const OwnerType &owner, DeltaContext &deltaContext, ElementType element)
static ElementType read(const OwnerType &owner, DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
typename ARRAY_TRAITS::OwnerType OwnerType
static size_t bitSizeOf(const OwnerType &owner, DeltaContext &deltaContext, size_t, ElementType element)
static void initContext(DeltaContext &deltaContext, const ElementType &element)
static size_t initializeOffsets(DeltaContext &deltaContext, size_t bitPosition, const ElementType &element)
static ElementType read(DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
static size_t bitSizeOf(DeltaContext &deltaContext, size_t bitPosition, const ElementType &element)
static void write(DeltaContext &deltaContext, BitStreamWriter &out, const ElementType &element)
static void write(DeltaContext &deltaContext, BitStreamWriter &out, ElementType element)
static void initContext(DeltaContext &deltaContext, ElementType element)
static ElementType read(DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
static size_t bitSizeOf(DeltaContext &deltaContext, size_t, ElementType element)
static size_t initializeOffsets(DeltaContext &deltaContext, size_t bitPosition, ElementType element)
static size_t bitSizeOf(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, size_t bitPosition, const ElementType &element)
static size_t initializeOffsets(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, size_t bitPosition, ElementType &element)
typename ArrayTraits::OwnerType OwnerType
static void write(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, BitStreamWriter &out, const ElementType &element)
static void read(typename ArrayTraits::OwnerType &owner, RAW_ARRAY &rawArray, PACKING_CONTEXT &packingContext, BitStreamReader &in, size_t index)
static void initContext(const typename ArrayTraits::OwnerType &, PACKING_CONTEXT &packingContext, const ElementType &element)
typename T::allocator_type allocator_type
static ElementType read(DeltaContext &deltaContext, BitStreamReader &in, size_t=0)
static void initContext(DeltaContext &deltaContext, ElementType element)
typename ARRAY_TRAITS::ElementType ElementType
static size_t bitSizeOf(DeltaContext &deltaContext, size_t, ElementType element)
static void write(DeltaContext &deltaContext, BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(DeltaContext &deltaContext, size_t bitPosition, ElementType element)
uint8_t numBits(uint64_t numValues)
size_t bitSizeOfString(StringView stringValue)
size_t bitSizeOfVarInt32(int32_t value)
void write(BitStreamWriter &out, T value)
size_t bitSizeOfVarUInt32(uint32_t value)
size_t bitSizeOfVarInt64(int64_t value)
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char > > string
std::vector< T, RebindAlloc< ALLOC, T > > vector
size_t initializeOffsets(size_t bitPosition, T value)
size_t bitSizeOfVarSize(uint32_t value)
size_t bitSizeOfVarUInt64(uint64_t value)
size_t bitSizeOfVarInt16(int16_t value)
void initPackingContext(PACKING_CONTEXT &context, T value)
size_t bitSizeOfBitBuffer(const BasicBitBuffer< ALLOC > &bitBuffer)
size_t bitSizeOfVarUInt(uint64_t value)
size_t bitSizeOfVarInt(int64_t value)
size_t bitSizeOfBytes(Span< const uint8_t > bytesValue)
size_t bitSizeOf(T value)
size_t bitSizeOfVarUInt16(uint16_t value)
static size_t initializeOffsets(size_t bitPosition, const ElementType &element)
typename ElementType::allocator_type allocator_type
static void write(BitStreamWriter &out, const ElementType &element)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf(size_t, const ElementType &element)
static void read(RAW_ARRAY &rawArray, BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, const ElementType &element)
zserio::vector< uint8_t, ALLOC< uint8_t > > ElementType
static size_t bitSizeOf(size_t, const ElementType &element)
static void read(RAW_ARRAY &rawArray, BitStreamReader &in, size_t=0)
static constexpr bool IS_BITSIZEOF_CONSTANT
typename ElementType::allocator_type allocator_type
static size_t initializeOffsets(size_t bitPosition, const ElementType &element)
typename ElementType::allocator_type allocator_type
static size_t initializeOffsets(size_t bitPosition, const ElementType &element)
static constexpr bool IS_BITSIZEOF_CONSTANT
static void write(BitStreamWriter &out, const ElementType &element)
zserio::string< ALLOC< char > > ElementType
static size_t bitSizeOf(size_t, const ElementType &element)
static void read(RAW_ARRAY &rawArray, BitStreamReader &in, size_t=0)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf(size_t, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType)
static ElementType read(BitStreamReader &in, size_t=0)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf()
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf()
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf()
static size_t bitSizeOf(size_t, ElementType)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf()
static void write(BitStreamWriter &out, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(size_t, ElementType)
static size_t bitSizeOf(size_t, ElementType)
static constexpr bool IS_BITSIZEOF_CONSTANT
static size_t bitSizeOf()
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType)
static size_t bitSizeOf(ElementType)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
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(ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf(size_t, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf(size_t, ElementType element)
static size_t bitSizeOf(ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t bitSizeOf(size_t, ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static size_t bitSizeOf(ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static size_t initializeOffsets(size_t bitPosition, ElementType element)
static size_t bitSizeOf(ElementType element)
static void write(BitStreamWriter &out, ElementType element)
static ElementType read(BitStreamReader &in, size_t=0)
static constexpr bool IS_BITSIZEOF_CONSTANT
static void write(BitStreamWriter &out, ElementType element)
static size_t bitSizeOf(ElementType element)
static size_t bitSizeOf(size_t, ElementType element)
static size_t initializeOffsets(size_t bitPosition, ElementType element)