1 #ifndef ZSERIO_ARRAY_TRAITS_H_INC
2 #define ZSERIO_ARRAY_TRAITS_H_INC
25 T read_bits(BitStreamReader& in, uint8_t
numBits);
28 inline int8_t read_bits<int8_t>(BitStreamReader& in, uint8_t
numBits)
30 return static_cast<int8_t
>(in.readSignedBits(
numBits));
34 inline int16_t read_bits<int16_t>(BitStreamReader& in, uint8_t
numBits)
36 return static_cast<int16_t
>(in.readSignedBits(
numBits));
40 inline int32_t read_bits<int32_t>(BitStreamReader& in, uint8_t
numBits)
42 return in.readSignedBits(
numBits);
46 inline int64_t read_bits<int64_t>(BitStreamReader& in, uint8_t
numBits)
48 return in.readSignedBits64(
numBits);
52 inline uint8_t read_bits<uint8_t>(BitStreamReader& in, uint8_t
numBits)
54 return static_cast<uint8_t
>(in.readBits(
numBits));
58 inline uint16_t read_bits<uint16_t>(BitStreamReader& in, uint8_t
numBits)
60 return static_cast<uint16_t
>(in.readBits(
numBits));
64 inline uint32_t read_bits<uint32_t>(BitStreamReader& in, uint8_t
numBits)
70 inline uint64_t read_bits<uint64_t>(BitStreamReader& in, uint8_t
numBits)
76 void write_bits(BitStreamWriter& out, T value, uint8_t
numBits);
79 inline void write_bits<int8_t>(BitStreamWriter& out, int8_t value, uint8_t
numBits)
81 out.writeSignedBits(
static_cast<int32_t
>(value),
numBits);
85 inline void write_bits<int16_t>(BitStreamWriter& out, int16_t value, uint8_t
numBits)
87 out.writeSignedBits(
static_cast<int32_t
>(value),
numBits);
91 inline void write_bits<int32_t>(BitStreamWriter& out, int32_t value, uint8_t
numBits)
93 out.writeSignedBits(value,
numBits);
97 inline void write_bits<int64_t>(BitStreamWriter& out, int64_t value, uint8_t
numBits)
99 out.writeSignedBits64(value,
numBits);
103 inline void write_bits<uint8_t>(BitStreamWriter& out, uint8_t value, uint8_t
numBits)
105 out.writeBits(
static_cast<uint32_t
>(value),
numBits);
109 inline void write_bits<uint16_t>(BitStreamWriter& out, uint16_t value, uint8_t
numBits)
111 out.writeBits(
static_cast<uint32_t
>(value),
numBits);
115 inline void write_bits<uint32_t>(BitStreamWriter& out, uint32_t value, uint8_t
numBits)
121 inline void write_bits<uint64_t>(BitStreamWriter& out, uint64_t value, uint8_t
numBits)
123 out.writeBits64(value,
numBits);
134 template <
typename T, u
int8_t NUM_BITS>
180 return bitPosition + NUM_BITS;
192 return detail::read_bits<T>(in, NUM_BITS);
203 detail::write_bits(out, element, NUM_BITS);
216 template <
typename T,
typename ELEMENT_BIT_SIZE,
typename =
void>
230 return ELEMENT_BIT_SIZE::get();
274 return detail::read_bits<T>(in, ELEMENT_BIT_SIZE::get());
285 detail::write_bits(out, element, ELEMENT_BIT_SIZE::get());
298 template <
typename T,
typename ELEMENT_BIT_SIZE>
300 typename std::enable_if<has_owner_type<ELEMENT_BIT_SIZE>::value>::type>
318 return ELEMENT_BIT_SIZE::get(owner);
368 return detail::read_bits<T>(in, ELEMENT_BIT_SIZE::get(owner));
380 detail::write_bits(out, element, ELEMENT_BIT_SIZE::get(owner));
390 template <
typename T>
435 return bitPosition + NUM_BITS;
447 return detail::read_bits<T>(in, NUM_BITS);
458 detail::write_bits(out, element, NUM_BITS);
465 static constexpr uint8_t NUM_BITS =
sizeof(T) * 8;
471 template <
typename T>
517 return bitPosition +
bitSizeOf(bitPosition, element);
544 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
590 return bitPosition +
bitSizeOf(bitPosition, element);
617 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
663 return bitPosition +
bitSizeOf(bitPosition, element);
690 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
736 return bitPosition +
bitSizeOf(bitPosition, element);
763 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
809 return bitPosition +
bitSizeOf(bitPosition, element);
836 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
882 return bitPosition +
bitSizeOf(bitPosition, element);
909 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
915 template <
typename T>
961 return bitPosition +
bitSizeOf(bitPosition, element);
988 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1034 return bitPosition +
bitSizeOf(bitPosition, element);
1061 static constexpr
bool IS_BITSIZEOF_CONSTANT =
false;
1106 return bitPosition +
bitSizeOf(bitPosition, element);
1174 return bitPosition +
bitSizeOf(bitPosition, element);
1242 return bitPosition +
bitSizeOf(bitPosition, element);
1310 return bitPosition +
bitSizeOf(bitPosition, element);
1378 return bitPosition +
bitSizeOf(bitPosition, element);
1411 template <
template <
typename>
class ALLOC = std::allocator>
1442 return bitPosition +
bitSizeOf(bitPosition, element);
1451 template <
typename RAW_ARRAY>
1454 rawArray.emplace_back(in.
readBytes(rawArray.get_allocator()));
1477 template <
template <
typename>
class ALLOC = std::allocator>
1508 return bitPosition +
bitSizeOf(bitPosition, element);
1517 template <
typename RAW_ARRAY>
1520 rawArray.emplace_back(in.
readString(rawArray.get_allocator()));
1543 template <
template <
typename>
class ALLOC = std::allocator>
1574 return bitPosition +
bitSizeOf(bitPosition, element);
1583 template <
typename RAW_ARRAY>
1586 rawArray.emplace_back(in.
readBitBuffer(rawArray.get_allocator()));
1609 template <
typename T>
1649 return zserio::read<ElementType>(in);
1671 template <
typename T>
1686 return element.bitSizeOf();
1699 return element.initializeOffsets(bitPosition);
1733 template <
typename T,
typename ELEMENT_FACTORY>
1756 return element.bitSizeOf(bitPosition);
1769 return element.initializeOffsets(bitPosition);
1780 template <
typename RAW_ARRAY>
1783 ELEMENT_FACTORY::create(owner, rawArray, in, index);
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);
1948 return deltaContext.template bitSizeOf<ArrayTraits>(owner, element);
1966 return bitPosition +
bitSizeOf(owner, deltaContext, bitPosition, element);
1982 return deltaContext.template read<ArrayTraits>(owner, in);
1998 deltaContext.template write<ArrayTraits>(owner, out, element);
2005 template <
typename T>
2063 return zserio::read<ElementType>(deltaContext, in);
2082 template <
typename T>
2099 element.initPackingContext(deltaContext);
2113 return element.bitSizeOf(deltaContext, bitPosition);
2127 return element.initializeOffsets(deltaContext, bitPosition);
2152 element.write(deltaContext, out);
2160 template <
typename T,
typename ELEMENT_FACTORY>
2162 typename std::enable_if<has_owner_type<ObjectArrayTraits<T, ELEMENT_FACTORY>>::value>::type>
2182 template <
typename PACKING_CONTEXT>
2186 element.initPackingContext(packingContext);
2198 template <
typename PACKING_CONTEXT>
2202 return element.bitSizeOf(packingContext, bitPosition);
2214 template <
typename PACKING_CONTEXT>
2218 return element.initializeOffsets(packingContext, bitPosition);
2231 template <
typename RAW_ARRAY,
typename PACKING_CONTEXT>
2235 ELEMENT_FACTORY::create(owner, rawArray, packingContext, in, index);
2245 template <
typename PACKING_CONTEXT>
2249 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)