Permalink
Browse files

[fix] runtime, mongo: Binary & mongo

  • Loading branch information...
1 parent 79fb671 commit 081bd7e2f7dc73f36cf658e5d3048825a21e21d5 @BourgerieQuentin BourgerieQuentin committed Jul 31, 2012
Showing with 11 additions and 8 deletions.
  1. +5 −2 lib/plugins/mongo/bslMongo.ml
  2. +4 −4 lib/plugins/mongo/bslMongo.nodejs
  3. +2 −2 lib/stdlib/apis/mongo/common/bson.opa
@@ -135,7 +135,7 @@ let serialize bsons b =
aux (unwrap_opa_bson_document value);
Bson.Append.finish_array b
| Some "Binary" ->
- let bin = ServerLib.unwrap_string value in
+ let bin = Buffer.contents value in
Bson.Append.binary b name Bson.st_bin_binary bin (String.length bin)
| Some "ObjectID" -> Bson.Append.oid b name (ServerLib.unwrap_string value)
| Some "Boolean" -> Bson.Append.bool b name (ServerLib.unwrap_bool value)
@@ -225,7 +225,10 @@ let make_bool n x = make_val field_bool n (ServerLib.wrap_bool x)
let make_string = make_val field_string
let make_document = make_val field_document
let make_array = make_val field_array
-let make_binary = make_val field_binary
+let make_binary n s =
+ let x = Buffer.create (String.length s) in
+ Buffer.add_string x s;
+ make_val field_binary n x
let make_objectid = make_val field_objectid
let make_date = make_val field_date
let make_regexp n r ro = make_val field_regexp n (make_pair r ro)
@@ -17,6 +17,7 @@ var connect = mongo.connect;
##extern-type NodeBson.document
##extern-type NodeBson.value
##extern-type Mongo.reply
+##extern-type binary
##opa-type Bson.document
##opa-type Bson.value
@@ -101,11 +102,10 @@ var connect = mongo.connect;
return a;
}
- // TODO - binary
- ##register binary_value: string -> NodeBson.value
+ ##register binary_value: binary -> NodeBson.value
##args(b)
{
- return new mongo.Binary(b);
+ return new mongo.Binary(b.contents);
}
##register object_id_value: string -> NodeBson.value
@@ -187,7 +187,7 @@ var connect = mongo.connect;
} else if(c === mongo.Long){
return {Int64 : [x.getHighBits(), x.getLowBits()]};
} else if(c === mongo.Binary){
- return {Binary : x.buffer};
+ return {Binary : binary_of_buffer(x.buffer)};
} else if(c === mongo.ObjectID){
return {ObjectID : x.toString()};
} else if(c === mongo.Code){
@@ -43,7 +43,7 @@ import stdlib.core.{date,map}
**/
type Bson.numeric = int
type Bson.oid = string
-type Bson.binary = string
+type Bson.binary = binary
type Bson.regexp = (string, string)
type Bson.code = string
type Bson.symbol = string
@@ -79,7 +79,7 @@ type Bson.value =
/ { String: string }
/ { Document: Bson.document }
/ { Array: Bson.document }
- / { Binary: string }
+ / { Binary: binary }
/ { ObjectID: string }
/ { Boolean: bool }
/ { Date: Date.date }

0 comments on commit 081bd7e

Please sign in to comment.