38 slice(std::shared_ptr<
const std::vector<uint8_t>> packet)
41 slice(std::shared_ptr<
const std::vector<uint8_t>> packet,
size_t offset,
57 template <
typename T,
size_t N = sizeof(T)>
59 static_assert(N <=
sizeof(T));
62 for (
size_t n = 0; n < N; n++) {
63 value |= (T)
at(n) << (8 * n);
73 template <
typename T,
size_t N = sizeof(T)>
75 static_assert(N <=
sizeof(T));
78 for (
size_t n = 0; n < N; n++) {
79 value = (value << 8) | (T)
at(n);
87 uint8_t
at(
size_t offset)
const {
88 assert(offset <=
size_);
107 std::vector<uint8_t>
bytes()
const {
120 std::shared_ptr<const std::vector<uint8_t>>
packet_;
139 template <
typename T,
size_t N = sizeof(T)>
140 static void write_le(std::vector<uint8_t>& output, T value) {
141 static_assert(N <=
sizeof(T));
142 for (
size_t n = 0; n < N; n++) {
143 output.push_back(value >> (8 * n));
148 template <
typename T,
size_t N = sizeof(T)>
149 static void write_be(std::vector<uint8_t>& output, T value) {
150 static_assert(N <=
sizeof(T));
151 for (
size_t n = 0; n < N; n++) {
152 output.push_back(value >> (8 * (N - 1 - n)));
158 std::vector<uint8_t> output;
Interface class for generated packet builders.
Definition: packet_runtime.h:126
static void write_be(std::vector< uint8_t > &output, T value)
Write a scalar value encoded in big-endian.
Definition: packet_runtime.h:149
virtual ~Builder()=default
static void write_le(std::vector< uint8_t > &output, T value)
Write a scalar value encoded in little-endian.
Definition: packet_runtime.h:140
virtual void Serialize(std::vector< uint8_t > &) const
Definition: packet_runtime.h:132
virtual std::vector< uint8_t > SerializeToBytes() const
Helper method to serialize the packet to a byte vector.
Definition: packet_runtime.h:157
virtual size_t GetSize() const
Definition: packet_runtime.h:136
Definition: packet_runtime.h:34
std::shared_ptr< const std::vector< uint8_t > > packet_
Definition: packet_runtime.h:120
std::vector< uint8_t > bytes() const
Return the contents of the slice as a byte vector.
Definition: packet_runtime.h:107
T read_le()
Definition: packet_runtime.h:58
slice subrange(size_t offset, size_t size) const
Definition: packet_runtime.h:48
slice(slice const &)=default
uint8_t at(size_t offset) const
Definition: packet_runtime.h:87
bool operator==(slice const &other) const
Definition: packet_runtime.h:112
slice(std::shared_ptr< const std::vector< uint8_t > > packet, size_t offset, size_t size)
Definition: packet_runtime.h:41
size_t size_
Definition: packet_runtime.h:122
slice(std::shared_ptr< const std::vector< uint8_t > > packet)
Definition: packet_runtime.h:38
void skip(size_t size)
Definition: packet_runtime.h:94
size_t offset_
Definition: packet_runtime.h:121
T read_be()
Definition: packet_runtime.h:74
size_t size() const
Return the size of the slice in bytes.
Definition: packet_runtime.h:104
void clear()
Empty the slice.
Definition: packet_runtime.h:101
Definition: packet_runtime.h:29
Definition: logging.h:464