#pragma once #include #include #include #include #include "secsgem/secs2/codec.hpp" #include "secsgem/secs2/item.hpp" namespace secsgem::secs2 { // A logical SECS-II message: stream/function, the W-bit (reply expected), and // an optional root data item as the body. The transport (HSMS) header carries // stream/function/W on the wire; the body bytes are the encoded root item. struct Message { uint8_t stream = 0; uint8_t function = 0; bool reply_expected = false; // W-bit std::optional body; Message() = default; Message(uint8_t s, uint8_t f, bool w, std::optional b = std::nullopt) : stream(s), function(f), reply_expected(w), body(std::move(b)) {} std::vector encode_body() const { if (!body) return {}; return encode(*body); } static Message from_body(uint8_t stream, uint8_t function, bool reply_expected, const std::vector& body_bytes) { Message m(stream, function, reply_expected); if (!body_bytes.empty()) m.body = decode(body_bytes); return m; } // e.g. S1F2 // > . std::string sml() const { std::string out = "S" + std::to_string(stream) + "F" + std::to_string(function); if (reply_expected) out += " W"; if (body) { out += "\n "; out += to_sml(*body); } out += " ."; return out; } }; } // namespace secsgem::secs2