lib/bson/encodable.rb
# Encodes BSON to raw bytes, for types that require the length of the
# entire bytes to be present as the first word of the encoded string. This
# includes Hash, CodeWithScope.
#
# @example Encode the BSON with placeholder bytes.
#   hash.encode_with_placeholder_and_null(BSON_ADJUST, encoded) do |encoded|
#     each do |field, value|
#       value.to_bson(encoded)
#     end
#   end
#
# @param [ Integer ] adjust The number of bytes to adjust with.
# @param [ String ] encoded The string to encode.
#
# @return [ String ] The encoded string.
#
# @since 2.0.0
Encodes BSON to raw bytes, for types that require the length of the
entire bytes to be present as the first word of the encoded string. This
includes Hash, CodeWithScope.
Encodes BSON to raw bytes for types that require the length of the entire bytes to be present as the first word of the encoded string . This includes Hash CodeWithScope .
def encode_with_placeholder_and_null(adjust, encoded = ''.force_encoding(BINARY))
      pos = encoded.bytesize
      encoded << PLACEHOLDER
      yield(encoded)
      encoded << NULL_BYTE
      encoded.set_int32(pos, encoded.bytesize - pos + adjust)
      encoded
    end
def encode_with_placeholder_and_null ( adjust , encoded = '' . force_encoding ( BINARY ) ) pos = encoded . bytesize encoded << PLACEHOLDER yield ( encoded ) encoded << NULL_BYTE encoded . set_int32 ( pos , encoded . bytesize - pos + adjust ) encoded end
Encodes BSON to raw bytes, for types that require the length of the
entire bytes to be present as the first word of the encoded string.
Encodes BSON to raw bytes for types that require the length of the entire bytes to be present as the first word of the encoded string .
The encoded string.
The encoded string .
 String 
adjust
encoded
force_encoding
encoded The string to encode.
encoded The string to encode .
example
Encode the BSON with placeholder bytes. hash.encode_with_placeholder_and_null(BSON_ADJUST, encoded) do |encoded| each do |field, value| value.to_bson(encoded) end end
Encode the BSON with placeholder bytes . hash . encode_with_placeholder_and_null ( BSON_ADJUST encoded ) do |encoded| each do |field value| value . to_bson ( encoded ) end end
since
None