mongo_protocol

package module
v0.0.0-...-b669844 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

mongodb 二进制协议

Documentation

Index

Constants

View Source
const CStringEndByte = '\x00'

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyMsgSection

type BodyMsgSection struct {
	Kind byte
	Body bson.M
}

func NewBodyMsgSection

func NewBodyMsgSection() *BodyMsgSection

func (*BodyMsgSection) GetKind

func (b *BodyMsgSection) GetKind() byte

type ConnContext

type ConnContext struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewConnContext

func NewConnContext(conn net.Conn) *ConnContext

func (*ConnContext) Get

func (c *ConnContext) Get(key string) (value interface{}, ok bool)

func (*ConnContext) Set

func (c *ConnContext) Set(key string, value interface{})

type Delete

type Delete struct {

	// 0 - reserved for future use
	ZERO int32
	// "dbname.collectionname"
	FullCollectionName string
	// bit vector - see below for details.
	Flags int32
	// query object.  See below for details.
	Selector bson.M
	// contains filtered or unexported fields
}

func (*Delete) UnMarshal

func (d *Delete) UnMarshal(r *Reader) error

type DocumentSequenceMsgSection

type DocumentSequenceMsgSection struct {
	Kind                       byte
	Size                       int32
	DocumentSequenceIdentifier string
	DocumentSequences          []bson.M
}

func NewDocumentSequenceMsgSection

func NewDocumentSequenceMsgSection() *DocumentSequenceMsgSection

func (*DocumentSequenceMsgSection) GetKind

func (d *DocumentSequenceMsgSection) GetKind() byte

type GetMore

type GetMore struct {
	// 0 - reserved for future use
	ZERO int32
	// "dbname.collectionname"
	FullCollectionName string
	// number of documents to return
	NumberToReturn int32
	// cursorID from the OP_REPLY
	CursorID *int64
}

func (*GetMore) UnMarshal

func (g *GetMore) UnMarshal(r *Reader) error

type Handler

type Handler interface {
	Process(header *MsgHeader, r *Reader, conn *ConnContext) error
}

type Insert

type Insert struct {
	// standard message header
	Header MsgHeader
	// bit vector - see below
	Flags int32
	// "dbname.collectionname"
	FullCollectionName string
	// one or more documents to insert into the collection
	Documents []bson.M
}

func (*Insert) UnMarshal

func (i *Insert) UnMarshal(r *Reader) error

type KillCursors

type KillCursors struct {
	// standard message header
	Header MsgHeader
	// 0 - reserved for future use
	ZERO int32
	// number of cursorIDs in message
	NumberOfCursorIDs int32
	// sequence of cursorIDs to close
	CursorIDs []int64
}

func (*KillCursors) UnMarshal

func (k *KillCursors) UnMarshal(r *Reader) error

type Msg

type Msg struct {
	FlatBits uint32
	Sections []MsgSection
}

func (*Msg) GetBodyMsgSection

func (m *Msg) GetBodyMsgSection() bson.M

func (*Msg) UnMarshal

func (m *Msg) UnMarshal(r *Reader) error

type MsgHeader

type MsgHeader struct {
	MessageLength int32
	RequestID     int32
	ResponseTo    int32
	OpCode        OpCode
}

type MsgReply

type MsgReply struct {
	*Msg
	Header *MsgHeader
}

func NewMsgReply

func NewMsgReply(requestID int32) *MsgReply

func (*MsgReply) Write

func (m *MsgReply) Write(w io.Writer) error

type MsgSection

type MsgSection interface {
	GetKind() byte
}

type OpCode

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

type PrintHandler

type PrintHandler struct {
}

func (*PrintHandler) Process

func (d *PrintHandler) Process(header *MsgHeader, r *Reader, conn *ConnContext) error

type Query

type Query struct {
	// standard message header
	Header MsgHeader
	// bit vector of query options.  See below for details.
	Flags int32
	// "dbname.collectionname"
	FullCollectionName string
	// number of documents to skip
	NumberToSkip int32
	// number of documents to return
	NumberToReturn int32
	//  in the first OP_REPLY batch
	// query object.  See below for details.
	Query bson.M
	// Optional. Selector indicating the fields
	ReturnFieldsSelector bson.M
}

func (*Query) UnMarshal

func (q *Query) UnMarshal(r *Reader) error

type QueryHandler

type QueryHandler interface {
	Support(query *Query) bool
	Process(query *Query, reply *Reply) error
}

type Reader

type Reader struct {
	io.Reader
}

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(n int) ([]byte, error)

func (*Reader) ReadCString

func (r *Reader) ReadCString() (string, error)

func (*Reader) ReadDocument

func (r *Reader) ReadDocument() (m bson.M, e error)

func (*Reader) ReadDocuments

func (r *Reader) ReadDocuments() (ms []bson.M, e error)

func (*Reader) ReadInt32

func (r *Reader) ReadInt32() (n int32, err error)

func (*Reader) ReadInt64

func (r *Reader) ReadInt64() (*int64, error)

func (*Reader) ReadOne

func (r *Reader) ReadOne() ([]byte, error)

type Reply

type Reply struct {
	// standard message header
	Header *MsgHeader
	// bit vector - see details below
	ResponseFlags ResponseFlags
	// cursor id if client needs to do get more's
	CursorID int64
	// where in the cursor this reply is starting
	StartingFrom int32
	// number of documents in the reply
	NumberReturned int32
	// documents
	Documents interface{}
}

func NewErrorReply

func NewErrorReply(header *MsgHeader, msg string) *Reply

func NewReply

func NewReply(requestId int32) *Reply

func (*Reply) Write

func (r *Reply) Write(w io.Writer) error

1,计算header中字节大小 2,依次按照小端序写入w

type ResponseFlags

type ResponseFlags int32
const (
	CursorNotFound ResponseFlags = iota
	QueryFailure
	ShardConfigStale
	AwaitCapable
)

type Server

type Server struct {
	Port string
	// contains filtered or unexported fields
}

func NewServer

func NewServer(port string) *Server

func (*Server) AddHandler

func (server *Server) AddHandler(code OpCode, handler Handler)

func (*Server) GetHandler

func (server *Server) GetHandler(code OpCode) Handler

func (*Server) SetDefaultHandler

func (server *Server) SetDefaultHandler(handler Handler)

func (*Server) Start

func (server *Server) Start(ctx context.Context) error

type UnMarshaler

type UnMarshaler interface {
	UnMarshal(r *Reader) error
}

type Update

type Update struct {
	// standard message header
	Header MsgHeader
	// 0 - reserved for future use
	ZERO int32
	// "dbname.collectionname"
	FullCollectionName string
	// bit vector. see below
	Flags int32
	// the query to select the document
	Selector bson.M
	// specification of the update to perform
	Update bson.M
}

func (*Update) UnMarshal

func (u *Update) UnMarshal(r *Reader) error

type Writer

type Writer interface {
	Write(w io.Writer) error
}

Jump to

Keyboard shortcuts

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