deserialise.hpp
Go to the documentation of this file.
00001 #ifndef DESERIALISE_HPP
00002 #define DESERIALISE_HPP
00003 
00004 #include "types.hpp"
00005 #include <cstdlib>
00006 
00007 namespace msp {
00008 
00011 
00012 void serialise_uint16(const uint16_t val, ByteVector &data) {
00013     data.push_back(val>>0);
00014     data.push_back(val>>8);
00015 }
00016 
00017 uint16_t deserialise_uint16(const ByteVector &data, const size_t start) {
00018     return (data[start]<<0) | (data[start+1]<<8);
00019 }
00020 
00021 void serialise_int16(const int16_t val, ByteVector &data) {
00022     data.push_back(val>>0);
00023     data.push_back(val>>8);
00024 }
00025 
00026 int16_t deserialise_int16(const ByteVector &data, const size_t start) {
00027     return (data[start]<<0) | (data[start+1]<<8);
00028 }
00029 
00030 int32_t deserialise_int32(const ByteVector &data, const size_t start) {
00031     return (data[start]<<0) | (data[start+1]<<8) | (data[start+2]<<16) | (data[start+3]<<24);
00032 }
00033 
00034 void serialise_uint32(const uint32_t val, ByteVector &data) {
00035     data.push_back(val>>0);
00036     data.push_back(val>>8);
00037     data.push_back(val>>16);
00038     data.push_back(val>>24);
00039 }
00040 
00041 uint32_t deserialise_uint32(const ByteVector &data, const size_t start) {
00042     return (data[start]<<0) | (data[start+1]<<8) | (data[start+2]<<16) | (data[start+3]<<24);
00043 }
00044 
00045 }
00046 
00047 #endif // DESERIALISE_HPP


msp
Author(s): Christian Rauch
autogenerated on Mon Oct 9 2017 03:02:13