Add RequestInfo/ResponseInfo with MAC address

This commit is contained in:
Ian Gulliver
2026-04-04 15:00:16 +09:00
parent 46af5becfe
commit d2b9a2e2aa
6 changed files with 67 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <expected>
@@ -366,6 +367,9 @@ public:
pack_result pack(const std::vector<uint8_t> &v) { return pack_bin(v); }
template <size_t N>
pack_result pack(const std::array<uint8_t, N> &v) { return pack_bin(v); }
template <typename... Ts>
pack_result pack(const std::tuple<Ts...> &t) {
auto r = pack_array(sizeof...(Ts));
@@ -725,6 +729,15 @@ inline result<parser> unpack(const parser &p, std::string &out) {
return p.next();
}
template <size_t N>
result<parser> unpack(const parser &p, std::array<uint8_t, N> &out) {
auto v = p.get_binary_view();
if (!v) return std::unexpected(v.error());
if (v->size() != N) return std::unexpected(error_code::type_error);
std::copy(v->begin(), v->end(), out.begin());
return p.next();
}
inline result<parser> unpack(const parser &p, std::vector<uint8_t> &out) {
auto v = p.get_binary_view();
if (!v) return std::unexpected(v.error());

View File

@@ -1,4 +1,5 @@
#pragma once
#include <array>
#include <cstdint>
#include <string>
#include <tuple>
@@ -16,6 +17,19 @@ struct RequestPICOBOOT {
auto as_tuple() { return std::tie(); }
};
struct RequestInfo {
static constexpr int8_t ext_id = 4;
auto as_tuple() const { return std::tie(); }
auto as_tuple() { return std::tie(); }
};
struct ResponseInfo {
static constexpr int8_t ext_id = 5;
std::array<uint8_t, 6> mac;
auto as_tuple() const { return std::tie(mac); }
auto as_tuple() { return std::tie(mac); }
};
struct DeviceError {
static constexpr int8_t ext_id = 3;
uint32_t code;