Skip to main content

Crate netbat

Crate netbat 

Source
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§

CoreHealth
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.
OperationName
Stable operation name. Validated once at construction; downstream code never re-parses the grammar.
RequestFrame
Decoded request frame for netbat’s blocking line protocol.
ResponseFrame
Encoded runtime output returned through a netbat transport frame.
Route
A mounted boundary route.
Server
Minimal server-boundary registry.
ServerModule
Server-facing wrapper for a data-oriented syncbat module.
ShutdownHandle
Shared shutdown flag for blocking TCP listener loops.
TcpServeStats
Summary returned after a blocking TCP listener exits.
TcpServerConfig
Blocking TCP server limits.

Enums§

NetbatError
Error returned by netbat transport framing or syncbat dispatch.
OperationNameError
Operation-name grammar violation surfaced by OperationName::new.
RouteValidationError
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 bytes as a lowercase hexadecimal byte string and return the owned buffer.
encode_hex_into
Append lowercase hexadecimal encoding of bytes into output.
encode_hex_str
Encode bytes as a lowercase hexadecimal String.
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.