Documentation
¶
Index ¶
- Constants
- func AppendByte(dst []byte, val byte) []byte
- func AppendCString(dst []byte, val string) []byte
- func AppendDocument(dst []byte, doc bson.Document) []byte
- func AppendHeader(dst []byte, length, reqid, respto int32, opcode OpCode) []byte
- func AppendInt32(dst []byte, val int32) []byte
- func AppendInt64(dst []byte, val int64) []byte
- func ReadCString(src []byte) (string, []byte, bool)
- func ReadCursorIDs(src []byte, numIDs int32) (cursorIDs []int64, rem []byte, ok bool)
- func ReadDocument(src []byte) (bson.Document, []byte, bool)
- func ReadDocumentSequence(src []byte) (identifier string, docs []bsoncore.Document, rem []byte, ok bool)
- func ReadDocuments(src []byte) (docs []bson.Document, rem []byte, ok bool)
- func ReadInt32(src []byte) (int32, []byte, bool)
- func ReadInt64(src []byte) (int64, []byte, bool)
- func ReadUint32(src []byte) (uint32, []byte, bool)
- type Delete
- type Flag
- type GetMore
- type Header
- func (header *Header) Bytes() []byte
- func (header *Header) GetBodySize() int32
- func (header *Header) GetMessageLength() int32
- func (header *Header) GetOpCode() OpCode
- func (header *Header) GetRequestID() int32
- func (header *Header) GetResponseTo() int32
- func (header *Header) ParseBytes(msg []byte) error
- func (header *Header) SetMessageLength(l int32)
- func (header *Header) SetRequestID(id int32)
- func (header *Header) SetResponseTo(id int32)
- func (header *Header) String() string
- type Insert
- type KillCursors
- type Message
- type MessageListener
- type Msg
- func (op *Msg) AddDocument(docID string, doc bson.Document)
- func (op *Msg) AddDocuments(docIDs []string, docs []bson.Document)
- func (op *Msg) Bytes() []byte
- func (op *Msg) GetBody() bson.Document
- func (op *Msg) GetDocuments() []bson.Document
- func (op *Msg) SetBody(doc bson.Document)
- func (op *Msg) Size() int32
- func (op *Msg) String() string
- type MsgFlag
- type OpCode
- type Query
- type Reply
- type ReplyFlag
- type Request
- type Response
- type Section
- type SectionType
- type Update
Constants ¶
const ( // CursorNotFound sets when getMore is called but the cursor id is not valid at the server. Returned with zero results. CursorNotFound = 0x01 // QueryFailure sets when query failed. Results consist of one document containing an “$err” field describing the failure. QueryFailure = 0x02 // ShardConfigStale needs to update config from the server, and so drivers should ignore this. ShardConfigStale = 0x04 // AwaitCapable sets when the server supports the AwaitData Query option. If it doesn’t, a client should sleep a little between getMore’s of a Tailable cursor. Mongod version 1.6 supports AwaitData and thus always sets AwaitCapable. AwaitCapable = 0x08 )
const (
// HeaderSize is the static header size of MongoDB wire protocol.
HeaderSize = (4 + 4 + 4 + 4)
)
Variables ¶
This section is empty.
Functions ¶
func AppendByte ¶
AppendByte appends the byte to the buffer.
func AppendCString ¶
AppendCString appends the string value to the buffer.
func AppendDocument ¶
AppendDocument appends the document to the buffer.
func AppendHeader ¶
AppendHeader appends a header to dst.
func AppendInt32 ¶
AppendInt32 appends the int32 value to the buffer.
func AppendInt64 ¶
AppendInt64 appends the int64 value to the buffer.
func ReadCString ¶
ReadCString reads the cstring from src.
func ReadCursorIDs ¶
ReadCursorIDs reads numIDs cursor IDs from src.
func ReadDocument ¶
ReadDocument reads a single document from src.
func ReadDocumentSequence ¶
func ReadDocumentSequence(src []byte) (identifier string, docs []bsoncore.Document, rem []byte, ok bool)
ReadDocumentSequence reads an identifier and document sequence from src.
func ReadDocuments ¶
ReadDocuments reads as many documents as possible from src.
Types ¶
type Delete ¶
type Delete struct { *Header // A standard wire protocol header ZERO int32 // 0 - reserved for future use FullCollectionName string // "dbname.collectionname" Flags Flag // bit vector. see below Selector bson.Document // the query to select the document }
Delete represents a OP_DELETE of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewDeleteWithHeaderAndBody ¶
NewDeleteWithHeaderAndBody returns a new update instance with the specified bytes.
type Flag ¶
type Flag = wiremessage.MsgFlag
Flag represents a message flag of MongoDB wire protocol.
type GetMore ¶
type GetMore struct { *Header // A standard wire protocol header ZERO int32 // 0 - reserved for future use FullCollectionName string // "dbname.collectionname" NumberToReturn int32 // number of documents to return CursorID int64 // cursorID from the OP_REPLY }
GetMore represents a OP_GET_MORE of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewGetMoreWithHeaderAndBody ¶
NewGetMoreWithHeaderAndBody returns a new get more instance with the specified bytes.
type Header ¶
type Header struct { MessageLength int32 // total message size, including this RequestID int32 // identifier for this message ResponseTo int32 // requestID from the original request OpCode OpCode // request type }
Header represents a standard header of MongoDB wire protocol.
func NewHeaderWithBytes ¶
NewHeaderWithBytes returns a new header instance of the specified bytes.
func NewHeaderWithOpCode ¶
NewHeaderWithOpCode returns a new header instance with the specified opcode.
func (*Header) GetBodySize ¶
GetBodySize returns body size excluding header.
func (*Header) GetMessageLength ¶
GetMessageLength gets the message length.
func (*Header) GetRequestID ¶
GetRequestID gets the message identifier.
func (*Header) GetResponseTo ¶
GetResponseTo gets the response message identifier.
func (*Header) ParseBytes ¶
ParseBytes parses the specified bytes.
func (*Header) SetMessageLength ¶
SetMessageLength sets a message length.
func (*Header) SetRequestID ¶
SetRequestID sets a message identifier.
func (*Header) SetResponseTo ¶
SetResponseTo sets a response message identifier.
type Insert ¶
type Insert struct { *Header // A standard wire protocol header Flags Flag // bit vector. see below FullCollectionName string // "dbname.collectionname" Document bson.Document // one or more documents to insert into the collection }
Insert represents a OP_INSERT of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewInsertWithHeaderAndBody ¶
NewInsertWithHeaderAndBody returns a new insert instance with the specified bytes.
type KillCursors ¶
type KillCursors struct { *Header // A standard wire protocol header ZERO int32 // 0 - reserved for future use NumberOfCursorIDs int32 // number of documents to return CursorIDs []int64 // cursorID from the OP_REPLY }
KillCursors represents a OP_KILL_CURSORS of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewKillCursorsWithHeaderAndBody ¶
func NewKillCursorsWithHeaderAndBody(header *Header, body []byte) (*KillCursors, error)
NewKillCursorsWithHeaderAndBody returns a new get more instance with the specified bytes.
func (*KillCursors) Size ¶
func (op *KillCursors) Size() int32
Size returns the message size including the header.
func (*KillCursors) String ¶
func (op *KillCursors) String() string
String returns the string description.
type Message ¶
type Message interface { // SetRequestID sets a message identifier. SetRequestID(id int32) // SetResponseTo sets a response message identifier. SetResponseTo(id int32) // GetMessageLength returns the message length. GetMessageLength() int32 // GetRequestID returns the message identifier. GetRequestID() int32 // GetResponseTo returns the response message identifier. GetResponseTo() int32 // GetOpCode returns the operation code. GetOpCode() OpCode // Size returns the message size including the header. Size() int32 // Bytes returns the binary description of BSON format. Bytes() []byte // String returns the string description. String() string }
Message represents an operation message of MongoDB wire protocol.
func NewMessageWithBytes ¶
NewMessageWithBytes returns a parsed message of the specified bytes.
type MessageListener ¶
MessageListener represents a listener for MongoDB Wire Protocol.
type Msg ¶
type Msg struct { *Header // A standard wire protocol header FlagBits MsgFlag // message flags Body bson.Document // Body DocumentIDs []string Documents []bson.Document // Document Sequence Checksum uint32 // optional CRC-32C checksum }
Msg represents a OP_MSG of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewMsgWithBody ¶
NewMsgWithBody returns a new msg instance with the specified body document.
func NewMsgWithHeaderAndBody ¶
NewMsgWithHeaderAndBody returns a new update instance with the specified bytes.
func (*Msg) AddDocument ¶
AddDocument adds a document with the ID.
func (*Msg) AddDocuments ¶
AddDocuments adds documents with the IDs.
func (*Msg) GetDocuments ¶
GetDocuments returns the sequence documents.
type MsgFlag ¶
type MsgFlag = wiremessage.MsgFlag
MsgFlag represents a MsgFlag of MongoDB wire protocol.
type OpCode ¶
type OpCode = wiremessage.OpCode
OpCode represents a MongoDB wire protocol opcode.
const ( // OpReply (OP_REPLY) replies to a client request. responseTo is set. OpReply OpCode = wiremessage.OpReply // OpUpdate (OP_UPDATE:2001) updates document. OpUpdate OpCode = wiremessage.OpUpdate // OpInsert (OP_INSERT:2002) inserts new document. OpInsert OpCode = wiremessage.OpInsert // OpQuery (OP_QUERY:2004) queries a collection. OpQuery OpCode = wiremessage.OpQuery // OpGetMore (GET_MORE:2005) gets more data from a query. See Cursors. OpGetMore OpCode = wiremessage.OpGetMore // OpDelete (OP_DELETE:2006) Deletes documents. OpDelete OpCode = wiremessage.OpDelete // OpKillCursors (OP_KILL_CURSORS:2007)Notifies database that the client has finished with the cursor. OpKillCursors OpCode = wiremessage.OpKillCursors // OpCommand (OP_COMMAND:2011) clusters internal protocol representing a command request. OpCommand OpCode = wiremessage.OpCommand // OpCommandReply (OP_COMMANDREPLY:2011) clusters internal protocol representing a reply to an OP_COMMAND. OpCommandReply OpCode = wiremessage.OpCommandReply // OpMsg (OP_MSG:2013) sends a message using the format introduced in MongoDB 3.6. OpMsg OpCode = wiremessage.OpMsg )
type Query ¶
type Query struct { *Header // A standard wire protocol header Flags Flag // bit vector. see below FullCollectionName string // "dbname.collectionname" NumberToSkip int32 // number of documents to skip NumberToReturn int32 // number of documents to return in the first OP_REPLY batch Query bson.Document // query object. See below for details. }
Query represents a OP_QUERY of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewQueryWithHeaderAndBody ¶
NewQueryWithHeaderAndBody returns a new insert instance with the specified bytes.
func (*Query) GetCollectionName ¶
GetCollectionName returns the query collection name.
func (*Query) IsCollection ¶
IsCollection returns true when the specified name equals the full collection name, otherwise false.
type Reply ¶
type Reply struct { *Header // A standard wire protocol header ReplyFlags ReplyFlag // bit vector - see details below CursorID int64 // cursor id if client needs to do get more's StartingFrom int32 // where in the cursor this reply is starting NumberReturned int32 // number of documents in the reply Documents []bson.Document // documents }
Reply represents a OP_REPLY of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewReplyWithDocument ¶
NewReplyWithDocument returns a new reply instance with ths specified document.
func NewReplyWithDocuments ¶
NewReplyWithDocuments returns a new reply instance with ths specified documents.
func NewReplyWithHeaderAndBody ¶
NewReplyWithHeaderAndBody returns a new reply instance with the specified bytes.
func (*Reply) SetResponseFlags ¶
SetResponseFlags sets a response flag.
type ReplyFlag ¶
type ReplyFlag = wiremessage.ReplyFlag
ReplyFlag represents a MsgFReplyFlaglag of MongoDB wire protocol.
type Request ¶
type Request interface {
GetCode() OpCode
}
Request represents a request operation of MongoDB wire protocol.
type Response ¶
type Response interface {
GetCode() OpCode
}
Response represents a response operation of MongoDB wire protocol.
type SectionType ¶
type SectionType = wiremessage.SectionType
SectionType represents a SectionType of MongoDB wire protocol.
func ReadSectionType ¶
func ReadSectionType(src []byte) (stype SectionType, rem []byte, ok bool)
ReadSectionType reads the section type from src.
type Update ¶
type Update struct { *Header // A standard wire protocol header ZERO int32 // 0 - reserved for future use FullCollectionName string // "dbname.collectionname" Flags Flag // bit vector. see below Selector bson.Document // the query to select the document Update bson.Document // specification of the update to perform }
Update represents a OP_UPDATE of MongoDB wire protocol. See : MongoDB Wire Protocol https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
func NewUpdateWithHeaderAndBody ¶
NewUpdateWithHeaderAndBody returns a new update instance with the specified bytes.