kitt_platform
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros
Image.h
Go to the documentation of this file.
1 #ifndef _ROS_sensor_msgs_Image_h
2 #define _ROS_sensor_msgs_Image_h
3 
4 #include <stdint.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include "ros/msg.h"
8 #include "std_msgs/Header.h"
9 
10 namespace sensor_msgs
11 {
12 
13  class Image : public ros::Msg
14  {
15  public:
17  uint32_t height;
18  uint32_t width;
19  const char* encoding;
20  uint8_t is_bigendian;
21  uint32_t step;
22  uint8_t data_length;
23  uint8_t st_data;
24  uint8_t * data;
25 
26  Image():
27  header(),
28  height(0),
29  width(0),
30  encoding(""),
31  is_bigendian(0),
32  step(0),
33  data_length(0), data(NULL)
34  {
35  }
36 
37  virtual int serialize(unsigned char *outbuffer) const
38  {
39  int offset = 0;
40  offset += this->header.serialize(outbuffer + offset);
41  *(outbuffer + offset + 0) = (this->height >> (8 * 0)) & 0xFF;
42  *(outbuffer + offset + 1) = (this->height >> (8 * 1)) & 0xFF;
43  *(outbuffer + offset + 2) = (this->height >> (8 * 2)) & 0xFF;
44  *(outbuffer + offset + 3) = (this->height >> (8 * 3)) & 0xFF;
45  offset += sizeof(this->height);
46  *(outbuffer + offset + 0) = (this->width >> (8 * 0)) & 0xFF;
47  *(outbuffer + offset + 1) = (this->width >> (8 * 1)) & 0xFF;
48  *(outbuffer + offset + 2) = (this->width >> (8 * 2)) & 0xFF;
49  *(outbuffer + offset + 3) = (this->width >> (8 * 3)) & 0xFF;
50  offset += sizeof(this->width);
51  uint32_t length_encoding = strlen(this->encoding);
52  memcpy(outbuffer + offset, &length_encoding, sizeof(uint32_t));
53  offset += 4;
54  memcpy(outbuffer + offset, this->encoding, length_encoding);
55  offset += length_encoding;
56  *(outbuffer + offset + 0) = (this->is_bigendian >> (8 * 0)) & 0xFF;
57  offset += sizeof(this->is_bigendian);
58  *(outbuffer + offset + 0) = (this->step >> (8 * 0)) & 0xFF;
59  *(outbuffer + offset + 1) = (this->step >> (8 * 1)) & 0xFF;
60  *(outbuffer + offset + 2) = (this->step >> (8 * 2)) & 0xFF;
61  *(outbuffer + offset + 3) = (this->step >> (8 * 3)) & 0xFF;
62  offset += sizeof(this->step);
63  *(outbuffer + offset++) = data_length;
64  *(outbuffer + offset++) = 0;
65  *(outbuffer + offset++) = 0;
66  *(outbuffer + offset++) = 0;
67  for( uint8_t i = 0; i < data_length; i++){
68  *(outbuffer + offset + 0) = (this->data[i] >> (8 * 0)) & 0xFF;
69  offset += sizeof(this->data[i]);
70  }
71  return offset;
72  }
73 
74  virtual int deserialize(unsigned char *inbuffer)
75  {
76  int offset = 0;
77  offset += this->header.deserialize(inbuffer + offset);
78  this->height = ((uint32_t) (*(inbuffer + offset)));
79  this->height |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
80  this->height |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
81  this->height |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
82  offset += sizeof(this->height);
83  this->width = ((uint32_t) (*(inbuffer + offset)));
84  this->width |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
85  this->width |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
86  this->width |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
87  offset += sizeof(this->width);
88  uint32_t length_encoding;
89  memcpy(&length_encoding, (inbuffer + offset), sizeof(uint32_t));
90  offset += 4;
91  for(unsigned int k= offset; k< offset+length_encoding; ++k){
92  inbuffer[k-1]=inbuffer[k];
93  }
94  inbuffer[offset+length_encoding-1]=0;
95  this->encoding = (char *)(inbuffer + offset-1);
96  offset += length_encoding;
97  this->is_bigendian = ((uint8_t) (*(inbuffer + offset)));
98  offset += sizeof(this->is_bigendian);
99  this->step = ((uint32_t) (*(inbuffer + offset)));
100  this->step |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
101  this->step |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
102  this->step |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
103  offset += sizeof(this->step);
104  uint8_t data_lengthT = *(inbuffer + offset++);
105  if(data_lengthT > data_length)
106  this->data = (uint8_t*)realloc(this->data, data_lengthT * sizeof(uint8_t));
107  offset += 3;
108  data_length = data_lengthT;
109  for( uint8_t i = 0; i < data_length; i++){
110  this->st_data = ((uint8_t) (*(inbuffer + offset)));
111  offset += sizeof(this->st_data);
112  memcpy( &(this->data[i]), &(this->st_data), sizeof(uint8_t));
113  }
114  return offset;
115  }
116 
117  const char * getType(){ return "sensor_msgs/Image"; };
118  const char * getMD5(){ return "060021388200f6f0f447d0fcd9c64743"; };
119 
120  };
121 
122 }
123 #endif
virtual int deserialize(unsigned char *inbuffer)
Definition: Header.h:53
uint32_t height
Definition: Image.h:17
uint8_t data_length
Definition: Image.h:22
uint8_t is_bigendian
Definition: Image.h:20
uint32_t step
Definition: Image.h:21
virtual int serialize(unsigned char *outbuffer) const
Definition: Header.h:27
Definition: Image.h:13
Image()
Definition: Image.h:26
virtual int serialize(unsigned char *outbuffer) const
Definition: Image.h:37
Definition: Header.h:13
const char * encoding
Definition: Image.h:19
const char * getMD5()
Definition: Image.h:118
uint32_t width
Definition: Image.h:18
uint8_t st_data
Definition: Image.h:23
virtual int deserialize(unsigned char *inbuffer)
Definition: Image.h:74
uint8_t * data
Definition: Image.h:24
std_msgs::Header header
Definition: Image.h:16
const char * getType()
Definition: Image.h:117
Definition: msg.h:43