Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023
00024
00025 # include <icl_comm/ByteOrderConversion.h>
00026
00027
00028
00029 namespace icl_comm {
00030
00031 std::ostream& operator << (std::ostream& o, const ArrayBuilder& ab)
00032 {
00033 for (size_t i = 0; i < ab.array.size(); i++)
00034 {
00035 o << "0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(ab.array[i]) << " ";
00036 }
00037
00038 std::cout << std::dec ;
00039 return o;
00040 }
00041
00042 template <>
00043 size_t toLittleEndian<float>(const float& data, std::vector<uint8_t>& array, size_t& write_pos)
00044 {
00046 return toLittleEndian(*(reinterpret_cast<const uint32_t*>(&data)),array,write_pos);
00047 }
00048
00049 template <>
00050 size_t toLittleEndian<double>(const double& data, std::vector<uint8_t>& array, size_t& write_pos)
00051 {
00053 return toLittleEndian(*(reinterpret_cast<const uint64_t*>(&data)),array,write_pos);
00054
00055 }
00056
00057 template <>
00058 size_t fromLittleEndian<float>(float& data, std::vector<uint8_t>& array, size_t& read_pos)
00059 {
00061 return fromLittleEndian(*(reinterpret_cast<uint32_t*>(&data)),array,read_pos);
00062 }
00063
00064 template <>
00065 size_t fromLittleEndian<double>(double& data, std::vector<uint8_t>& array, size_t& read_pos)
00066 {
00068 return fromLittleEndian(*(reinterpret_cast<uint64_t*>(&data)),array,read_pos);
00069
00070 }
00071
00072 void ArrayBuilder::reset(size_t array_size)
00073 {
00074 array.clear();
00075 write_pos = 0;
00076 read_pos = 0;
00077 array.resize(array_size,0);
00078 }
00079
00080
00081 }