driver-core/src/main/com/mongodb/internal/connection/RequestMessage.java
public void encode(final BsonOutput bsonOutput, final SessionContext sessionContext) {
        notNull("sessionContext", sessionContext);
        int messageStartPosition = bsonOutput.getPosition();
        writeMessagePrologue(bsonOutput);
        EncodingMetadata encodingMetadata = encodeMessageBodyWithMetadata(bsonOutput, sessionContext);
        backpatchMessageLength(messageStartPosition, bsonOutput);
        this.encodingMetadata = encodingMetadata;
    }
public void encode(final BsonOutput bsonOutput, final SessionContext sessionContext) {
        notNull("sessionContext", sessionContext);
        int messageStartPosition = bsonOutput.getPosition();
        writeMessagePrologue(bsonOutput);
        EncodingMetadata encodingMetadata = encodeMessageBodyWithMetadata(bsonOutput, sessionContext);
        backpatchMessageLength(messageStartPosition, bsonOutput);
        this.encodingMetadata = encodingMetadata;
    }
Encoded the message to the given output.

@param bsonOutput the output
@param sessionContext the session context