mongowire

package
v0.0.0-...-79636ce Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OpMessageSectionBody             = 0
	OpMessageSectionDocumentSequence = 1
)
View Source
const MaxInt32 = 2147483647

Variables

This section is empty.

Functions

func NamespaceIsCommand

func NamespaceIsCommand(ns string) bool

func NamespaceToCollection

func NamespaceToCollection(ns string) string

func NamespaceToDB

func NamespaceToDB(ns string) string

func SendMessage

func SendMessage(ctx context.Context, m Message, writer io.Writer) error

Types

type CommandMessage

type CommandMessage struct {
	DB          string
	CmdName     string
	CommandArgs *birch.Document
	Metadata    *birch.Document
	InputDocs   []birch.Document
	// contains filtered or unexported fields
}

OP_COMMAND

func (*CommandMessage) HasResponse

func (m *CommandMessage) HasResponse() bool

func (*CommandMessage) Header

func (m *CommandMessage) Header() MessageHeader

func (*CommandMessage) Scope

func (m *CommandMessage) Scope() *OpScope

func (*CommandMessage) Serialize

func (m *CommandMessage) Serialize() []byte

type CommandReplyMessage

type CommandReplyMessage struct {
	CommandReply *birch.Document
	Metadata     *birch.Document
	OutputDocs   []birch.Document
	// contains filtered or unexported fields
}

OP_COMMAND_REPLY

func (*CommandReplyMessage) HasResponse

func (m *CommandReplyMessage) HasResponse() bool

func (*CommandReplyMessage) Header

func (m *CommandReplyMessage) Header() MessageHeader

func (*CommandReplyMessage) Scope

func (m *CommandReplyMessage) Scope() *OpScope

func (*CommandReplyMessage) Serialize

func (m *CommandReplyMessage) Serialize() []byte

type Message

type Message interface {
	Header() MessageHeader
	Serialize() []byte
	HasResponse() bool
	Scope() *OpScope
}

func NewCommand

func NewCommand(db, name string, args, metadata *birch.Document, inputs []birch.Document) Message

func NewCommandReply

func NewCommandReply(reply, metadata *birch.Document, output []birch.Document) Message

func NewDelete

func NewDelete(ns string, flags int32, filter *birch.Document) Message

func NewGetMore

func NewGetMore(ns string, number int32, cursorID int64) Message

func NewInsert

func NewInsert(ns string, docs ...*birch.Document) Message

func NewKillCursors

func NewKillCursors(ids ...int64) Message

func NewOpMessage

func NewOpMessage(moreToCome bool, documents []birch.Document, items ...model.SequenceItem) Message

func NewQuery

func NewQuery(ns string, flags, skip, toReturn int32, query, project *birch.Document) Message

func NewReply

func NewReply(cursorID int64, flags, startingFrom, numReturned int32, docs []birch.Document) Message

func NewUpdate

func NewUpdate(ns string, flags int32, filter, update *birch.Document) Message

func ReadMessage

func ReadMessage(ctx context.Context, reader io.Reader) (Message, error)

type MessageHeader

type MessageHeader struct {
	Size       int32 // total message size
	RequestID  int32
	ResponseTo int32
	OpCode     OpType
}

func (*MessageHeader) Parse

func (h *MessageHeader) Parse(body []byte) (Message, error)

func (*MessageHeader) WriteTo

func (h *MessageHeader) WriteTo(wr io.Writer)

type OpMessage

type OpMessage struct {
	Flags      uint32
	DB         string
	Collection string
	Operation  string
	Items      []OpMessageSection
	Checksum   int32
	// contains filtered or unexported fields
}

OP_MSG

func (*OpMessage) HasResponse

func (m *OpMessage) HasResponse() bool

func (*OpMessage) Header

func (m *OpMessage) Header() MessageHeader

func (*OpMessage) Scope

func (m *OpMessage) Scope() *OpScope

func (*OpMessage) Serialize

func (m *OpMessage) Serialize() []byte

type OpMessageSection

type OpMessageSection interface {
	Type() uint8
	Name() string
	DB() string
	Documents() []birch.Document
	Serialize() []byte
}

type OpScope

type OpScope struct {
	Type    OpType
	Context string
	Command string
	Payload *birch.Document
}

func (*OpScope) Validate

func (s *OpScope) Validate() error

type OpType

type OpType int32
const (
	OP_REPLY         OpType = 1
	OP_UPDATE        OpType = 2001
	OP_INSERT        OpType = 2002
	RESERVED         OpType = 2003
	OP_QUERY         OpType = 2004
	OP_GET_MORE      OpType = 2005
	OP_DELETE        OpType = 2006
	OP_KILL_CURSORS  OpType = 2007
	OP_COMMAND       OpType = 2010
	OP_COMMAND_REPLY OpType = 2011
	OP_MSG           OpType = 2013
)

func GetModel

func GetModel(msg Message) (any, OpType)

func (OpType) String

func (op OpType) String() string

type ReplyMessage

type ReplyMessage struct {
	Flags          int32
	CursorId       int64
	StartingFrom   int32
	NumberReturned int32

	Docs []birch.Document
	// contains filtered or unexported fields
}

OP_REPLY

func (*ReplyMessage) HasResponse

func (m *ReplyMessage) HasResponse() bool

because its a response

func (*ReplyMessage) Header

func (m *ReplyMessage) Header() MessageHeader

func (*ReplyMessage) Scope

func (m *ReplyMessage) Scope() *OpScope

func (*ReplyMessage) Serialize

func (m *ReplyMessage) Serialize() []byte

Jump to

Keyboard shortcuts

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