public static BsonTimestamp decodeTimestamp(BsonDocument resumeToken) {
        BsonValue bsonValue =
                Objects.requireNonNull(resumeToken, "Missing ResumeToken.").get(DATA_FIELD);
        final byte[] keyStringBytes;
        // Resume Tokens format: https://www.mongodb.com/docs/manual/changeStreams/#resume-tokens
        if (bsonValue.isBinary()) { // BinData
            keyStringBytes = bsonValue.asBinary().getData();
        } else if (bsonValue.isString()) { // Hex-encoded string (v0 or v1)
            keyStringBytes = hexToUint8Array(bsonValue.asString().getValue());
        } else {
            throw new IllegalArgumentException(
                    "Unknown resume token format: " + resumeToken.toJson());
        }

        ByteBuffer buffer = ByteBuffer.wrap(keyStringBytes).order(ByteOrder.BIG_ENDIAN);
        int kType = buffer.get() & 0xff;
        if (kType != K_TIMESTAMP) {
            throw new IllegalArgumentException("Unknown keyType of timestamp: " + kType);
        }

        int t = buffer.getInt();
        int i = buffer.getInt();
        return new BsonTimestamp(t, i);
    }
@Test
    public void testDecodeBinDataFormat() {
        BsonDocument resumeToken =
                BsonDocument.parse(
                        "{\"_data\": {\"$binary\": {\"base64\": \"gmNXqzwAAAABRmRfaWQAZGNXqj41xq4H4ebHNwBaEATmzwG2DzpOl4tpOyYEG9zABA==\", \"subType\": \"00\"}}}");
        BsonTimestamp expected = new BsonTimestamp(1666689852, 1);
        BsonTimestamp actual = ResumeTokenUtils.decodeTimestamp(resumeToken);
        assertEquals(expected, actual);
    }