rosserial for Hydro
Fork of rosserial_mbed_lib by
dianostic_msgs/KeyValue.h@0:77afd7560544, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:30 2011 +0000
- Revision:
- 0:77afd7560544
- Child:
- 1:ff0ec969dad1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:77afd7560544 | 1 | #ifndef ros_KeyValue_h |
nucho | 0:77afd7560544 | 2 | #define ros_KeyValue_h |
nucho | 0:77afd7560544 | 3 | |
nucho | 0:77afd7560544 | 4 | #include <stdint.h> |
nucho | 0:77afd7560544 | 5 | #include <string.h> |
nucho | 0:77afd7560544 | 6 | #include <stdlib.h> |
nucho | 0:77afd7560544 | 7 | #include "../ros/msg.h" |
nucho | 0:77afd7560544 | 8 | |
nucho | 0:77afd7560544 | 9 | namespace diagnostic_msgs |
nucho | 0:77afd7560544 | 10 | { |
nucho | 0:77afd7560544 | 11 | |
nucho | 0:77afd7560544 | 12 | class KeyValue : public ros::Msg |
nucho | 0:77afd7560544 | 13 | { |
nucho | 0:77afd7560544 | 14 | public: |
nucho | 0:77afd7560544 | 15 | char * key; |
nucho | 0:77afd7560544 | 16 | char * value; |
nucho | 0:77afd7560544 | 17 | |
nucho | 0:77afd7560544 | 18 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 19 | { |
nucho | 0:77afd7560544 | 20 | int offset = 0; |
nucho | 0:77afd7560544 | 21 | long * length_key = (long *)(outbuffer + offset); |
nucho | 0:77afd7560544 | 22 | *length_key = strlen( (const char*) this->key); |
nucho | 0:77afd7560544 | 23 | offset += 4; |
nucho | 0:77afd7560544 | 24 | memcpy(outbuffer + offset, this->key, *length_key); |
nucho | 0:77afd7560544 | 25 | offset += *length_key; |
nucho | 0:77afd7560544 | 26 | long * length_value = (long *)(outbuffer + offset); |
nucho | 0:77afd7560544 | 27 | *length_value = strlen( (const char*) this->value); |
nucho | 0:77afd7560544 | 28 | offset += 4; |
nucho | 0:77afd7560544 | 29 | memcpy(outbuffer + offset, this->value, *length_value); |
nucho | 0:77afd7560544 | 30 | offset += *length_value; |
nucho | 0:77afd7560544 | 31 | return offset; |
nucho | 0:77afd7560544 | 32 | } |
nucho | 0:77afd7560544 | 33 | |
nucho | 0:77afd7560544 | 34 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 35 | { |
nucho | 0:77afd7560544 | 36 | int offset = 0; |
nucho | 0:77afd7560544 | 37 | uint32_t length_key = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 38 | offset += 4; |
nucho | 0:77afd7560544 | 39 | for(unsigned int k= offset; k< offset+length_key; ++k){ |
nucho | 0:77afd7560544 | 40 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 41 | } |
nucho | 0:77afd7560544 | 42 | inbuffer[offset+length_key-1]=0; |
nucho | 0:77afd7560544 | 43 | this->key = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 44 | offset += length_key; |
nucho | 0:77afd7560544 | 45 | uint32_t length_value = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 46 | offset += 4; |
nucho | 0:77afd7560544 | 47 | for(unsigned int k= offset; k< offset+length_value; ++k){ |
nucho | 0:77afd7560544 | 48 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 49 | } |
nucho | 0:77afd7560544 | 50 | inbuffer[offset+length_value-1]=0; |
nucho | 0:77afd7560544 | 51 | this->value = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 52 | offset += length_value; |
nucho | 0:77afd7560544 | 53 | return offset; |
nucho | 0:77afd7560544 | 54 | } |
nucho | 0:77afd7560544 | 55 | |
nucho | 0:77afd7560544 | 56 | virtual const char * getType(){ return "diagnostic_msgs/KeyValue"; }; |
nucho | 0:77afd7560544 | 57 | |
nucho | 0:77afd7560544 | 58 | }; |
nucho | 0:77afd7560544 | 59 | |
nucho | 0:77afd7560544 | 60 | } |
nucho | 0:77afd7560544 | 61 | #endif |