VSM C++ SDK
Vehicle Specific Modules SDK
io_buffer.h
Go to the documentation of this file.
1 // Copyright (c) 2014, Smart Projects Holdings Ltd
2 // All rights reserved.
3 // See LICENSE file for license details.
4 
11 #include <ugcs/vsm/utils.h>
12 
13 #include <memory>
14 #include <vector>
15 
16 #ifndef IO_BUFFER_H_
17 #define IO_BUFFER_H_
18 
19 namespace ugcs {
20 namespace vsm {
21 
33 class Io_buffer: public std::enable_shared_from_this<Io_buffer> {
35 public:
36 
38  static const size_t END;
39 
49  Io_buffer(const Io_buffer &buf, size_t offset = 0, size_t len = END);
50 
52  Io_buffer(Io_buffer &&buf);
53 
67  explicit Io_buffer(std::shared_ptr<const std::vector<uint8_t>> &&data_vec,
68  size_t offset = 0, size_t len = END);
69 
73  Io_buffer(std::vector<uint8_t> &&data_vec, size_t offset = 0, size_t len = END);
74 
76  Io_buffer();
77 
81  Io_buffer(const std::string &data_str);
82 
88  Io_buffer(const void *data, size_t len);
89 
90  ~Io_buffer();
91 
99  Ptr
100  Concatenate(Io_buffer::Ptr buf);
101 
111  Ptr
112  Slice(size_t offset, size_t len = END) const;
113 
115  size_t
116  Get_length() const
117  {
118  return len;
119  }
120 
124  const void *
125  Get_data() const;
126 
128  std::string
129  Get_string() const;
130 
132  std::string
133  Get_ascii() const;
134 
136  std::string
137  Get_hex() const;
138 
139 private:
145  std::shared_ptr<const std::vector<uint8_t>> data;
147  size_t offset;
149  size_t len;
150 
161  Io_buffer(const std::shared_ptr<const std::vector<uint8_t>> &data_vec,
162  size_t offset = 0, size_t len = END);
163 
165  static Ptr
166  Create(const std::shared_ptr<const std::vector<uint8_t>> &data_vec,
167  size_t offset = 0, size_t len = END);
168 
170  void
171  Init_data(size_t offset, size_t len);
172 };
173 
174 } /* namespace vsm */
175 } /* namespace ugcs */
176 
177 #endif /* IO_BUFFER_H_ */
UGCS root namespace.
Definition: android-linux/ugcs/vsm/platform_sockets.h:27
static Ptr Create(Args &&...args)
Create an instance.
Definition: io_buffer.h:34
std::string Get_ascii() const
Get buffer data as string of characters.
Ptr Concatenate(Io_buffer::Ptr buf)
Concatenate this buffer data with another buffer data and return new buffer object which contains res...
STL namespace.
Various common utilities.
static const size_t END
Special value which references data end.
Definition: io_buffer.h:38
size_t Get_length() const
Get length of the contained data.
Definition: io_buffer.h:116
const void * Get_data() const
Get pointer to raw data stored in the buffer.
Generic I/O buffer.
Definition: io_buffer.h:33
std::shared_ptr< Io_buffer > Ptr
Pointer type.
Definition: io_buffer.h:34
std::string Get_hex() const
Get buffer data as hex string.
std::string Get_string() const
Get buffer content as string.
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
Ptr Slice(size_t offset, size_t len=END) const
Take slice from buffer data.
Io_buffer()
Construct empty buffer.