# nexuscompress-text

Text domain module for NexusCompress.

## Overview

Provides `TextCompressor` for compressing batches of text messages (notifications,
alerts, chat messages, short documents) using length-prefixed encoding and `zstd`
compression. Designed for workloads where many similar short-to-medium text payloads
are compressed together, allowing `zstd` to exploit cross-message redundancy.

## Key Types

| Type | Description |
|---|---|
| `TextCompressor` | Main compressor; built from a `TextConfig` |
| `TextConfig` | Configuration with `max_dict_size` hint |

## Configuration

```rust
use nexuscompress_text::{TextCompressor, TextConfig};

let config = TextConfig {
    max_dict_size: 65536,  // dictionary size hint (bytes)
};
let compressor = TextCompressor::new(config);
```

The `max_dict_size` is passed as metadata to the codec context. The default value
is 65536 bytes.

## Usage

```rust
let messages = vec![
    "Hello, world!",
    "Your order #12345 has shipped.",
    "Reminder: meeting at 3pm.",
];

let compressed = compressor.compress_batch(&messages)?;

// Decompress
let decompressed = compressor.decompress_batch(&compressed)?;
assert_eq!(decompressed[0], "Hello, world!");
assert_eq!(decompressed.len(), 3);
```

## Encoding Format

Messages are encoded as a single byte buffer with u32 LE length prefixes:

```
For each message:
  u32 LE: message length in bytes
  [u8]:   UTF-8 message bytes
```

This intermediate buffer is then compressed with `zstd` and stored in a `Frame`.

## Frame Format

The compressed output is a serialized `Frame` containing:
- An embedded `Plan` with a single field ("messages") and a `zstd` codec
- A CRC32 checksum

## Supported Content

- ASCII text
- Unicode / UTF-8 text (CJK, accented characters, emoji, etc.)
- Empty strings (zero-length messages are preserved)
- Messages containing newlines, tabs, and other whitespace

## Error Handling

- Returns `CompressError::EmptyInput` if no messages are provided.
- Returns `CompressError::InvalidFrame` for truncated or corrupt frame data.
- Returns `CompressError::CodecError` for invalid UTF-8 in stored messages.

## Dependencies

- `nexuscompress-core` -- Plan, Schema, Frame, Codec trait
- `nexuscompress-codecs` -- Codec implementations (zstd)
- `nexuscompress-graph` -- Plan graph utilities

## License

MIT OR Apache-2.0
