summaryrefslogtreecommitdiff
path: root/core/io/marshalls.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/marshalls.h')
-rw-r--r--core/io/marshalls.h80
1 files changed, 39 insertions, 41 deletions
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index f04ec9a256..939ed9cea9 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -38,7 +38,6 @@
* in an endian independent way
*/
-
union MarshallFloat {
uint32_t i; ///< int
@@ -53,41 +52,44 @@ union MarshallDouble {
static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
- for (int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
- *p_arr=p_uint&0xFF;
- p_arr++; p_uint>>=8;
+ *p_arr = p_uint & 0xFF;
+ p_arr++;
+ p_uint >>= 8;
}
- return sizeof( uint16_t );
+ return sizeof(uint16_t);
}
static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
- for (int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
- *p_arr=p_uint&0xFF;
- p_arr++; p_uint>>=8;
+ *p_arr = p_uint & 0xFF;
+ p_arr++;
+ p_uint >>= 8;
}
- return sizeof( uint32_t );
+ return sizeof(uint32_t);
}
static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
MarshallFloat mf;
- mf.f=p_float;
- encode_uint32( mf.i, p_arr );
+ mf.f = p_float;
+ encode_uint32(mf.i, p_arr);
- return sizeof( uint32_t );
+ return sizeof(uint32_t);
}
static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
- for (int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
- *p_arr=p_uint&0xFF;
- p_arr++; p_uint>>=8;
+ *p_arr = p_uint & 0xFF;
+ p_arr++;
+ p_uint >>= 8;
}
return sizeof(uint64_t);
@@ -96,23 +98,21 @@ static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
MarshallDouble md;
- md.d=p_double;
- encode_uint64( md.l, p_arr );
+ md.d = p_double;
+ encode_uint64(md.l, p_arr);
return sizeof(uint64_t);
-
}
+static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
-static inline int encode_cstring(const char *p_string, uint8_t * p_data) {
-
- int len=0;
+ int len = 0;
while (*p_string) {
if (p_data) {
- *p_data=(uint8_t)*p_string;
+ *p_data = (uint8_t)*p_string;
p_data++;
}
p_string++;
@@ -120,18 +120,18 @@ static inline int encode_cstring(const char *p_string, uint8_t * p_data) {
};
if (p_data) *p_data = 0;
- return len+1;
+ return len + 1;
}
static inline uint16_t decode_uint16(const uint8_t *p_arr) {
- uint16_t u=0;
+ uint16_t u = 0;
- for (int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
uint16_t b = *p_arr;
- b<<=(i*8);
- u|=b;
+ b <<= (i * 8);
+ u |= b;
p_arr++;
}
@@ -140,13 +140,13 @@ static inline uint16_t decode_uint16(const uint8_t *p_arr) {
static inline uint32_t decode_uint32(const uint8_t *p_arr) {
- uint32_t u=0;
+ uint32_t u = 0;
- for (int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
uint32_t b = *p_arr;
- b<<=(i*8);
- u|=b;
+ b <<= (i * 8);
+ u |= b;
p_arr++;
}
@@ -162,13 +162,13 @@ static inline float decode_float(const uint8_t *p_arr) {
static inline uint64_t decode_uint64(const uint8_t *p_arr) {
- uint64_t u=0;
+ uint64_t u = 0;
- for (int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
- uint64_t b = (*p_arr)&0xFF;
- b<<=(i*8);
- u|=b;
+ uint64_t b = (*p_arr) & 0xFF;
+ b <<= (i * 8);
+ u |= b;
p_arr++;
}
@@ -178,13 +178,11 @@ static inline uint64_t decode_uint64(const uint8_t *p_arr) {
static inline double decode_double(const uint8_t *p_arr) {
MarshallDouble md;
- md.l = decode_uint64( p_arr );
+ md.l = decode_uint64(p_arr);
return md.d;
-
}
-
-Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *r_len=NULL);
-Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len);
+Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL);
+Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len);
#endif