/* * struct { * MsgHeader header; // standard message header * int32 responseFlags; // bit vector - see details below * int64 cursorID; // cursor id if client needs to do get more's * int32 startingFrom; // where in the cursor this reply is starting * int32 numberReturned; // number of documents in the reply * document* documents; // documents * } */ /// <summary> /// Reads OP_REPLY but does not interpret it /// </summary> public static ReplyData Read_REPLY(Stream stream) { stream.Position = sizeof(Int32); //skip Total size var hdrReqID = BinUtils.ReadInt32(stream); var hdrRespTo = BinUtils.ReadInt32(stream); var hdrOpCode = BinUtils.ReadInt32(stream); if (hdrOpCode != OP_REPLY) { throw new MongoDbConnectorProtocolException(StringConsts.PROTO_READ_OP_REPLY_ERROR + " not OP_REPLY"); } var flags = (ResponseFlags)BinUtils.ReadInt32(stream); var cursorID = BinUtils.ReadInt64(stream); var startingFrom = BinUtils.ReadInt32(stream); var numReturned = BinUtils.ReadInt32(stream); if (numReturned > MAX_DOC_COUNT_LIMIT) { throw new MongoDbConnectorProtocolException(StringConsts.PROTO_REPLY_DOC_COUNT_EXCEED_LIMIT_ERROR.Args(numReturned, MAX_DOC_COUNT_LIMIT)); } var docs = new BSONDocument[numReturned]; for (var i = 0; i < numReturned; i++) { docs[i] = new BSONDocument(stream); } return(new ReplyData(hdrReqID, hdrRespTo, flags, cursorID, startingFrom, docs)); }
private Stream readSocket() { var nets = m_TcpClient.GetStream(); var total = BinUtils.ReadInt32(nets); if (total >= Protocol.BSON_SIZE_LIMIT) { throw new MongoDBConnectorProtocolException(StringConsts.PROTO_SOCKET_READ_EXCEED_LIMIT_ERROR.Args(total, Protocol.BSON_SIZE_LIMIT)); } var leftToRead = total - sizeof(Int32); //the total size includes the 4 bytes m_BufferStream.SetLength(total); var buffer = m_BufferStream.GetBuffer(); BinUtils.WriteInt32(buffer, total, 0); socketRead(nets, buffer, sizeof(Int32), leftToRead); m_Received.BindBuffer(buffer, 0, total); return(m_Received); //todo stats }