libbgp  0.6
A C++ BGP Library.
value-op.h
Go to the documentation of this file.
1 
11 #ifndef VALUE_OP_H_
12 #define VALUE_OP_H_
13 #include <stdint.h>
14 #include <unistd.h>
15 #include <string.h>
16 
17 namespace libbgp {
18 
28 template <typename T> T getValue(const uint8_t **buffer);
29 
40 template <typename T> size_t putValue(uint8_t **buffer, T value);
41 
42 template <typename T> T getValue(const uint8_t **buffer) {
43  auto *buf = *buffer;
44  size_t sz = sizeof(T);
45  T var;
46  memcpy(&var, buf, sz);
47  *buffer = buf + sz;
48  return var;
49 }
50 
51 template <typename T> size_t putValue(uint8_t **buffer, T value) {
52  uint8_t *buf = *buffer;
53  size_t sz = sizeof(T);
54  memcpy(buf, &value, sz);
55  *buffer = buf + sz;
56  return sz;
57 }
58 
59 }
60 #endif // VALUE_OP_H_
T getValue(const uint8_t **buffer)
Get value from buffer.
Definition: value-op.h:42
size_t putValue(uint8_t **buffer, T value)
Put value to buffer.
Definition: value-op.h:51
Definition: bgp-afi.h:14