Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Fix #to_utf8_binary conflicts with bson gem #388

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/moped/bson/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __bson_dump__(io, key)
io << key.to_bson_cstring
code_start = io.bytesize
io << START_LENGTH
data = code.to_utf8_binary
data = code.to_utf8_binary_moped
io << [data.bytesize+1].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand All @@ -30,7 +30,7 @@ def __bson_dump__(io, key)
else
io << Types::CODE
io << key.to_bson_cstring
data = code.to_utf8_binary
data = code.to_utf8_binary_moped
io << [data.bytesize+1].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand Down
6 changes: 3 additions & 3 deletions lib/moped/bson/extensions/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module String
def __bson_dump__(io, key)
io << Types::STRING
io << key.to_bson_cstring
data = to_utf8_binary
data = to_utf8_binary_moped
io << [ data.bytesize + 1 ].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand All @@ -18,10 +18,10 @@ def to_bson_cstring
raise EncodingError, "#{inspect} cannot be converted to a BSON " \
"cstring because it contains a null byte"
end
to_utf8_binary << NULL_BYTE
to_utf8_binary_moped << NULL_BYTE
end

def to_utf8_binary
def to_utf8_binary_moped
encode(Moped::BSON::UTF8_ENCODING).force_encoding(Moped::BSON::BINARY_ENCODING)
rescue EncodingError
data = dup.force_encoding(Moped::BSON::UTF8_ENCODING)
Expand Down
6 changes: 3 additions & 3 deletions lib/moped/bson/extensions/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Symbol
def __bson_dump__(io, key)
io << Types::SYMBOL
io << key.to_bson_cstring
data = to_utf8_binary
data = to_utf8_binary_moped
io << [ data.bytesize + 1 ].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand All @@ -17,8 +17,8 @@ def to_bson_cstring
to_s.to_bson_cstring
end

def to_utf8_binary
to_s.to_utf8_binary
def to_utf8_binary_moped
to_s.to_utf8_binary_moped
end

module ClassMethods
Expand Down