# API Reference
## Types
- `Message`: Core data model containing identifiers, routing metadata, payload bytes, and a `MessageMeta` variant describing the payload semantics.
- `MessageType`: Enumerates text, media, call signaling, and attachment control packets (init/chunk/end/abort/ack).
- `MessageMeta`: Enum covering `Basic` metadata for inline payloads plus dedicated attachment metadata (`AttachmentMeta`, `AttachmentChunkMeta`, `AttachmentAckMeta`, and specialized end/abort data).
- `AttachmentKind`: Distinguishes file/image/video/voice attachments while keeping transfer handling generic.
- `PacketView<'a>`: Lightweight view of a raw packet header plus a borrowed `BODY` slice, useful when filtering packets without decoding.
## Functions
### `validate_message(message: &Message) -> Result<()>`
Ensures the message complies with all validation rules before it is encoded or acted upon.
### `encode_message(message: &Message) -> Result<Vec<u8>>`
Serializes and frames a validated message. Returns a complete packet ready for transport. Fails if validation fails, the serialized body exceeds the per-packet safety bound, or framing constraints are violated.
### `decode_message(packet: &[u8]) -> Result<Message>`
Parses the frame, deserializes the message body with deterministic bincode options, then re-validates the message. Rejects malformed headers, unsupported versions, oversize packets, mismatched lengths, and deserialization errors.
### `peek_packet(packet: &[u8]) -> Result<PacketView<'_>>`
Returns header values and a borrowed view of the packet body without decoding the message. This is useful for quickly filtering packets by version, flags, or declared body size before performing heavier processing.
## Errors
All functions return `Result<T, EnigmaPacketError>` with the following variants:
- `InvalidPacket`: Header formatting, magic bytes, or declared lengths are invalid.
- `UnsupportedVersion`: Packet version does not match the compiled codec.
- `SizeLimitExceeded`: Header or body exceeds the configured maxima (16 MiB per packet).
- `DecodeError`: Bincode deserialization failed because the body is corrupted or inconsistent.
- `ValidationError`: Semantic validation failed (e.g., bad chunk offsets, forbidden metadata combinations).