@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); } }
private static boolean writeDocument(final BsonWriter writer, final BsonOutput bsonOutput, final MessageSettings settings, final BsonDocument document, final int messageStartPosition, final int batchItemCount) { int currentPosition = bsonOutput.getPosition(); getCodec(document).encode(writer, document, ENCODER_CONTEXT); int messageSize = bsonOutput.getPosition() - messageStartPosition; int documentSize = bsonOutput.getPosition() - currentPosition; if (exceedsLimits(settings, messageSize, documentSize, batchItemCount)) { bsonOutput.truncateToPosition(currentPosition); return false; } return true; }
/** * 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 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()); } }
BsonBinaryReader binaryReader = (BsonBinaryReader) reader; if (getState() == State.VALUE) { bsonOutput.writeByte(BsonType.DOCUMENT.getValue()); writeCurrentName(); throw new BsonSerializationException("Document size must be at least 5"); int pipedDocumentStartPosition = bsonOutput.getPosition(); bsonOutput.writeInt32(size); byte[] bytes = new byte[size - 4]; bsonInput.readBytes(bytes); bsonOutput.writeBytes(bytes); bsonOutput.truncateToPosition(bsonOutput.getPosition() - 1); setContext(new Context(getContext(), BsonContextType.DOCUMENT, pipedDocumentStartPosition)); setState(State.NAME); pipeExtraElements(extraElements); bsonOutput.writeByte(0); bsonOutput.writeInt32(pipedDocumentStartPosition, bsonOutput.getPosition() - pipedDocumentStartPosition); setContext(getContext().getParentContext()); validateSize(bsonOutput.getPosition() - pipedDocumentStartPosition); } else if (extraElements != null) { super.pipe(reader, extraElements);
@Override protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput, final SessionContext sessionContext) { int messageStartPosition = bsonOutput.getPosition() - MESSAGE_PROLOGUE_LENGTH; int commandStartPosition; 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(), messageStartPosition, payload); int payloadBsonOutputLength = bsonOutput.getPosition() - payloadBsonOutputStartPosition; bsonOutput.writeInt32(payloadBsonOutputStartPosition, payloadBsonOutputLength); bsonOutput.writeInt32(flagPosition, getOpMsgFlagBits()); } else { bsonOutput.writeInt32(getOpQueryFlagBits()); bsonOutput.writeCString(namespace.getFullName()); bsonOutput.writeInt32(0); bsonOutput.writeInt32(-1); commandStartPosition = bsonOutput.getPosition();
@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 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 doWriteInt64(final long value) { bsonOutput.writeByte(BsonType.INT64.getValue()); writeCurrentName(); bsonOutput.writeInt64(value); }
@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 doWriteInt32(final int value) { bsonOutput.writeByte(BsonType.INT32.getValue()); writeCurrentName(); bsonOutput.writeInt32(value); }
@Override protected void doWriteDBPointer(final BsonDbPointer value) { bsonOutput.writeByte(BsonType.DB_POINTER.getValue()); writeCurrentName(); bsonOutput.writeString(value.getNamespace()); bsonOutput.writeBytes(value.getId().toByteArray()); }
/** * Creates a new instance storing the current position of the {@link org.bson.io.BsonOutput}. */ protected Mark() { this.position = bsonOutput.getPosition(); }
@Override protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput) { writeKillCursorsPrologue(cursors.size(), bsonOutput); for (final Long cur : cursors) { bsonOutput.writeInt64(cur); } return new EncodingMetadata(bsonOutput.getPosition()); }
@Override public void doWriteRegularExpression(final BsonRegularExpression value) { bsonOutput.writeByte(BsonType.REGULAR_EXPRESSION.getValue()); writeCurrentName(); bsonOutput.writeCString(value.getPattern()); bsonOutput.writeCString(value.getOptions()); }
@Override public void doWriteObjectId(final ObjectId value) { bsonOutput.writeByte(BsonType.OBJECT_ID.getValue()); writeCurrentName(); bsonOutput.writeBytes(value.toByteArray()); }
@Override protected void doWriteJavaScript(final String value) { bsonOutput.writeByte(BsonType.JAVASCRIPT.getValue()); writeCurrentName(); bsonOutput.writeString(value); }