Dart Documentationmongo_dartMongoInsertMessage

MongoInsertMessage class

class MongoInsertMessage extends MongoMessage{
 BsonCString _collectionFullName;
 int flags;
 List<BsonMap> _documents;
 MongoInsertMessage(String collectionFullName,
           List<Map> documents,
           [this.flags = 0]
           ){
   _collectionFullName = new BsonCString(collectionFullName);
   _documents = new List();
   for (var document in documents){
     _documents.add(new BsonMap(document));
   }
   opcode = MongoMessage.Insert;
 }
 int get messageLength{
   int docsSize = 0;
   for (var _doc in _documents){
     docsSize += _doc.byteLength();
   }
   int result = 16+4+_collectionFullName.byteLength()+docsSize;
   return result;
 }
 BsonBinary serialize(){
   BsonBinary buffer = new BsonBinary(messageLength);
   writeMessageHeaderTo(buffer);
   buffer.writeInt(flags);
   _collectionFullName.packValue(buffer);
   for (var _doc in _documents){
     _doc.packValue(buffer);
   }
   buffer.offset = 0;
   return buffer;
 }
 String toString(){
   if (_documents.length == 1) {
     return "MongoInserMessage($requestId, ${_collectionFullName.value}, ${_documents[0].value})";
   }
   return "MongoInserMessage($requestId, ${_collectionFullName.value}, ${_documents.length} documents)";
 }

}

Extends

MongoMessage > MongoInsertMessage

Constructors

new MongoInsertMessage(String collectionFullName, List<Map> documents, [int flags = 0]) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
MongoInsertMessage(String collectionFullName,
         List<Map> documents,
         [this.flags = 0]
         ){
 _collectionFullName = new BsonCString(collectionFullName);
 _documents = new List();
 for (var document in documents){
   _documents.add(new BsonMap(document));
 }
 opcode = MongoMessage.Insert;
}

Properties

int flags #

int flags

final int messageLength #

int get messageLength{
 int docsSize = 0;
 for (var _doc in _documents){
   docsSize += _doc.byteLength();
 }
 int result = 16+4+_collectionFullName.byteLength()+docsSize;
 return result;
}

int opcode #

inherited from MongoMessage
int opcode = MongoMessage.Reply

final int requestId #

inherited from MongoMessage
int get requestId{
 if (_requestId == null){
   _requestId = _Statics.nextRequestId;
 }
 return _requestId;
}

int responseTo #

inherited from MongoMessage
int responseTo

Methods

MongoMessage deserialize(BsonBinary buffer) #

inherited from MongoMessage
MongoMessage deserialize(BsonBinary buffer){
 throw new MongoDartError('Must be implemented');
}

dynamic readMessageHeaderFrom(BsonBinary buffer) #

inherited from MongoMessage
readMessageHeaderFrom(BsonBinary buffer)
{
   _messageLength = buffer.readInt32();
   _requestId = buffer.readInt32();
   responseTo = buffer.readInt32();
   int opcodeFromWire = buffer.readInt32();
   if (opcodeFromWire != opcode)
   {
       throw new MongoDartError('Expected $opcode in Message header. Got $opcodeFromWire');
   }
}

BsonBinary serialize() #

BsonBinary serialize(){
 BsonBinary buffer = new BsonBinary(messageLength);
 writeMessageHeaderTo(buffer);
 buffer.writeInt(flags);
 _collectionFullName.packValue(buffer);
 for (var _doc in _documents){
   _doc.packValue(buffer);
 }
 buffer.offset = 0;
 return buffer;
}

String toString() #

Returns a string representation of this object.

docs inherited from Object
String toString(){
 if (_documents.length == 1) {
   return "MongoInserMessage($requestId, ${_collectionFullName.value}, ${_documents[0].value})";
 }
 return "MongoInserMessage($requestId, ${_collectionFullName.value}, ${_documents.length} documents)";
}

dynamic writeMessageHeaderTo(BsonBinary buffer) #

inherited from MongoMessage
writeMessageHeaderTo(BsonBinary buffer)
{
   buffer.writeInt(messageLength); // messageLength will be backpatched later
   buffer.writeInt(requestId);
   buffer.writeInt(0); // responseTo not used in requests sent by client
   buffer.writeInt(opcode);
   if (messageLength < 0){
     throw new MongoDartError('Error in message length');
   }
}