protocol

package
v0.0.0-...-2925d70 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpReplyCode       = OpCode(1)
	OpMessageCode     = OpCode(1000)
	OpUpdateCode      = OpCode(2001)
	OpInsertCode      = OpCode(2002)
	Reserved          = OpCode(2003)
	OpQueryCode       = OpCode(2004)
	OpGetMoreCode     = OpCode(2005)
	OpDeleteCode      = OpCode(2006)
	OpKillCursorsCode = OpCode(2007)
)

The full set of known request op codes: http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#request-opcodes

View Source
const HeaderLen = 16

Variables

This section is empty.

Functions

func CopyMessage

func CopyMessage(w io.Writer, r io.Reader) error

copyMessage copies reads & writes an entire message.

Types

type CSString

type CSString []byte

func (CSString) String

func (s CSString) String() string

type Document

type Document []byte

func (Document) String

func (s Document) String() string

func (Document) ToBSON

func (s Document) ToBSON() (bson.D, error)

type Message

type Message interface {
	WriteTo(w io.Writer) error
	GetOpCode() OpCode
	GetMsgHeader() *MsgHeader
	String() string
}

type MsgHeader

type MsgHeader struct {
	// MessageLength is the total message size, including this header
	MessageLength int32
	// RequestID is the identifier for this message
	RequestID int32
	// ResponseTo is the RequestID of the message being responded to. used in DB responses
	ResponseTo int32
	// OpCode is the request type, see consts above.
	OpCode OpCode
	// Message raw content
	Message []byte
}

MsgHeader is the mongo MsgHeader

func ReadMsgHeader

func ReadMsgHeader(r io.Reader) (*MsgHeader, error)

func (*MsgHeader) GetMsgHeader

func (m *MsgHeader) GetMsgHeader() *MsgHeader

func (*MsgHeader) GetOpCode

func (m *MsgHeader) GetOpCode() OpCode

func (*MsgHeader) String

func (m *MsgHeader) String() string

String returns a string representation of the message header.

func (*MsgHeader) WriteTo

func (m *MsgHeader) WriteTo(w io.Writer) error

type OpCode

type OpCode int32

OpCode allow identifying the type of operation:

http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#request-opcodes

func (OpCode) HasResponse

func (c OpCode) HasResponse() bool

HasResponse tells us if the operation will have a response from the server.

func (OpCode) IsMutation

func (c OpCode) IsMutation() bool

IsMutation tells us if the operation will mutate data. These operations can be followed up by a getLastErr operation.

func (OpCode) String

func (c OpCode) String() string

String returns a human readable representation of the OpCode.

type OpQuery

type OpQuery struct {
	// MsgHeader standard message header
	MsgHeader *MsgHeader
	// Flags bit vector of query options.
	Flags int32
	// FullCollectionName "dbname.collectionname"
	FullCollectionName CSString
	// number of documents to skip
	NumberToSkip int32
	// number of documents to return
	NumberToReturn int32
	//  in the first OP_REPLY batch
	Query Document
	// Optional. Selector indicating the fields
	ReturnFieldsSelector Document
}

MsgHeader is the mongo MsgHeader

func ReadOpQuery

func ReadOpQuery(h *MsgHeader, r io.Reader) (*OpQuery, error)

func (*OpQuery) GetMsgHeader

func (op *OpQuery) GetMsgHeader() *MsgHeader

func (*OpQuery) GetOpCode

func (op *OpQuery) GetOpCode() OpCode

func (*OpQuery) String

func (op *OpQuery) String() string

String returns a string representation of the message header.

func (*OpQuery) WriteTo

func (op *OpQuery) WriteTo(w io.Writer) error

type OpReply

type OpReply struct {
	// MsgHeader standard message header
	MsgHeader *MsgHeader
	// ResponseFlags bit vector.
	ResponseFlags int32
	// CursorID cursor id if client needs to do get more's
	CursorID int64
	// StartingFrom where in the cursor this reply is starting
	StartingFrom int32
	// NumberReturned number of documents in the reply
	NumberReturned int32
	// Documents
	Documents []Document
}

MsgHeader is the mongo MsgHeader

func NewOpReplay

func NewOpReplay(req Message, requestID int32) *OpReply

func ReadOpReply

func ReadOpReply(h *MsgHeader, r io.Reader) (*OpReply, error)

func (*OpReply) AddDocument

func (op *OpReply) AddDocument(d interface{}) error

func (*OpReply) GetOpCode

func (op *OpReply) GetOpCode() OpCode

func (*OpReply) String

func (op *OpReply) String() string

String returns a string representation of the message header.

func (*OpReply) WriteTo

func (op *OpReply) WriteTo(w io.Writer) error

type WriteError

type WriteError struct {
	Index   int32
	Code    int32
	Message string `bson:"errmsg"`
}

type WriteResult

type WriteResult struct {
	Result        int32        `bson:"ok"`
	InsertedCount int32        `bson:"n"`
	WriteErrors   []WriteError `bson:"writeErrors"`
}

Jump to

Keyboard shortcuts

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