zap

package
v1.24.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package zap provides a ZAP binary protocol listener for DocumentDB.

This allows clients to communicate using the ZAP zero-copy protocol instead of MongoDB wire protocol. ZAP messages are translated to the same internal handler operations — find, insert, update, delete, aggregate — that MongoDB wire protocol uses.

The key insight: DocumentDB stores data in PostgreSQL (hanzo/sql). With native ZAP, the path is ZAP→DocumentDB→ZAP→PostgreSQL. Wire format stays binary end-to-end; only the semantic translation (MongoDB query language → SQL) happens in between.

Index

Constants

View Source
const MsgTypeDocumentDB uint16 = 303

ZAP message type for DocumentDB operations.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Port to listen on (default 9654).
	Port int

	// ServiceType for mDNS discovery (default "_hanzo-documentdb._tcp").
	ServiceType string

	// NodeID for ZAP peer identification.
	NodeID string

	// Enabled controls whether the ZAP listener starts.
	Enabled bool
}

Config for the ZAP transport.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler translates ZAP messages into DocumentDB operations. It bridges "mongo-thinking" ZAP clients to PostgreSQL storage.

func NewHandler

func NewHandler(pool *documentdb.Pool, logger *slog.Logger) *Handler

NewHandler creates a ZAP message handler backed by a DocumentDB pool.

func (*Handler) HandleMessage

func (h *Handler) HandleMessage(ctx context.Context, from string, msg *zaplib.Message) (*zaplib.Message, error)

HandleMessage is the main ZAP message handler for DocumentDB operations. It dispatches based on the path field in the ZAP message:

  • /find → MongoDB-style find (filter, projection, sort, limit)
  • /insert → Insert documents
  • /update → Update documents (filter + update operators)
  • /delete → Delete documents (filter)
  • /aggregate → Aggregation pipeline
  • /count → Count documents matching filter

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener manages a ZAP node that accepts binary protocol connections and routes them to DocumentDB's internal handler layer.

Architecture:

ZAP Client (mongo-thinking)
  │ ZAP binary (:9654)
  ▼
DocumentDB Listener (this)
  │ translates mongo semantics → SQL
  │ via documentdb_api PostgreSQL extension
  ▼
hanzo/sql (PostgreSQL :9999)
  ZAP binary — end-to-end, no JSON, no wire protocol translation

func NewListener

func NewListener(pool *documentdb.Pool, logger *slog.Logger) *Listener

NewListener creates a ZAP listener for DocumentDB.

func NewListenerWithConfig

func NewListenerWithConfig(pool *documentdb.Pool, logger *slog.Logger, config Config) *Listener

NewListenerWithConfig creates a ZAP listener with custom configuration.

func (*Listener) Start

func (l *Listener) Start() error

Start begins listening for ZAP connections.

func (*Listener) Stop

func (l *Listener) Stop()

Stop gracefully shuts down the ZAP listener.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL