From 8102980583360ebb17dcb039d3a28c14d1fe1bc2 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 8 Apr 2014 21:16:38 +0400 Subject: [PATCH] Out of line methods for ScalarCodec --- .../include/uavcan/marshal/scalar_codec.hpp | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) 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; +} + }