Expand description
Thin sync-first server/network boundary exposure layer.
netbat is intentionally thin: nb exposes, sb dispatches, bp records. This
crate can describe server-facing modules, endpoints, and route tables around
syncbat modules or cores. It can also handle bounded sync transport
frames, but it does not own dispatch decisions, run handlers directly, or
write batpak records.
The crate is designed to be imported as:
use netbat as nb;§Frame round-trip
Encode a CALL request, decode it back, and inspect the parts. The
encoder enforces the operation-name grammar via the substrate
OperationName newtype; downstream code never re-parses.
use netbat as nb;
let frame = nb::encode_request("system.heartbeat", &[0xde, 0xad]);
assert_eq!(frame, b"NETBAT/1 CALL system.heartbeat dead\n");
let parsed = nb::decode_line(&frame, &nb::Limits::default()).expect("decode");
assert_eq!(parsed.operation(), "system.heartbeat");
assert_eq!(parsed.input(), &[0xde, 0xad]);§Response framing
encode_response emits either OK <hex>\n or ERR <code> <hex>\n.
The ERR-frame code is a stable token from
NetbatError::code — never a runtime
string. The message half is hex of UTF-8 text, not MessagePack.
use netbat as nb;
// Success: OK <hex>\n
let ok = nb::encode_response(Ok(b"hi"));
assert_eq!(ok, b"OK 6869\n");
// Error: ERR <code> <hex>\n
let err = nb::NetbatError::MalformedRequest { reason: "bad" };
let err_frame = nb::encode_response(Err(&err));
assert!(err_frame.starts_with(b"ERR malformed_request "));
assert!(err_frame.ends_with(b"\n"));Structs§
- Core
Health - Borrowed health check over a syncbat core’s mounted operation descriptors.
- Endpoint
- A syncbat operation exposed at a server/network boundary.
- Introspection
- Introspection report for exposed boundary metadata.
- IoTimeouts
- Optional read/write timeout hints for listener owners.
- Limits
- Bounded transport limits for netbat’s blocking line protocol.
- Operation
Name - Stable operation name. Validated once at construction; downstream code never re-parses the grammar.
- Request
Frame - Decoded request frame for netbat’s blocking line protocol.
- Response
Frame - Encoded runtime output returned through a netbat transport frame.
- Route
- A mounted boundary route.
- Server
- Minimal server-boundary registry.
- Server
Module - Server-facing wrapper for a data-oriented syncbat module.
- Shutdown
Handle - Shared shutdown flag for blocking TCP listener loops.
- TcpServe
Stats - Summary returned after a blocking TCP listener exits.
- TcpServer
Config - Blocking TCP server limits.
Enums§
- Netbat
Error - Error returned by netbat transport framing or syncbat dispatch.
- Operation
Name Error - Operation-name grammar violation surfaced by
OperationName::new. - Route
Validation Error - Boundary route validation failure.
Constants§
- CALL_
VERB - Request verb used by netbat’s line protocol.
- DEFAULT_
MAX_ CONNECTIONS - Default maximum accepted connections for
serve_tcp_listener. - DEFAULT_
MAX_ INPUT_ BYTES - Default maximum decoded input size accepted by the line transport.
- DEFAULT_
MAX_ LINE_ BYTES - Default maximum request line size accepted by the line transport.
- DEFAULT_
MAX_ OPERATION_ NAME_ BYTES - Default maximum operation name size accepted by the line transport.
- DEFAULT_
MAX_ OUTPUT_ BYTES - Default maximum handler output size encoded into a response frame.
- DEFAULT_
MAX_ REQUESTS_ PER_ CONNECTION - Default maximum requests served from one accepted TCP connection.
- LAYER_
RULE - Stable crate-layer rule for docs, diagnostics, and tests.
- LINE_
PROTOCOL_ VERSION - Current version token accepted by netbat’s versioned line protocol.
- MAX_
ROUTE_ PATH_ BYTES - Maximum bytes accepted for a boundary route path.
- PROTOCOL_
PREFIX - Prefix used by every versioned netbat line-protocol token.
Functions§
- decode_
hex - Decode a lowercase or uppercase hexadecimal byte string with a decoded-size limit.
- decode_
hex_ str - Decode a lowercase or uppercase hexadecimal
&str. - decode_
line - Decode one netbat line-protocol request.
- dispatch_
frame - Dispatch a decoded request frame through syncbat.
- encode_
hex - Encode
bytesas a lowercase hexadecimal byte string and return the owned buffer. - encode_
hex_ into - Append lowercase hexadecimal encoding of
bytesintooutput. - encode_
hex_ str - Encode
bytesas a lowercase hexadecimalString. - encode_
request - Encode a stable versioned request line.
- encode_
response - Encode a stable response line.
- inspect_
core_ operations - Inspect whether named operations are mounted in a borrowed syncbat core.
- introspect_
modules - Build an introspection report over server-facing module metadata.
- serve_
stream - Serve one request from an already-accepted blocking stream.
- serve_
tcp_ listener - Serve a blocking TCP listener sequentially until shutdown or limits stop it.