Documentation
¶
Overview ¶
Package mach defines foundational Layer 7 protocol engines, wire codecs, and stream multiplexing abstractions for Go.
Root contracts unify transport mechanics across HTTP/1.1, HTTP/2, and HTTP/3 over QUIC, establishing protocol-agnostic interfaces for connection lifecycles, zero-allocation framing, and request dispatching.
Unified Protocol Model ¶
Protocol engines expose a cohesive hierarchy decoupling network I/O from protocol state machines:
- Engine: Protocol connection factory establishing outbound transports or yielding protocol-specific multiplexers.
- Conn: Active transport carrier managing one or more concurrent request-response streams.
- Stream: Isolated data-in-motion stream supporting zero-copy frame ingestion (Stream.ReadFrame) and standard streaming I/O.
- Frame: Protocol-agnostic representation of serialized wire frames (Frame.Type, Frame.Payload), encompassing standard control, header, and data primitives.
- Handler and HandlerFunc: Universal request processing abstraction serving streams across HTTP generations without transport coupling.
Architectural Invariants ¶
- Zero-Allocation Steady State: Wire framing, header parsing, payload masking, and stream demultiplexing execute without heap allocations on active streams.
- 64-Bit SWAR Acceleration: Vectorized bit-manipulation kernels scan header delimiters and apply WebSocket masking masks at memory bandwidth limits.
- Asymmetric Isolation: Protocol parsers reject malformed ingress frames at the wire boundary, safeguarding application handlers from malformed traffic and network congestion.
- Sans-I/O State Machines: Event-driven parsing pipelines decouple protocol transitions from thread scheduling and blocking socket operations.
Supported Protocols & Standards ¶
- RFC 9110: HTTP Semantics
- RFC 9112: HTTP/1.1 (Chunked Transfer, Pipelining)
- RFC 9113: HTTP/2 (Binary Framing, Stream Multiplexing, Flow Control)
- RFC 9114: HTTP/3 (QUIC-Mapped Transport, Control Streams)
- RFC 7541: HPACK - Header Compression for HTTP/2
- RFC 9204: QPACK - Field Compression for HTTP/3
- RFC 6455: The WebSocket Protocol
- RFC 8441: Bootstrapping WebSockets with HTTP/2 (Extended CONNECT)
- RFC 9220: Bootstrapping WebSockets with HTTP/3 (Extended CONNECT)
- RFC 7838: HTTP Alternative Services (Alt-Svc)
Example ¶
Example provides a quick overview of mach's universal protocol-agnostic handler contract.
package main
import (
"fmt"
"github.com/lemon4ksan/mach"
)
func main() {
// A universal HandlerFunc processes streams transparently across HTTP/1.1, HTTP/2, and HTTP/3.
handler := mach.HandlerFunc(func(stream mach.Stream) error {
// Read wire frames without heap allocations
frame, err := stream.ReadFrame()
if err != nil {
return err
}
// Inspect protocol-agnostic frame types and zero-copy payloads
switch frame.Type() {
case mach.FrameHeaders:
_ = frame.Payload()
case mach.FrameData:
_ = frame.Payload()
}
return nil
})
_ = handler
fmt.Println("mach protocol engine ready")
}
Output: mach protocol engine ready
Index ¶
Examples ¶
Constants ¶
const ( FrameData uint8 = 0x00 FrameHeaders uint8 = 0x01 FramePriority uint8 = 0x02 FrameReset uint8 = 0x03 FrameSettings uint8 = 0x04 FramePushPromise uint8 = 0x05 FramePing uint8 = 0x06 FrameGoAway uint8 = 0x07 FrameWindowUpdate uint8 = 0x08 FrameContinuation uint8 = 0x09 )
Standard protocol-agnostic frame type identifiers.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface {
io.Closer
// OpenStream creates a new request-response stream (Zero-alloc where possible).
OpenStream(ctx context.Context) (Stream, error)
}
Conn represents an active protocol connection. For multiplexed protocols (H2, H3), it manages multiple Streams. For H1, it acts as a single-stream carrier.
Example ¶
ExampleConn demonstrates the abstract protocol connection contract.
package main
import (
"fmt"
"github.com/lemon4ksan/mach"
)
func main() {
var _ mach.Conn // Interface compliance check
fmt.Println("mach protocol engine contract")
}
Output: mach protocol engine contract
type Engine ¶
type Engine interface {
// Dial establishes a connection or yields a protocol-specific multiplexer.
Dial(ctx context.Context, addr string) (Conn, error)
}
Engine defines the universal contract for protocol engines (H1/H2/H3/QUIC). It acts as a factory for protocol connections.
type Frame ¶
type Frame interface {
// Type returns the protocol-specific frame type identifier.
Type() uint8
// Payload yields the zero-copy slice of the frame body.
Payload() []byte
}
Frame represents a Data-In-Motion abstraction of a protocol frame (H2/H3/QUIC).
type Handler ¶ added in v0.2.0
type Handler interface {
// Serve processes an incoming request/response stream across H1, H2, or H3.
Serve(stream Stream) error
}
Handler defines the universal contract for protocol-agnostic request dispatching.
type HandlerFunc ¶ added in v0.2.0
HandlerFunc is an adapter to allow the use of ordinary functions as universal Handlers.
func (HandlerFunc) Serve ¶ added in v0.2.0
func (f HandlerFunc) Serve(stream Stream) error
Serve calls f(stream).
type Stream ¶
type Stream interface {
io.Reader
io.Writer
io.Closer
// ReadFrame parses the next protocol-specific frame without heap allocations.
ReadFrame() (Frame, error)
}
Stream represents an isolated request/response lifecycle. It bypasses standard io.Reader/io.Writer allocations by using Zero-copy methods or integrating directly with the foundation/bufkit arenas.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides high-performance client transport engines, connection pooling, multi-protocol session abstractions, and zero-allocation proxy integration across HTTP/1.1, HTTP/2, and HTTP/3.
|
Package client provides high-performance client transport engines, connection pooling, multi-protocol session abstractions, and zero-allocation proxy integration across HTTP/1.1, HTTP/2, and HTTP/3. |
|
h1
Package h1 implements the HTTP/1.1 client protocol engine conforming to RFC 9112, featuring asymmetric isolation and zero-allocation persistent connection reuse.
|
Package h1 implements the HTTP/1.1 client protocol engine conforming to RFC 9112, featuring asymmetric isolation and zero-allocation persistent connection reuse. |
|
h2
Package h2 implements the HTTP/2 client protocol engine conforming to RFC 9113, featuring stream multiplexing, HPACK header compression, and asymmetric isolation.
|
Package h2 implements the HTTP/2 client protocol engine conforming to RFC 9113, featuring stream multiplexing, HPACK header compression, and asymmetric isolation. |
|
h3
Package h3 implements the HTTP/3 client protocol engine conforming to RFC 9114, featuring QUIC stream multiplexing, QPACK field compression, and asymmetric isolation.
|
Package h3 implements the HTTP/3 client protocol engine conforming to RFC 9114, featuring QUIC stream multiplexing, QPACK field compression, and asymmetric isolation. |
|
net
|
|
|
proxy
Package proxy implements zero-allocation proxy dialers and tunnel negotiation engines supporting SOCKS5 and HTTP CONNECT protocols.
|
Package proxy implements zero-allocation proxy dialers and tunnel negotiation engines supporting SOCKS5 and HTTP CONNECT protocols. |
|
proxy/socks
Package socks implements a zero-allocation SOCKS version 5 client conforming to RFC 1928 and RFC 1929.
|
Package socks implements a zero-allocation SOCKS version 5 client conforming to RFC 1928 and RFC 1929. |
|
proxy/socks/sockstest
Package sockstest implements test harnesses, mock servers, and frame synthesizers for SOCKS protocols.
|
Package sockstest implements test harnesses, mock servers, and frame synthesizers for SOCKS protocols. |
|
quic
Package quic provides an RFC 9000 compliant, zero-allocation QUIC transport protocol implementation.
|
Package quic provides an RFC 9000 compliant, zero-allocation QUIC transport protocol implementation. |
|
quic/core/handshake
Package handshake implements a modern, clean-room TLS 1.3 cryptographic handshake session driver for QUIC (RFC 9001 and RFC 9369) directly on the Go standard library crypto/tls.QUICConn API without legacy assembly or internal compiler shims.
|
Package handshake implements a modern, clean-room TLS 1.3 cryptographic handshake session driver for QUIC (RFC 9001 and RFC 9369) directly on the Go standard library crypto/tls.QUICConn API without legacy assembly or internal compiler shims. |
|
quic/core/stream
Package stream implements high-performance, zero-allocation stream multiplexing, flow control, and reassembly for QUIC connections (RFC 9000 §2, §3, and §4).
|
Package stream implements high-performance, zero-allocation stream multiplexing, flow control, and reassembly for QUIC connections (RFC 9000 §2, §3, and §4). |
|
quic/core/wire
Package wire provides an ultra-lightweight, zero-allocation wire and packet engine for QUIC (RFC 9000, RFC 9001, and RFC 9369).
|
Package wire provides an ultra-lightweight, zero-allocation wire and packet engine for QUIC (RFC 9000, RFC 9001, and RFC 9369). |
|
quic/varint
Package varint implements QUIC variable-length integer encoding and decoding routines (RFC 9000).
|
Package varint implements QUIC variable-length integer encoding and decoding routines (RFC 9000). |
|
proto
|
|
|
cachestatus
Package cachestatus implements the Cache-Status HTTP Response Header Field strictly conforming to RFC 9211.
|
Package cachestatus implements the Cache-Status HTTP Response Header Field strictly conforming to RFC 9211. |
|
codec/compress
Package compress implements HTTP payload compression and decompression codecs conforming to RFC 9110 §8.4.
|
Package compress implements HTTP payload compression and decompression codecs conforming to RFC 9110 §8.4. |
|
codec/hpack
Package hpack implements HTTP/2 header compression conforming to RFC 7541.
|
Package hpack implements HTTP/2 header compression conforming to RFC 7541. |
|
codec/qpack
Package qpack implements HTTP/3 field section compression conforming to RFC 9204.
|
Package qpack implements HTTP/3 field section compression conforming to RFC 9204. |
|
grpcweb
Package grpcweb implements gRPC-Web wire framing, streaming, and trailer processing.
|
Package grpcweb implements gRPC-Web wire framing, streaming, and trailer processing. |
|
h1
Package h1 implements low-level HTTP/1.1 wire framing, SWAR-accelerated header scanning, and chunked transfer encoding conforming to RFC 9112.
|
Package h1 implements low-level HTTP/1.1 wire framing, SWAR-accelerated header scanning, and chunked transfer encoding conforming to RFC 9112. |
|
h2
Package h2 implements the HTTP/2 binary framing layer, stream flow control state machines, and slab-allocated frame pooling conforming to RFC 9113.
|
Package h2 implements the HTTP/2 binary framing layer, stream flow control state machines, and slab-allocated frame pooling conforming to RFC 9113. |
|
h2/fsm
Package fsm implements a Sans-I/O finite state machine for HTTP/2 protocol processing conforming to RFC 9113.
|
Package fsm implements a Sans-I/O finite state machine for HTTP/2 protocol processing conforming to RFC 9113. |
|
h2/overlay
Package overlay provides in-situ, zero-copy HTTP/2 frame inspection and payload extraction directly over raw byte buffers (RFC 9113).
|
Package overlay provides in-situ, zero-copy HTTP/2 frame inspection and payload extraction directly over raw byte buffers (RFC 9113). |
|
h3
Package h3 implements the HTTP/3 application protocol layer, binary variable-length integer framing, unidirectional control stream state tracking, and QPACK field compression conforming to RFC 9114 and RFC 9204.
|
Package h3 implements the HTTP/3 application protocol layer, binary variable-length integer framing, unidirectional control stream state tracking, and QPACK field compression conforming to RFC 9114 and RFC 9204. |
|
headkit
Package headkit provides a zero-allocation, high-performance HTTP header, directive, content-negotiation, and MIME media-type toolkit for Go.
|
Package headkit provides a zero-allocation, high-performance HTTP header, directive, content-negotiation, and MIME media-type toolkit for Go. |
|
http
Package http implements high-performance, zero-allocation HTTP/1.x wire parsing, message serialization, header manipulation, and streaming body decoders conforming to RFC 9110 and RFC 9112.
|
Package http implements high-performance, zero-allocation HTTP/1.x wire parsing, message serialization, header manipulation, and streaming body decoders conforming to RFC 9110 and RFC 9112. |
|
semantic/altsvc
Package altsvc provides zero-allocation parsing and formatting for HTTP Alternative Services (RFC 7838).
|
Package altsvc provides zero-allocation parsing and formatting for HTTP Alternative Services (RFC 7838). |
|
semantic/auth
Package auth implements HTTP Authentication schemes strictly conforming to IETF standards (RFC 7617 Basic, RFC 6750 Bearer, and RFC 9110 HTTP Authentication Framework).
|
Package auth implements HTTP Authentication schemes strictly conforming to IETF standards (RFC 7617 Basic, RFC 6750 Bearer, and RFC 9110 HTTP Authentication Framework). |
|
semantic/contentdisposition
Package contentdisposition implements Content-Disposition header parsing, RFC 8187 parameter encoding/decoding, and safe filename sanitization strictly conforming to RFC 6266 and RFC 8187.
|
Package contentdisposition implements Content-Disposition header parsing, RFC 8187 parameter encoding/decoding, and safe filename sanitization strictly conforming to RFC 6266 and RFC 8187. |
|
semantic/cookie
Package cookie provides high-performance zero-allocation RFC 6265 and RFC 6265bis HTTP cookie parsing, serialization, and management.
|
Package cookie provides high-performance zero-allocation RFC 6265 and RFC 6265bis HTTP cookie parsing, serialization, and management. |
|
semantic/digest
Package digest implements RFC 7616 and RFC 2617 Digest Access Authentication for HTTP transactions.
|
Package digest implements RFC 7616 and RFC 2617 Digest Access Authentication for HTTP transactions. |
|
semantic/etag
Package etag implements RFC 9110 (§8.8.1-§8.8.3) and RFC 9111 HTTP Entity Tags, conditional request matching, and 304 response reconstruction.
|
Package etag implements RFC 9110 (§8.8.1-§8.8.3) and RFC 9111 HTTP Entity Tags, conditional request matching, and 304 response reconstruction. |
|
semantic/hpkp
Package hpkp implements the Public Key Pinning Extension for HTTP strictly conforming to RFC 7469.
|
Package hpkp implements the Public Key Pinning Extension for HTTP strictly conforming to RFC 7469. |
|
semantic/priority
Package priority implements RFC 9218 Extensible Priorities for HTTP/2, HTTP/3, and HTTP/1.1 aligning request resource scheduling with modern Chromium architecture.
|
Package priority implements RFC 9218 Extensible Priorities for HTTP/2, HTTP/3, and HTTP/1.1 aligning request resource scheduling with modern Chromium architecture. |
|
semantic/status
Package status provides RFC 9110 HTTP status codes, canonical reason phrases, and zero-allocation status line formatting and classification utilities.
|
Package status provides RFC 9110 HTTP status codes, canonical reason phrases, and zero-allocation status line formatting and classification utilities. |
|
semantic/uri
Package uri provides high-performance zero-allocation RFC 3986 Uniform Resource Identifier (URI) and query parameter parsing, normalization, and serialization.
|
Package uri provides high-performance zero-allocation RFC 3986 Uniform Resource Identifier (URI) and query parameter parsing, normalization, and serialization. |
|
sse
Package sse implements the Server-Sent Events (SSE) protocol specified by the WHATWG HTML standard.
|
Package sse implements the Server-Sent Events (SSE) protocol specified by the WHATWG HTML standard. |
|
weblink
Package weblink implements Web Linking and Link HTTP header processing conforming to RFC 8288.
|
Package weblink implements Web Linking and Link HTTP header processing conforming to RFC 8288. |
|
ws
Package ws implements the RFC 6455 WebSocket wire protocol, vectorized payload masking, and HTTP/1.1 opening handshake negotiation.
|
Package ws implements the RFC 6455 WebSocket wire protocol, vectorized payload masking, and HTTP/1.1 opening handshake negotiation. |
|
Package server provides a multi-protocol Layer 7 application server binding HTTP/1.1, HTTP/2, and HTTP/3 engines under a unified handler architecture.
|
Package server provides a multi-protocol Layer 7 application server binding HTTP/1.1, HTTP/2, and HTTP/3 engines under a unified handler architecture. |
|
h1
Package h1 implements the HTTP/1.1 server protocol engine conforming to RFC 9112, featuring asymmetric isolation, zero-allocation request parsing, and pipelined execution.
|
Package h1 implements the HTTP/1.1 server protocol engine conforming to RFC 9112, featuring asymmetric isolation, zero-allocation request parsing, and pipelined execution. |
|
h2
Package h2 implements the HTTP/2 server protocol engine conforming to RFC 9113, featuring stream multiplexing, flow control state machines, and asymmetric isolation.
|
Package h2 implements the HTTP/2 server protocol engine conforming to RFC 9113, featuring stream multiplexing, flow control state machines, and asymmetric isolation. |
|
h3
Package h3 implements the HTTP/3 server protocol engine conforming to RFC 9114, featuring QUIC stream demultiplexing, QPACK field compression, and asymmetric isolation.
|
Package h3 implements the HTTP/3 server protocol engine conforming to RFC 9114, featuring QUIC stream demultiplexing, QPACK field compression, and asymmetric isolation. |