Sha256: 2a75310db41a680b5a8dfac6a4f1c7a361d17190293f953365a715b31bb768e8
Contents?: true
Size: 1.12 KB
Versions: 22
Compression:
Stored size: 1.12 KB
Contents
module Moped module BSON # @private module Extensions module String module ClassMethods def __bson_load__(io) io.read(*io.read(4).unpack(INT32_PACK)).from_utf8_binary.chop! end end def __bson_dump__(io, key) io << Types::STRING io << key.to_bson_cstring data = to_utf8_binary io << [ data.bytesize + 1 ].pack(INT32_PACK) io << data io << NULL_BYTE end def to_bson_cstring if include? NULL_BYTE raise EncodingError, "#{inspect} cannot be converted to a BSON " \ "cstring because it contains a null byte" end to_utf8_binary << NULL_BYTE end def to_utf8_binary encode(UTF8_ENCODING).force_encoding(BINARY_ENCODING) rescue EncodingError data = dup.force_encoding(UTF8_ENCODING) raise unless data.valid_encoding? data.force_encoding(BINARY_ENCODING) end def from_utf8_binary force_encoding(UTF8_ENCODING).encode! end end end end end
Version data entries
22 entries across 22 versions & 2 rubygems