src/anonimongo/core/wire

Source   Edit  

Types

CompressorId {.size: 1.} = enum
  cidNoop = (0, "noop"), cidSnappy = "snappy", cidZlib = "zlib",
  cidZstd = "zstd"
Compression ID which will be used as indicattor what kind of compression used when sending the message. Source   Edit  
Flags {.size: 4, pure.} = enum
  Reserved, TailableCursor, SlaveOk, OplogReplay, ## mongodb internal use only, don't set
  NoCursorTimeout,          ## disable cursor timeout, default timeout 10 minutes
  AwaitData,                ## used with tailable cursor
  Exhaust, Partial           ## get partial data instead of error when some shards are down
Bitfield used when query the mongo command. Source   Edit  
MsgBitFlags {.size: 4, pure.} = enum
  ChecksumPresent, MoreToCome, ExhaustAllowed = 16
The OP_MESSAGE bit flag definition Source   Edit  
MsgFlags = set[MsgBitFlags]
The actual bitfield value for message flags. Source   Edit  
MsgHeader = object
  messageLength*, requestId*, responseTo*, opCode*: int32
An object that will spearhead any exchanges of Bson data. Source   Edit  
OpCode = enum
  opReply = 1, opUpdate = 2001, opInsert, opReserved, opQuery, opGetMore,
  opDelete, opKillCursors, opCommand = 2010, opCommandReply, opCompressed,
  opMsg = 2013
Wire protocol OP_CODE. Source   Edit  
QueryFlags = set[Flags]
Flags itself that holds which bit flags available. Source   Edit  
ReplyFormat = object
  responseFlags*: int32
  cursorId*: int64
  startingFrom*: int32
  numberReturned*: int32
  documents*: seq[BsonDocument]
Object that actually holds the values from Bson data. Source   Edit  
ResponseFlags = set[RFlags]
The actual available ResponseFlags. Source   Edit  
RFlags {.size: 4, pure.} = enum
  CursorNotFound, QueryFailure, ShardConfigStale, AwaitCapable
RFlags is bitfield flag for ReplyFormat.responseFlags Source   Edit  

Procs

proc code(b: BsonDocument): int {....raises: [ValueError, Exception, KeyError],
                                  tags: [RootEffect], forbids: [].}
Fetch (error?) code from BsonDocument. Source   Edit  
proc errmsg(b: BsonDocument): string {....raises: [ValueError, Exception, KeyError],
                                       tags: [RootEffect], forbids: [].}
Helper to fetch error message from BsonDocument. Source   Edit  
proc getReply(socket: AsyncSocket): Future[ReplyFormat] {....gcsafe,
    stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, ReadIOEffect], forbids: [].}
Get data from socket and apply the replyParse into the result. Source   Edit  
proc getReply(socket: Socket): ReplyFormat {....gcsafe, raises: [TimeoutError,
    OSError, SslError, IOError, Exception, SnappyError, ZippyError],
    tags: [ReadIOEffect, TimeEffect, RootEffect], forbids: [].}
Get data from socket and apply the replyParse into the result. Source   Edit  
proc look(reply: ReplyFormat) {....raises: [ValueError, Exception, KeyError],
                                tags: [RootEffect], forbids: [].}
Helper for easier debugging and checking the returned ReplyFormat. Source   Edit  
proc msgParse(s: var Streamable; rest = 0): ReplyFormat {....gcsafe.}
Get the message in the ReplyFormat from given data stream. This is adapted to older type ReplyFormat from newer wire protocol OP_MSG. Source   Edit  
proc ok(b: BsonDocument): bool {....raises: [KeyError, ValueError, Exception],
                                 tags: [RootEffect], forbids: [].}
Check whether BsonDocument is ok. Source   Edit  
proc prepareQuery(s: var Streamable; reqId, target, opcode, flags: int32;
                  collname: string; nskip, nreturn: int32; query = newBson();
                  selector = newBson(); compression = cidNoop): int {....gcsafe.}
Convert and encode the query into stream to be ready for sending onto TCP wire socket. Source   Edit  
proc replyParse(s: var Streamable): ReplyFormat
Get the ReplyFormat from given data stream. Source   Edit  

Templates

template check(r: ReplyFormat): (bool, string)
Utility that will check whether the ReplyFormat is successful failed and return it as tuple of bool and string. Source   Edit  
template prepare(q: BsonDocument; flags: int32; dbname: string; id = 0;
                 skip = 0; limit = 1; compression = cidNoop): untyped
Source   Edit