/** * {@inheritDoc} * * <p>Overridden to write the kill_cursors message. * * @see Message#write(int, BsonOutputStream) */ @Override public void write(final int messageId, final BsonOutputStream out) throws IOException { int size = HEADER_SIZE; size += 4; // 0 - reserved size += 4; // number of cursors. size += (8 * myCursorIds.length); writeHeader(out, messageId, 0, Operation.KILL_CURSORS, size); out.writeInt(0); out.writeInt(myCursorIds.length); for (final long myCursorId : myCursorIds) { out.writeLong(myCursorId); } }
/** * {@inheritDoc} * * <p>Overridden to write the insert message. * * @see Message#write(int, BsonOutputStream) */ @Override public void write(final int messageId, final BsonOutputStream out) throws IOException { final int flags = computeFlags(); int size = HEADER_SIZE; size += 4; // flags size += out.sizeOfCString(myDatabaseName, ".", myCollectionName); for (final Document document : myDocuments) { size += document.size(); } writeHeader(out, messageId, 0, Operation.INSERT, size); out.writeInt(flags); out.writeCString(myDatabaseName, ".", myCollectionName); for (final Document document : myDocuments) { out.writeDocument(document); } }