Skip to content

Commit

Permalink
Extend runtime tests to support withbitPositionCode option
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Aug 1, 2024
1 parent 7212010 commit 025fd72
Show file tree
Hide file tree
Showing 121 changed files with 1,110 additions and 171 deletions.
13 changes: 8 additions & 5 deletions compiler/extensions/cpp/runtime/src/zserio/IReflectable.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,16 @@ class IBasicReflectable
/** \} */

/**
* Returns the reflectables bit position (blob) in bits.
* Returns the bit position in the parsed blob after reading of the reflectable object.
*
* \note The bit position is only stored for code generated using zserios `-withBitPositionCode`
* option and only set for objects read from a blob.
* This feature is experimental and can be removed without any warning!
*
* \return The blob offset of the objects in bits
* \throw CppRuntimeException If the object was compiled without the source region feature enabled.
* \note Note that the returned bit position can be invalid if the Zserio object has been changed after
* reading (e.g. if some field has been set).
* \note The bit position is only stored for code generated using `-withBitPositionCode` option.
*
* \return The blob offset of the objects in bits.
* \throw CppRuntimeException If the object was compiled without the bit position feature enabled.
*/
virtual size_t bitPosition() const = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion compiler/extensions/cpp/runtime/src/zserio/Reflectable.h
Original file line number Diff line number Diff line change
Expand Up @@ -4378,7 +4378,8 @@ string<ALLOC> ReflectableBase<ALLOC>::toString() const
template <typename ALLOC>
size_t ReflectableBase<ALLOC>::bitPosition() const
{
throw CppRuntimeException("Bit position unavailable for type '") << getTypeInfo().getSchemaName() << "'!";
throw CppRuntimeException("Bit position is not available for type '")
<< getTypeInfo().getSchemaName() << "'!";
}

template <typename ALLOC>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/HashCodeUtil.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_BITMASK_H
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/StringConvertUtil.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_ENUM_H
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/StringConvertUtil.h>
Expand All @@ -22,6 +22,7 @@ namespace polymorphic_allocator

ArrayHolder::ArrayHolder(const allocator_type& allocator) noexcept :
m_areChildrenInitialized(false),
m_bitPosition(0),
m_enumArray_(allocator),
m_bitmaskArray_(allocator),
m_packedArray_(allocator),
Expand All @@ -31,6 +32,7 @@ ArrayHolder::ArrayHolder(const allocator_type& allocator) noexcept :

ArrayHolder::ArrayHolder(::zserio::BitStreamReader& in, const allocator_type& allocator) :
m_areChildrenInitialized(true),
m_bitPosition(in.getBitPosition()),
m_enumArray_(readEnumArray(in, allocator)),
m_bitmaskArray_(readBitmaskArray(in, allocator)),
m_packedArray_(readPackedArray(in, allocator)),
Expand All @@ -39,6 +41,7 @@ ArrayHolder::ArrayHolder(::zserio::BitStreamReader& in, const allocator_type& al
}

ArrayHolder::ArrayHolder(const ArrayHolder& other) :
m_bitPosition(other.m_bitPosition),
m_enumArray_(other.m_enumArray_),
m_bitmaskArray_(other.m_bitmaskArray_),
m_packedArray_(other.m_packedArray_),
Expand All @@ -56,6 +59,7 @@ ArrayHolder::ArrayHolder(const ArrayHolder& other) :

ArrayHolder& ArrayHolder::operator=(const ArrayHolder& other)
{
m_bitPosition = other.m_bitPosition;
m_enumArray_ = other.m_enumArray_;
m_bitmaskArray_ = other.m_bitmaskArray_;
m_packedArray_ = other.m_packedArray_;
Expand All @@ -73,6 +77,7 @@ ArrayHolder& ArrayHolder::operator=(const ArrayHolder& other)
}

ArrayHolder::ArrayHolder(ArrayHolder&& other) :
m_bitPosition(other.m_bitPosition),
m_enumArray_(::std::move(other.m_enumArray_)),
m_bitmaskArray_(::std::move(other.m_bitmaskArray_)),
m_packedArray_(::std::move(other.m_packedArray_)),
Expand All @@ -90,6 +95,7 @@ ArrayHolder::ArrayHolder(ArrayHolder&& other) :

