Skip to content

Commit

Permalink
Release v5.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Mar 22, 2023
2 parents 6c30fdf + f8cdb39 commit 0c726eb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
16 changes: 14 additions & 2 deletions include/comms/field/adapter/FixedLength.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ class FixedLength : public TBase
template <typename... TParams>
static constexpr BaseSerialisedType adjustFromSerialised(SerialisedType val, JustCastTag<TParams...>)
{
return static_cast<BaseSerialisedType>(val);
return castToBaseSerializedType(val, HasSignTag<>());
}

template <typename... TParams>
static BaseSerialisedType adjustFromSerialised(SerialisedType val, SignExtendTag<TParams...>)
{
auto valueTmp = static_cast<UnsignedSerialisedType>(val) & UnsignedValueMask;
return static_cast<BaseSerialisedType>(signExtUnsignedSerialised(valueTmp, HasSignTag<>()));
return castToBaseSerializedType(signExtUnsignedSerialised(valueTmp, HasSignTag<>()), HasSignTag<>());
}

template <typename... TParams>
Expand All @@ -222,6 +222,18 @@ class FixedLength : public TBase
return static_cast<SerialisedType>(val);
}

template <typename... TParams>
static constexpr BaseSerialisedType castToBaseSerializedType(SerialisedType val, UnsignedTag<TParams...>)
{
return static_cast<BaseSerialisedType>(static_cast<UnsignedSerialisedType>(val));
}

template <typename... TParams>
static constexpr BaseSerialisedType castToBaseSerializedType(SerialisedType val, SignedTag<TParams...>)
{
return static_cast<BaseSerialisedType>(val);
}

static const std::size_t Length = TLen;
static const std::size_t BitsInByte = std::numeric_limits<std::uint8_t>::digits;
static const std::size_t BitLength = Length * BitsInByte;
Expand Down
2 changes: 1 addition & 1 deletion include/comms/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define COMMS_MINOR_VERSION 1U

/// @brief Patch level of the library
#define COMMS_PATCH_VERSION 1U
#define COMMS_PATCH_VERSION 2U

/// @brief Macro to create numeric version as single unsigned number
#define COMMS_MAKE_VERSION(major_, minor_, patch_) \
Expand Down
25 changes: 25 additions & 0 deletions test/Fields2.th
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public:
void test26();
void test27();
void test28();
void test29();

private:
template <typename TField>
Expand Down Expand Up @@ -1882,6 +1883,30 @@ void FieldsTestSuite2::test28()
} while (false);
}

void FieldsTestSuite2::test29()
{
using Field =
comms::field::IntValue<
BeFieldBase,
std::int16_t,
comms::option::def::FixedLength<1U, false>,
comms::option::def::NumValueSerOffset<128>,
comms::option::def::ValidNumValueRange<-128, 127>
>;

do {
Field field;
field.value() = 10;

static const char Buf[] = {
static_cast<char>(0x8a),
};
static const std::size_t BufSize = std::extent<decltype(Buf)>::value;

writeReadField(field, &Buf[0], BufSize);
} while (false);
}

template <typename TField>
void FieldsTestSuite2::writeField(
const TField& field,
Expand Down

0 comments on commit 0c726eb

Please sign in to comment.