Go to the documentation of this file.00001 #ifndef ros_sensor_msgs_Image_h
00002 #define ros_sensor_msgs_Image_h
00003
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "../ros/msg.h"
00008 #include "std_msgs/Header.h"
00009
00010 namespace sensor_msgs
00011 {
00012
00013 class Image : public ros::Msg
00014 {
00015 public:
00016 std_msgs::Header header;
00017 unsigned long height;
00018 unsigned long width;
00019 char * encoding;
00020 unsigned char is_bigendian;
00021 unsigned long step;
00022 unsigned char data_length;
00023 unsigned char st_data;
00024 unsigned char * data;
00025
00026 virtual int serialize(unsigned char *outbuffer)
00027 {
00028 int offset = 0;
00029 offset += this->header.serialize(outbuffer + offset);
00030 union {
00031 unsigned long real;
00032 unsigned long base;
00033 } u_height;
00034 u_height.real = this->height;
00035 *(outbuffer + offset + 0) = (u_height.base >> (8 * 0)) & 0xFF;
00036 *(outbuffer + offset + 1) = (u_height.base >> (8 * 1)) & 0xFF;
00037 *(outbuffer + offset + 2) = (u_height.base >> (8 * 2)) & 0xFF;
00038 *(outbuffer + offset + 3) = (u_height.base >> (8 * 3)) & 0xFF;
00039 offset += sizeof(this->height);
00040 union {
00041 unsigned long real;
00042 unsigned long base;
00043 } u_width;
00044 u_width.real = this->width;
00045 *(outbuffer + offset + 0) = (u_width.base >> (8 * 0)) & 0xFF;
00046 *(outbuffer + offset + 1) = (u_width.base >> (8 * 1)) & 0xFF;
00047 *(outbuffer + offset + 2) = (u_width.base >> (8 * 2)) & 0xFF;
00048 *(outbuffer + offset + 3) = (u_width.base >> (8 * 3)) & 0xFF;
00049 offset += sizeof(this->width);
00050 long * length_encoding = (long *)(outbuffer + offset);
00051 *length_encoding = strlen( (const char*) this->encoding);
00052 offset += 4;
00053 memcpy(outbuffer + offset, this->encoding, *length_encoding);
00054 offset += *length_encoding;
00055 union {
00056 unsigned char real;
00057 unsigned char base;
00058 } u_is_bigendian;
00059 u_is_bigendian.real = this->is_bigendian;
00060 *(outbuffer + offset + 0) = (u_is_bigendian.base >> (8 * 0)) & 0xFF;
00061 offset += sizeof(this->is_bigendian);
00062 union {
00063 unsigned long real;
00064 unsigned long base;
00065 } u_step;
00066 u_step.real = this->step;
00067 *(outbuffer + offset + 0) = (u_step.base >> (8 * 0)) & 0xFF;
00068 *(outbuffer + offset + 1) = (u_step.base >> (8 * 1)) & 0xFF;
00069 *(outbuffer + offset + 2) = (u_step.base >> (8 * 2)) & 0xFF;
00070 *(outbuffer + offset + 3) = (u_step.base >> (8 * 3)) & 0xFF;
00071 offset += sizeof(this->step);
00072 *(outbuffer + offset++) = data_length;
00073 *(outbuffer + offset++) = 0;
00074 *(outbuffer + offset++) = 0;
00075 *(outbuffer + offset++) = 0;
00076 for( unsigned char i = 0; i < data_length; i++){
00077 union {
00078 unsigned char real;
00079 unsigned char base;
00080 } u_datai;
00081 u_datai.real = this->data[i];
00082 *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF;
00083 offset += sizeof(this->data[i]);
00084 }
00085 return offset;
00086 }
00087
00088 virtual int deserialize(unsigned char *inbuffer)
00089 {
00090 int offset = 0;
00091 offset += this->header.deserialize(inbuffer + offset);
00092 union {
00093 unsigned long real;
00094 unsigned long base;
00095 } u_height;
00096 u_height.base = 0;
00097 u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 0))) << (8 * 0);
00098 u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 1))) << (8 * 1);
00099 u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 2))) << (8 * 2);
00100 u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 3))) << (8 * 3);
00101 this->height = u_height.real;
00102 offset += sizeof(this->height);
00103 union {
00104 unsigned long real;
00105 unsigned long base;
00106 } u_width;
00107 u_width.base = 0;
00108 u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 0))) << (8 * 0);
00109 u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 1))) << (8 * 1);
00110 u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 2))) << (8 * 2);
00111 u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 3))) << (8 * 3);
00112 this->width = u_width.real;
00113 offset += sizeof(this->width);
00114 uint32_t length_encoding = *(uint32_t *)(inbuffer + offset);
00115 offset += 4;
00116 for(unsigned int k= offset; k< offset+length_encoding; ++k){
00117 inbuffer[k-1]=inbuffer[k];
00118 }
00119 inbuffer[offset+length_encoding-1]=0;
00120 this->encoding = (char *)(inbuffer + offset-1);
00121 offset += length_encoding;
00122 union {
00123 unsigned char real;
00124 unsigned char base;
00125 } u_is_bigendian;
00126 u_is_bigendian.base = 0;
00127 u_is_bigendian.base |= ((typeof(u_is_bigendian.base)) (*(inbuffer + offset + 0))) << (8 * 0);
00128 this->is_bigendian = u_is_bigendian.real;
00129 offset += sizeof(this->is_bigendian);
00130 union {
00131 unsigned long real;
00132 unsigned long base;
00133 } u_step;
00134 u_step.base = 0;
00135 u_step.base |= ((typeof(u_step.base)) (*(inbuffer + offset + 0))) << (8 * 0);
00136 u_step.base |= ((typeof(u_step.base)) (*(inbuffer + offset + 1))) << (8 * 1);
00137 u_step.base |= ((typeof(u_step.base)) (*(inbuffer + offset + 2))) << (8 * 2);
00138 u_step.base |= ((typeof(u_step.base)) (*(inbuffer + offset + 3))) << (8 * 3);
00139 this->step = u_step.real;
00140 offset += sizeof(this->step);
00141 unsigned char data_lengthT = *(inbuffer + offset++);
00142 if(data_lengthT > data_length)
00143 this->data = (unsigned char*)realloc(this->data, data_lengthT * sizeof(unsigned char));
00144 offset += 3;
00145 data_length = data_lengthT;
00146 for( unsigned char i = 0; i < data_length; i++){
00147 union {
00148 unsigned char real;
00149 unsigned char base;
00150 } u_st_data;
00151 u_st_data.base = 0;
00152 u_st_data.base |= ((typeof(u_st_data.base)) (*(inbuffer + offset + 0))) << (8 * 0);
00153 this->st_data = u_st_data.real;
00154 offset += sizeof(this->st_data);
00155 memcpy( &(this->data[i]), &(this->st_data), sizeof(unsigned char));
00156 }
00157 return offset;
00158 }
00159
00160 const char * getType(){ return "sensor_msgs/Image"; };
00161
00162 };
00163
00164 }
00165 #endif