ArrayHolder& ArrayHolder::operator=(ArrayHolder&& other)
{
m_bitPosition = other.m_bitPosition;
m_enumArray_ = ::std::move(other.m_enumArray_);
m_bitmaskArray_ = ::std::move(other.m_bitmaskArray_);
m_packedArray_ = ::std::move(other.m_packedArray_);
Expand All @@ -108,6 +114,7 @@ ArrayHolder& ArrayHolder::operator=(ArrayHolder&& other)

ArrayHolder::ArrayHolder(::zserio::PropagateAllocatorT,
const ArrayHolder& other, const allocator_type& allocator) :
m_bitPosition(other.m_bitPosition),
m_enumArray_(::zserio::allocatorPropagatingCopy(other.m_enumArray_, allocator)),
m_bitmaskArray_(::zserio::allocatorPropagatingCopy(other.m_bitmaskArray_, allocator)),
m_packedArray_(::zserio::allocatorPropagatingCopy(other.m_packedArray_, allocator)),
Expand Down Expand Up @@ -266,6 +273,11 @@ ::zserio::pmr::IReflectableConstPtr ArrayHolder::reflectable(const allocator_typ
return ::zserio::pmr::AnyHolder(::std::cref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
const ::test_object::polymorphic_allocator::ArrayHolder& m_object;
};
Expand Down Expand Up @@ -406,6 +418,11 @@ ::zserio::pmr::IReflectablePtr ArrayHolder::reflectable(const allocator_type& al
return ::zserio::pmr::AnyHolder(::std::ref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
::test_object::polymorphic_allocator::ArrayHolder& m_object;
};
Expand Down Expand Up @@ -599,6 +616,11 @@ void ArrayHolder::write(::zserio::BitStreamWriter& out) const
m_packedParamArray_.writePacked(*this, out);
}

size_t ArrayHolder::bitPosition() const
{
return m_bitPosition;
}

void ArrayHolder::ZserioElementFactory_packedArray::create(ArrayHolder&,
::zserio::pmr::vector<::test_object::polymorphic_allocator::ArrayObject>& array,
::zserio::BitStreamReader& in, size_t)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_HOLDER_H
Expand Down Expand Up @@ -108,6 +108,8 @@ class ArrayHolder

void write(::zserio::BitStreamWriter& out) const;

size_t bitPosition() const;

private:
class ZserioElementFactory_packedArray
{
Expand Down Expand Up @@ -163,6 +165,7 @@ class ArrayHolder
const allocator_type& allocator);

bool m_areChildrenInitialized;
size_t m_bitPosition;
ZserioArrayType_enumArray m_enumArray_;
ZserioArrayType_bitmaskArray m_bitmaskArray_;
ZserioArrayType_packedArray m_packedArray_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/StringConvertUtil.h>
Expand All @@ -21,22 +21,26 @@ namespace polymorphic_allocator
{

ArrayObject::ArrayObject(const allocator_type&) noexcept :
m_bitPosition(0),
m_value_(uint32_t())
{
}

ArrayObject::ArrayObject(::zserio::BitStreamReader& in, const allocator_type&) :
m_bitPosition(in.getBitPosition()),
m_value_(readValue(in))
{
}

ArrayObject::ArrayObject(ArrayObject::ZserioPackingContext& context, ::zserio::BitStreamReader& in, const allocator_type&) :
m_bitPosition(in.getBitPosition()),
m_value_(readValue(context, in))
{
}

ArrayObject::ArrayObject(::zserio::PropagateAllocatorT,
const ArrayObject& other, const allocator_type& allocator) :
m_bitPosition(other.m_bitPosition),
m_value_(::zserio::allocatorPropagatingCopy(other.m_value_, allocator))
{
}
Expand Down Expand Up @@ -121,6 +125,11 @@ ::zserio::pmr::IReflectableConstPtr ArrayObject::reflectable(const allocator_typ
return ::zserio::pmr::AnyHolder(::std::cref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
const ::test_object::polymorphic_allocator::ArrayObject& m_object;
};
Expand Down Expand Up @@ -206,6 +215,11 @@ ::zserio::pmr::IReflectablePtr ArrayObject::reflectable(const allocator_type& al
return ::zserio::pmr::AnyHolder(::std::ref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
::test_object::polymorphic_allocator::ArrayObject& m_object;
};
Expand Down Expand Up @@ -308,6 +322,11 @@ void ArrayObject::write(ArrayObject::ZserioPackingContext& context, ::zserio::Bi
context.getValue().write<::zserio::BitFieldArrayTraits<uint32_t, UINT8_C(31)>>(out, m_value_);
}

size_t ArrayObject::bitPosition() const
{
return m_bitPosition;
}

uint32_t ArrayObject::readValue(::zserio::BitStreamReader& in)
{
return static_cast<uint32_t>(in.readBits(UINT8_C(31)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_OBJECT_H
Expand Down Expand Up @@ -92,11 +92,14 @@ class ArrayObject
void write(::zserio::BitStreamWriter& out) const;
void write(ZserioPackingContext& context, ::zserio::BitStreamWriter& out) const;

size_t bitPosition() const;

private:
uint32_t readValue(::zserio::BitStreamReader& in);
uint32_t readValue(ZserioPackingContext& context,
::zserio::BitStreamReader& in);

size_t m_bitPosition;
uint32_t m_value_;
};

Expand Down
Loading

0 comments on commit 025fd72

Please sign in to comment.