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