wire

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderLen               = 16
	DefaultMaxMessageLength = 48_000_000
)
View Source
const (
	MsgSectionBody             byte = 0
	MsgSectionDocumentSequence byte = 1
)

Variables

View Source
var (
	ErrMessageTooShort = errors.New("mongo wire: message too short")
	ErrMessageTooLarge = errors.New("mongo wire: message too large")
	ErrMalformed       = errors.New("mongo wire: malformed message")
	ErrUnsupported     = errors.New("mongo wire: unsupported message")
)

Functions

func AppendHeader

func AppendHeader(dst []byte, h Header) []byte

func AppendMessage

func AppendMessage(dst []byte, requestID, responseTo int32, opCode OpCode, body []byte) ([]byte, error)

func AppendMsgBody

func AppendMsgBody(dst []byte, flags MsgFlag, doc Document) ([]byte, error)

func AppendMsgBodyWithSequences

func AppendMsgBodyWithSequences(dst []byte, flags MsgFlag, doc Document, sequences []DocumentSequence) ([]byte, error)

func AppendMsgMessage

func AppendMsgMessage(dst []byte, requestID, responseTo int32, flags MsgFlag, doc Document) ([]byte, error)

func AppendMsgMessageWithSequences

func AppendMsgMessageWithSequences(dst []byte, requestID, responseTo int32, flags MsgFlag, doc Document, sequences []DocumentSequence) ([]byte, error)

func AppendQueryBody

func AppendQueryBody(dst []byte, flags int32, fullCollectionName string, numberToSkip, numberToReturn int32, query Document, returnFieldsSelector Document) ([]byte, error)

func AppendQueryMessage

func AppendQueryMessage(dst []byte, requestID, responseTo int32, flags int32, fullCollectionName string, numberToSkip, numberToReturn int32, query Document, returnFieldsSelector Document) ([]byte, error)

func AppendReplyBody

func AppendReplyBody(dst []byte, responseFlags int32, cursorID int64, startingFrom int32, docs ...Document) ([]byte, error)

func AppendReplyMessage

func AppendReplyMessage(dst []byte, requestID, responseTo int32, responseFlags int32, cursorID int64, startingFrom int32, docs ...Document) ([]byte, error)

func CommandName

func CommandName(doc Document) (string, error)

func CommandNameFromValidatedDocument

func CommandNameFromValidatedDocument(doc Document) (string, error)

CommandNameFromValidatedDocument extracts the command name from a document that has already passed ValidateDocument, such as a ParseMsg or ParseQuery result.

func ValidateDocument

func ValidateDocument(doc Document) error

Types

type Document

type Document = bson.Raw

type DocumentSequence

type DocumentSequence struct {
	Identifier string
	Documents  []Document
}
type Header struct {
	MessageLength int32
	RequestID     int32
	ResponseTo    int32
	OpCode        OpCode
}

func ParseHeader

func ParseHeader(src []byte) (Header, error)

func ReadMessage

func ReadMessage(r io.Reader, maxMessageLength int32) (Header, []byte, error)

func ReadMessageInto

func ReadMessageInto(r io.Reader, dst []byte, maxMessageLength int32) (Header, []byte, error)

ReadMessageInto reads one wire message and uses dst as reusable storage for the returned body when dst has enough capacity. Callers that pass a reusable dst must treat the returned body as borrowed: it may alias dst and remains valid only until dst is reused or modified. Clone the body before retaining it across subsequent reads.

type Msg

type Msg struct {
	Flags     MsgFlag
	Body      Document
	Sequences []DocumentSequence
}

func ParseMsg

func ParseMsg(body []byte) (Msg, error)

type MsgFlag

type MsgFlag uint32
const (
	MsgFlagChecksumPresent MsgFlag = 1 << 0
	MsgFlagMoreToCome      MsgFlag = 1 << 1
	MsgFlagExhaustAllowed  MsgFlag = 1 << 16
)

type OpCode

type OpCode int32
const (
	OpReply      OpCode = 1
	OpUpdate     OpCode = 2001
	OpInsert     OpCode = 2002
	OpQuery      OpCode = 2004
	OpGetMore    OpCode = 2005
	OpDelete     OpCode = 2006
	OpKillCursor OpCode = 2007
	OpCompressed OpCode = 2012
	OpMsg        OpCode = 2013
)

type Query

type Query struct {
	Flags                int32
	FullCollectionName   string
	NumberToSkip         int32
	NumberToReturn       int32
	Query                Document
	ReturnFieldsSelector Document
}

func ParseQuery

func ParseQuery(body []byte) (Query, error)

type Reply

type Reply struct {
	ResponseFlags int32
	CursorID      int64
	StartingFrom  int32
	Documents     []Document
}

func ParseReply

func ParseReply(body []byte) (Reply, error)

Jump to

Keyboard shortcuts

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