private void writeKillCursorsPrologue(final int numCursors, final BsonOutput bsonOutput) { bsonOutput.writeInt32(0); // reserved bsonOutput.writeInt32(numCursors); } }
/** * Writes the message prologue to the given output. * * @param bsonOutput the output */ protected void writeMessagePrologue(final BsonOutput bsonOutput) { bsonOutput.writeInt32(0); // length: will set this later bsonOutput.writeInt32(id); bsonOutput.writeInt32(0); // response to bsonOutput.writeInt32(opCode.getValue()); }
/** * Write the query prologue to the given BSON output. * * @param bsonOutput the BSON output */ protected void writeQueryPrologue(final BsonOutput bsonOutput) { bsonOutput.writeInt32(getCursorFlag()); bsonOutput.writeCString(getCollectionName()); bsonOutput.writeInt32(skip); bsonOutput.writeInt32(numberToReturn); } }
private void writeGetMore(final BsonOutput buffer) { buffer.writeInt32(0); buffer.writeCString(getCollectionName()); buffer.writeInt32(numberToReturn); buffer.writeInt64(cursorId); }
/** * Backpatches the message length into the beginning of the message. * * @param startPosition the start position of the message * @param bsonOutput the output */ protected void backpatchMessageLength(final int startPosition, final BsonOutput bsonOutput) { int messageLength = bsonOutput.getPosition() - startPosition; bsonOutput.writeInt32(bsonOutput.getPosition() - messageLength, messageLength); }
private void writeInsertPrologue(final BsonOutput outputStream) { outputStream.writeInt32(0); // flags outputStream.writeCString(getCollectionName()); } }
@Override protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput) { bsonOutput.writeInt32(0); // reserved bsonOutput.writeCString(getCollectionName()); if (deleteRequest.isMulti()) { bsonOutput.writeInt32(0); } else { bsonOutput.writeInt32(1); } int firstDocumentStartPosition = bsonOutput.getPosition(); addDocument(deleteRequest.getFilter(), bsonOutput, new NoOpFieldNameValidator()); return new EncodingMetadata(firstDocumentStartPosition); } }
@Override protected void doWriteInt32(final int value) { bsonOutput.writeByte(BsonType.INT32.getValue()); writeCurrentName(); bsonOutput.writeInt32(value); }
private void backpatchSize() { int size = bsonOutput.getPosition() - getContext().startPosition; validateSize(size); bsonOutput.writeInt32(bsonOutput.getPosition() - size, size); }
@Override protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput, final SessionContext sessionContext) { bsonOutput.writeInt32(wrappedOpcode.getValue()); bsonOutput.writeInt32(getWrappedMessageSize(wrappedMessageBuffers) - MESSAGE_HEADER_LENGTH); bsonOutput.writeByte(compressor.getId()); getFirstWrappedMessageBuffer(wrappedMessageBuffers) .position(getFirstWrappedMessageBuffer(wrappedMessageBuffers).position() + MESSAGE_HEADER_LENGTH); compressor.compress(wrappedMessageBuffers, bsonOutput); return new EncodingMetadata(0); }
if (useOpMsg()) { int flagPosition = bsonOutput.getPosition(); bsonOutput.writeInt32(0); // flag bits bsonOutput.writeByte(0); // payload type commandStartPosition = bsonOutput.getPosition(); bsonOutput.writeByte(1); // payload type int payloadBsonOutputStartPosition = bsonOutput.getPosition(); bsonOutput.writeInt32(0); // size bsonOutput.writeCString(payload.getPayloadName()); writePayload(new BsonBinaryWriter(bsonOutput, payloadFieldNameValidator), bsonOutput, getSettings(), bsonOutput.writeInt32(payloadBsonOutputStartPosition, payloadBsonOutputLength); bsonOutput.writeInt32(flagPosition, getOpMsgFlagBits()); } else { bsonOutput.writeInt32(getOpQueryFlagBits()); bsonOutput.writeCString(namespace.getFullName()); bsonOutput.writeInt32(0); bsonOutput.writeInt32(-1);
@Override protected void doWriteBinaryData(final BsonBinary value) { bsonOutput.writeByte(BsonType.BINARY.getValue()); writeCurrentName(); int totalLen = value.getData().length; if (value.getType() == BsonBinarySubType.OLD_BINARY.getValue()) { totalLen += 4; } bsonOutput.writeInt32(totalLen); bsonOutput.writeByte(value.getType()); if (value.getType() == BsonBinarySubType.OLD_BINARY.getValue()) { bsonOutput.writeInt32(totalLen - 4); } bsonOutput.writeBytes(value.getData()); }
@Override protected void doWriteStartArray() { bsonOutput.writeByte(BsonType.ARRAY.getValue()); writeCurrentName(); setContext(new Context(getContext(), BsonContextType.ARRAY, bsonOutput.getPosition())); bsonOutput.writeInt32(0); // reserve space for size }
@Override protected void doWriteStartDocument() { if (getState() == State.VALUE) { bsonOutput.writeByte(BsonType.DOCUMENT.getValue()); writeCurrentName(); } setContext(new Context(getContext(), BsonContextType.DOCUMENT, bsonOutput.getPosition())); bsonOutput.writeInt32(0); // reserve space for size }
@Override protected void doWriteJavaScriptWithScope(final String value) { bsonOutput.writeByte(BsonType.JAVASCRIPT_WITH_SCOPE.getValue()); writeCurrentName(); setContext(new Context(getContext(), BsonContextType.JAVASCRIPT_WITH_SCOPE, bsonOutput.getPosition())); bsonOutput.writeInt32(0); bsonOutput.writeString(value); }
@Override protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput) { bsonOutput.writeInt32(0); // reserved bsonOutput.writeCString(getCollectionName()); int flags = 0; if (updateRequest.isUpsert()) { flags |= 1; } if (updateRequest.isMulti()) { flags |= 2; } bsonOutput.writeInt32(flags); int firstDocumentStartPosition = bsonOutput.getPosition(); addDocument(updateRequest.getFilter(), bsonOutput, new NoOpFieldNameValidator()); if (updateRequest.getType() == REPLACE) { addDocument(updateRequest.getUpdate(), bsonOutput, new CollectibleDocumentFieldNameValidator()); } else { int bufferPosition = bsonOutput.getPosition(); addDocument(updateRequest.getUpdate(), bsonOutput, new UpdateFieldNameValidator()); if (bsonOutput.getPosition() == bufferPosition + 5) { throw new IllegalArgumentException("Invalid BSON document for an update"); } } return new EncodingMetadata(firstDocumentStartPosition); }
bsonOutput.writeInt32(size); byte[] bytes = new byte[size - 4]; bsonInput.readBytes(bytes); pipeExtraElements(extraElements); bsonOutput.writeByte(0); bsonOutput.writeInt32(pipedDocumentStartPosition, bsonOutput.getPosition() - pipedDocumentStartPosition); setContext(getContext().getParentContext());
/** * Write the query prologue to the given BSON output. * * @param bsonOutput the BSON output */ protected void writeQueryPrologue(final BsonOutput bsonOutput) { bsonOutput.writeInt32(getCursorFlag()); bsonOutput.writeCString(getCollectionName()); bsonOutput.writeInt32(skip); bsonOutput.writeInt32(numberToReturn); } }
private void writeGetMore(final BsonOutput buffer) { buffer.writeInt32(0); buffer.writeCString(getCollectionName()); buffer.writeInt32(numberToReturn); buffer.writeInt64(cursorId); }
private void writeInsertPrologue(final BsonOutput outputStream) { outputStream.writeInt32(0); // flags outputStream.writeCString(getCollectionName()); } }