/*
 * protocol/envelope.h — thin helpers around the generated protobuf types.
 *
 * Hides the generated namespace from callers that only need to send/receive
 * envelopes without touching proto types directly. All callers that do need
 * the proto types can #include the generated header alongside this one.
 *
 * Requires VOICECAT_HAS_NET (protobuf codegen).
 */
#ifndef VOICECAT_PROTOCOL_ENVELOPE_H
#define VOICECAT_PROTOCOL_ENVELOPE_H

#ifdef VOICECAT_HAS_NET

#include <cstddef>
#include <cstdint>
#include <vector>

// Generated by protobuf_generate(); lives in the build tree.
#include "proto/voicecat.pb.h"

namespace voicecat::protocol {

// Serialize env into a framed wire buffer: [big-endian u32 length][payload].
// Returns false on serialization error.
bool encode_envelope(const voicecat::v1::Envelope& env, std::vector<uint8_t>& out);

// Deserialize a raw payload (no length prefix) into out.
// Returns false on parse error.
bool decode_envelope(const uint8_t* data, size_t len, voicecat::v1::Envelope& out);
bool decode_envelope(const std::vector<uint8_t>& frame, voicecat::v1::Envelope& out);

// Stamp a monotonically increasing request_id (thread-safe, relaxed ordering).
uint64_t next_request_id();

}  // namespace voicecat::protocol

#endif  // VOICECAT_HAS_NET
#endif  // VOICECAT_PROTOCOL_ENVELOPE_H
