Pure-Veko NATS Core/Headers wire protocol & wildcard subject matcher alongside Kafka RecordBatch v2 (CRC32C) & Produce/Fetch codecs.
Pure-Veko NATS / JetStream text-and-header wire protocol client, Apache Kafka / Redpanda KIP-98 binary wire codec (RecordBatch v2 + CRC-32C Castagnoli), and deterministic in-memory broker (mq_streams, mq_streams/nats, mq_streams/kafka).
mq_streams provides wire-level messaging codecs and io/Stream clients for event-driven microservices and log pipelines:
mq_streams/nats:INFO, CONNECT, PUB, HPUB, SUB, UNSUB, MSG, HMSG, PING, PONG, +OK, -ERR).NATS/1.0 header serialization with JetStream status codes (100 FlowControl, 503 No Responders),hierarchical . subject wildcard matching (* single token and > tail match), and io/Stream client session (connect-stream, client-pub, client-hpub, client-sub, client-read-frame with automatic PING -> PONG keepalive).mq_streams/kafka:0x82F63B78) checksum, 4-byte TCP packet framing, and RequestHeader v2 / ResponseHeader codecs built over codec/wire and big-endian wire intrinsics.RecordBatch v2 (magic = 2) encoder and CRC-32C-verifying decoder supporting ZigZag signed-varint Record framing, per-record headers, nullable keys, producer IDs, and RFC 8878 Zstandard (attributes = 4) batch compression (compress/zstd).ProduceRequest, FetchRequest, FetchResponse, and decode-fetch-records wire codecs compatible with Apache Kafka and Redpanda.mq_streams:MemoryBroker combining NATS wildcard fan-out and queue-group round-robin load balancing with append-only CRC-32C-verified Kafka v2 partition logs for zero-network integration tests.veko pkg add mq_streams@1.0.0Import the modules in .vk source files:
use [
mq = mq_streams
nats = mq_streams/nats
kafka = mq_streams/kafka
]HPUB / HMSG Header FramingHeader-carrying NATS frames prefix the payload with a NATS/1.0 header block terminated by \r\n\r\n and declare both #header_bytes and #total_bytes on the control line:
HPUB orders.42.eu _INBOX.1 45 60\r\n
NATS/1.0\r\n
Nats-Msg-Id: ord-42\r\n
\r\n
{"amount":2500}\r\nRecordBatch v2 LayoutEach RecordBatch v2 begins with a 61-byte big-endian header:
| Byte Offset | Field | Type | Notes |
|---|---|---|---|
0..8 | baseOffset | int64 BE | First offset in batch |
8..12 | batchLength | int32 BE | Byte length of bytes 12..end |
12..16 | partitionLeaderEpoch | int32 BE | Broker leader epoch |
16 | magic | int8 | Always 2 for KIP-98 v2 |
17..21 | crc | uint32 BE | CRC-32C Castagnoli (0x82F63B78) over 21..end |
21..23 | attributes | int16 BE | Bits 0..2: 0 = none, 4 = Zstd |
23..27 | lastOffsetDelta | int32 BE | (len records) - 1 |
27..43 | baseTimestamp / maxTimestamp | 2 x int64 BE | Unix millisecond timestamps |
43..57 | producerId / epoch / seq | 8B + 2B + 4B | Idempotent producer metadata (-1 if unset) |
57..61 | recordsCount | int32 BE | Number of ZigZag-varint-framed Records |
mq_streams/natsNatsFrame, FrameDecodeStep, NatsClientsubject-match? [pattern str, subject str] boolencode-connect [opts map] bytes / encode-info [info map] bytesencode-ping [] bytes / encode-pong [] bytes / encode-ok [] bytes / encode-err [reason str] bytesencode-sub [subject str, sid str /queue qgroup str = ''] bytesencode-unsub [sid str /max max_msgs i64 = 0] bytesencode-pub [subject str, payload bytes /reply reply_to str = ''] bytesencode-hpub [subject str, headers map[str], payload bytes /reply reply_to str = ''] bytesencode-msg [subject str, sid str, payload bytes /reply reply_to str = ''] bytesencode-hmsg [subject str, sid str, headers map[str], payload bytes /reply reply_to str = '' /status code i64 = 0 /reason text str = ''] bytesdecode-frame-at [wire bytes, off i64] FrameDecodeStep / decode-frames [wire bytes] block[NatsFrame]connect-stream [mut stream io/Stream, connect_opts map] NatsClientclient-pub [mut client NatsClient, subject str, payload bytes /reply reply_to str = ''] i64client-hpub [mut client NatsClient, subject str, headers map[str], payload bytes /reply reply_to str = ''] i64client-sub [mut client NatsClient, subject str /queue qgroup str = ''] strclient-read-frame [mut client NatsClient /auto-pong pong bool = true] NatsFramemq_streams/kafkaAPI-PRODUCE, API-FETCH, API-LIST-OFFSETS, API-METADATA, API-API-VERSIONSRecordHeader, KafkaRecord, RecordBatch, RequestHeaderV2, ResponseHeadercrc32c [data bytes] i64frame-packet [payload bytes] bytes / unframe-packet [framed bytes] bytesencode-request-header-v2 [api_key i64, api_version i64, correlation_id i64, client_id str] bytesdecode-request-header-v2 [buf bytes, off i64] RequestHeaderV2encode-response-header [correlation_id i64] bytes / decode-response-header [buf bytes, off i64] ResponseHeaderencode-record-batch [base_offset i64, base_timestamp i64, records block[KafkaRecord] /zstd use_zstd bool = false /producer-id pid i64 = -1] bytesdecode-record-batch [wire bytes] RecordBatch / decode-record-batch-at [wire bytes, off i64] mapencode-produce-request [correlation_id i64, client_id str, topic str, partition i64, record_batch bytes /acks req_acks i64 = -1 /timeout timeout_ms i64 = 5000] bytesencode-fetch-request [correlation_id i64, client_id str, topic str, partition i64, fetch_offset i64 /max-wait max_wait_ms i64 = 500 /max-bytes max_bytes i64 = 1048576] bytesencode-fetch-response [correlation_id i64, topic str, partition i64, high_watermark i64, batches_wire bytes] bytesdecode-fetch-records [framed_resp bytes] block[KafkaRecord]mq_streamsnew-broker [] MemoryBrokersubscribe [mut b MemoryBroker, pattern str /queue qgroup str = ''] strunsubscribe [mut b MemoryBroker, sid str] boolpublish [mut b MemoryBroker, subject str, payload bytes /headers hdrs map[str] = {} /reply reply_to str = ''] i64drain-sub [mut b MemoryBroker, sid str] block[BrokerMsg]append-partition-batch [mut b MemoryBroker, topic str, partition i64, base_timestamp i64, records block[kafka/KafkaRecord] /zstd use_zstd bool = false] i64fetch-partition [b MemoryBroker, topic str, partition i64, min_offset i64] block[kafka/KafkaRecord]HPUB Framing & Subject Matchinguse [nats = mq_streams/nats]
wire = nats/encode-hpub 'orders.42.eu' { 'Nats-Msg-Id' = 'id-42' } (bytes/from-str 'payload')
frames = nats/decode-frames wire
if nats/subject-match? 'orders.*.eu' frames[0].subject [
print (map/get frames[0].headers 'Nats-Msg-Id')
]RecordBatch Encode, CRC-32C Verification & Decodeuse [kafka = mq_streams/kafka]
batch_bytes = kafka/encode-record-batch/zstd 100 1730000000000 [
kafka/KafkaRecord {
timestamp_ms = 1730000000050
key = bytes/from-str 'k1'
value = bytes/from-str 'v1'
headers = [ kafka/RecordHeader { key = 'source', value = (bytes/from-str 'edge') } ]
}
] true
batch = kafka/decode-record-batch batch_bytes
print batch.records[0].offsethttps://veko-lang.org/pkg/mq_streams/1.0.0.vkp013cee8cb3d7f7d1480ef8cd63115848facd02d37065e81d9291aa3e9ad1a4ebfb0f19baf8b32719a31d171e7727d7ee4e1223165e2523ca91268a0b059e6a09ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"mq_streams","version":"1.0.0","tier":2.0,"tier_label":"Tier 2: Distributed & Wire Protocols","category":"NATS & Kafka Wire Codecs","description":"Pure-Veko NATS Core/Headers wire protocol & wildcard subject matcher alongside Kafka RecordBatch v2 (CRC32C) & Produce/Fetch codecs.","modules":["mq_streams/kafka","mq_streams","mq_streams/nats"],"homepage":"https://veko-lang.org/packages/mq_streams"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 7 KB | c62465266fcb012269e762cf967fb35405167a2262fed77bb1a91ae92eb50f8f |
| examples/demo.vk | 7 KB | df1eeadbba0297e5cca19b73c03cd8ac7415174e19023aa93530b6de7e4f5e37 |
| kafka.vk | 19 KB | 33cd5c50f813ab6e5079d77571c21de16c88c50ca6c3b36b3b58e9dcbebd4364 |
| mod.vk | 5 KB | bec5422756574b1f45840e355f55268b04bcc07bad010633f8c89319888c9b8d |
| nats.vk | 18 KB | f3acf2d76e95c0366a3a61694540c145b82449c337095fa90252fb3cabd7e4f3 |