diff --git a/libuavcan/include/uavcan/marshal/scalar_codec.hpp b/libuavcan/include/uavcan/marshal/scalar_codec.hpp index 6d07e41cfb..990cf5fa0d 100644 --- a/libuavcan/include/uavcan/marshal/scalar_codec.hpp +++ b/libuavcan/include/uavcan/marshal/scalar_codec.hpp @@ -90,39 +90,47 @@ public: { } template - int encode(const T value) - { - validate(); - union ByteUnion - { - T value; - uint8_t bytes[sizeof(T)]; - } byte_union; - byte_union.value = value; - clearExtraBits(byte_union.value); - convertByteOrder(byte_union.bytes); - return encodeBytesImpl(byte_union.bytes, BitLen); - } + int encode(const T value); template - int decode(T& value) - { - validate(); - union ByteUnion - { - T value; - uint8_t bytes[sizeof(T)]; - } byte_union; - byte_union.value = T(); - const int read_res = decodeBytesImpl(byte_union.bytes, BitLen); - if (read_res > 0) - { - convertByteOrder(byte_union.bytes); - fixTwosComplement(byte_union.value); - value = byte_union.value; - } - return read_res; - } + int decode(T& value); }; +// ---------------------------------------------------------------------------- + +template +int ScalarCodec::encode(const T value) +{ + validate(); + union ByteUnion + { + T value; + uint8_t bytes[sizeof(T)]; + } byte_union; + byte_union.value = value; + clearExtraBits(byte_union.value); + convertByteOrder(byte_union.bytes); + return encodeBytesImpl(byte_union.bytes, BitLen); +} + +template +int ScalarCodec::decode(T& value) +{ + validate(); + union ByteUnion + { + T value; + uint8_t bytes[sizeof(T)]; + } byte_union; + byte_union.value = T(); + const int read_res = decodeBytesImpl(byte_union.bytes, BitLen); + if (read_res > 0) + { + convertByteOrder(byte_union.bytes); + fixTwosComplement(byte_union.value); + value = byte_union.value; + } + return read_res; +} + }