/** * Encodes an undefined value * * @param name the field name * @see org.bson.BsonType#UNDEFINED */ protected void putUndefined(final String name) { putName(name); bsonWriter.writeUndefined(); }
/** * Encodes a field with data and time value. * * @param name the field name * @param date the value * @see org.bson.BsonType#DATE_TIME */ protected void putDate(final String name, final Date date) { putName(name); bsonWriter.writeDateTime(date.getTime()); }
/** * Encodes a String field * * @param name the field name * @param value the value * @see org.bson.BsonType#STRING */ protected void putString(final String name, final String value) { putName(name); bsonWriter.writeString(value); }
/** * Encodes a null value * * @param name the field name * @see org.bson.BsonType#NULL */ protected void putNull(final String name) { putName(name); bsonWriter.writeNull(); }
/** * Encodes a Decimal128 field. * * @param name the field name * @param value the value * @since 3.4 * @mongodb.server.release 3.4 */ protected void putDecimal128(final String name, final Decimal128 value) { putName(name); bsonWriter.writeDecimal128(value); }
/** * Encodes an ObjectId field to a {@link org.bson.BsonType#OBJECT_ID}. * * @param name the field name * @param objectId the value */ protected void putObjectId(final String name, final ObjectId objectId) { putName(name); bsonWriter.writeObjectId(objectId); }
/** * Encodes a field with a {@code Boolean} or {@code boolean} value * * @param name the field name * @param value the value */ protected void putBoolean(final String name, final Boolean value) { putName(name); bsonWriter.writeBoolean(value); }
/** * Encodes any {@code BSONObject}, as a document * * @param name the field name * @param document the value * @return the number of characters in the encoding */ protected int putObject(final String name, final BSONObject document) { putName(name); return putObject(document); }
/** * Encodes a field to a {@link org.bson.BsonType#MIN_KEY} value. * * @param name the field name */ protected void putMinKey(final String name) { putName(name); bsonWriter.writeMinKey(); }
/** * Encodes a field to a {@link org.bson.BsonType#MAX_KEY} value. * * @param name the field name */ protected void putMaxKey(final String name) { putName(name); bsonWriter.writeMaxKey(); }
/** * Encodes a byte array field * * @param name the field name * @param bytes the value * @see org.bson.BsonType#BINARY */ protected void putBinary(final String name, final byte[] bytes) { putName(name); bsonWriter.writeBinaryData(new BsonBinary(bytes)); }
/** * Encodes a Symbol field * * @param name the field name * @param symbol the value * @see org.bson.BsonType#SYMBOL */ protected void putSymbol(final String name, final Symbol symbol) { putName(name); bsonWriter.writeSymbol(symbol.getSymbol()); }
/** * Encodes a field to a {@link org.bson.BsonType#JAVASCRIPT} value. * * @param name the field name * @param code the value */ protected void putCode(final String name, final Code code) { putName(name); bsonWriter.writeJavaScript(code.getCode()); }
/** * Encodes a map, as a BSON document * * @param name the field name * @param map the value */ @SuppressWarnings({"rawtypes", "unchecked"}) protected void putMap(final String name, final Map map) { putName(name); bsonWriter.writeStartDocument(); for (final Map.Entry entry : (Set<Map.Entry>) map.entrySet()) { _putObjectField((String) entry.getKey(), entry.getValue()); } bsonWriter.writeEndDocument(); }
/** * Encodes a field with a {@link java.util.UUID} value. This is encoded to a binary value of subtype {@link * org.bson.BsonBinarySubType#UUID_LEGACY} * * @param name the field name * @param uuid the value */ protected void putUUID(final String name, final UUID uuid) { putName(name); byte[] bytes = new byte[16]; writeLongToArrayLittleEndian(bytes, 0, uuid.getMostSignificantBits()); writeLongToArrayLittleEndian(bytes, 8, uuid.getLeastSignificantBits()); bsonWriter.writeBinaryData(new BsonBinary(BsonBinarySubType.UUID_LEGACY, bytes)); }
/** * Encodes an Iterable, for example {@code List} values * * @param name the field name * @param iterable the value */ @SuppressWarnings("rawtypes") protected void putIterable(final String name, final Iterable iterable) { putName(name); bsonWriter.writeStartArray(); int i = 0; for (final Object o : iterable) { _putObjectField(String.valueOf(i), o); } bsonWriter.writeEndArray(); }
/** * Encodes a Pattern field to a {@link org.bson.BsonType#REGULAR_EXPRESSION}. * * @param name the field name * @param value the value * @mongodb.driver.manual reference/operator/query/regex/ $regex * @see org.bson.BsonType#BINARY */ protected void putPattern(final String name, final Pattern value) { putName(name); bsonWriter.writeRegularExpression(new BsonRegularExpression(value.pattern(), org.bson.BSON.regexFlags(value.flags()))); }
/** * Encodes a BSON timestamp * * @param name the field name * @param timestamp the timestamp to encode * @see org.bson.BsonType#TIMESTAMP */ protected void putTimestamp(final String name, final BSONTimestamp timestamp) { putName(name); bsonWriter.writeTimestamp(new BsonTimestamp(timestamp.getTime(), timestamp.getInc())); }
/** * Encodes a Binary field * * @param name the field name * @param binary the value * @see org.bson.BsonType#BINARY */ protected void putBinary(final String name, final Binary binary) { putName(name); bsonWriter.writeBinaryData(new BsonBinary(binary.getType(), binary.getData())); }
/** * Encodes a field to a {@link org.bson.BsonType#JAVASCRIPT_WITH_SCOPE} value. * * @param name the field name * @param codeWScope the value */ protected void putCodeWScope(final String name, final CodeWScope codeWScope) { putName(name); bsonWriter.writeJavaScriptWithScope(codeWScope.getCode()); putObject(codeWScope.getScope()); }