Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix string/symbol encoding

  • Loading branch information...
commit 95bbb25a83c1b49bc6572096c892a3aef894be39 1 parent 8e12a7f
@tmm1 authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 buffer.rb
View
12 buffer.rb
@@ -84,6 +84,7 @@ def read *types
when 1 # number
data.read(:double)
when 2 # string
+ data.read(:int)
data.read(:cstring)
when 3 # object
data.read(:bson)
@@ -113,6 +114,7 @@ def read *types
ref[:_id] = data.read(:oid)
ref
when 14 # symbol
+ data.read(:int)
data.read(:cstring).intern
end
end
@@ -165,7 +167,10 @@ def write *args
type = :oid
else
id = 2
- type = :cstring
+ type = proc{ |out|
+ out.write(:int, value.length+1)
+ out.write(:cstring, value)
+ }
end
when Hash
if data.keys.map{|k| k.to_s}.sort == %w[ _id _ns ]
@@ -204,7 +209,10 @@ def write *args
}
when Symbol
id = 14
- type = :cstring
+ type = proc{ |out|
+ out.write(:int, value.to_s.length+1)
+ out.write(:cstring, value.to_s)
+ }
end
buf.write(:byte, id)
Please sign in to comment.
Something went wrong with that request. Please try again.