Permalink
Browse files

switch default subtype to 0 for BinData bson

  • Loading branch information...
1 parent 1dd024d commit 23882959f5f7a66b39524af8710277ee0dfc29bb @dwight dwight committed Jun 9, 2010
Showing with 35 additions and 24 deletions.
  1. +4 −3 bson/bsonobjbuilder.h
  2. +8 −1 bson/bsontypes.h
  3. +1 −1 dbtests/jsobjtests.cpp
  4. +18 −15 dbtests/jsontests.cpp
  5. +4 −4 dbtests/jstests.cpp
View
@@ -376,8 +376,8 @@ namespace mongo {
/** Append a binary data element
@param fieldName name of the field
@param len length of the binary data in bytes
- @param type type information for the data. @see BinDataType. Use ByteArray if you
- don't care about the type.
+ @param subtype subtype information for the data. @see enum BinDataType in bsontypes.h.
+ Use BinDataGeneral if you don't care about the type.
@param data the byte array
*/
BSONObjBuilder& appendBinData( const char *fieldName, int len, BinDataType type, const char *data ) {
@@ -393,11 +393,12 @@ namespace mongo {
}
/**
+ Subtype 2 is deprecated.
Append a BSON bindata bytearray element.
@param data a byte array
@param len the length of data
*/
- BSONObjBuilder& appendBinDataArray( const char * fieldName , const char * data , int len ){
+ BSONObjBuilder& appendBinDataArrayDeprecated( const char * fieldName , const char * data , int len ){
_b.append( (char) BinData );
_b.append( fieldName );
_b.append( len + 4 );
View
@@ -94,7 +94,14 @@ enum BSONType {
bdtCustom and above are ones that the JS compiler understands, but are
opaque to the database.
*/
- enum BinDataType { Function=1, ByteArray=2, bdtUUID = 3, MD5Type=5, bdtCustom=128 };
+ enum BinDataType {
+ BinDataGeneral=0,
+ Function=1,
+ ByteArrayDeprecated=2, /* use BinGeneral instead */
+ bdtUUID = 3,
+ MD5Type=5,
+ bdtCustom=128
+ };
}
View
@@ -639,7 +639,7 @@ namespace JsobjTests {
"\"seven\": [ \"a\", \"bb\", \"ccc\", 5 ],"
"\"eight\": Dbref( \"rrr\", \"01234567890123456789aaaa\" ),"
"\"_id\": ObjectId( \"deadbeefdeadbeefdeadbeef\" ),"
- "\"nine\": { \"$binary\": \"abc=\", \"$type\": \"02\" },"
+ "\"nine\": { \"$binary\": \"abc=\", \"$type\": \"00\" },"
"\"ten\": Date( 44 ), \"eleven\": /foooooo/i }" );
fuzz( b );
b.valid();
View
@@ -248,18 +248,21 @@ namespace JsonTests {
z[ 1 ] = 'b';
z[ 2 ] = 'c';
BSONObjBuilder b;
- b.appendBinData( "a", 3, ByteArray, z );
- ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"02\" } }",
- b.done().jsonString( Strict ) );
+ b.appendBinData( "a", 3, BinDataGeneral, z );
+
+ string o = b.done().jsonString( Strict );
+
+ ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"00\" } }",
+ o );
BSONObjBuilder c;
- c.appendBinData( "a", 2, ByteArray, z );
- ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"02\" } }",
+ c.appendBinData( "a", 2, BinDataGeneral, z );
+ ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"00\" } }",
c.done().jsonString( Strict ) );
BSONObjBuilder d;
- d.appendBinData( "a", 1, ByteArray, z );
- ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"02\" } }",
+ d.appendBinData( "a", 1, BinDataGeneral, z );
+ ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"00\" } }",
d.done().jsonString( Strict ) );
}
};
@@ -771,11 +774,11 @@ namespace JsonTests {
z[ 1 ] = 'b';
z[ 2 ] = 'c';
BSONObjBuilder b;
- b.appendBinData( "a", 3, ByteArray, z );
+ b.appendBinData( "a", 3, BinDataGeneral, z );
return b.obj();
}
virtual string json() const {
- return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"02\" } }";
+ return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"00\" } }";
}
};
@@ -785,11 +788,11 @@ namespace JsonTests {
z[ 0 ] = 'a';
z[ 1 ] = 'b';
BSONObjBuilder b;
- b.appendBinData( "a", 2, ByteArray, z );
+ b.appendBinData( "a", 2, BinDataGeneral, z );
return b.obj();
}
virtual string json() const {
- return "{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"02\" } }";
+ return "{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"00\" } }";
}
};
@@ -798,11 +801,11 @@ namespace JsonTests {
char z[ 1 ];
z[ 0 ] = 'a';
BSONObjBuilder b;
- b.appendBinData( "a", 1, ByteArray, z );
+ b.appendBinData( "a", 1, BinDataGeneral, z );
return b.obj();
}
virtual string json() const {
- return "{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"02\" } }";
+ return "{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"00\" } }";
}
};
@@ -816,11 +819,11 @@ namespace JsonTests {
0x5D, 0xB7, 0xE3, 0x9E, 0xBB, 0xF3, 0xDF, 0xBF
};
BSONObjBuilder b;
- b.appendBinData( "a", 48, ByteArray, z );
+ b.appendBinData( "a", 48, BinDataGeneral, z );
return b.obj();
}
virtual string json() const {
- return "{ \"a\" : { \"$binary\" : \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\", \"$type\" : \"02\" } }";
+ return "{ \"a\" : { \"$binary\" : \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\", \"$type\" : \"00\" } }";
}
};
View
@@ -808,7 +808,7 @@ namespace JSTests {
{
BSONObjBuilder b;
b.append( "a" , 7 );
- b.appendBinData( "b" , 12 , ByteArray , foo );
+ b.appendBinData( "b" , 12 , BinDataGeneral , foo );
in = b.obj();
s->setObject( "x" , in );
}
@@ -825,11 +825,11 @@ namespace JSTests {
// check that BinData js class is utilized
s->invokeSafe( "q = x.b.toString();", BSONObj() );
stringstream expected;
- expected << "BinData( type: " << ByteArray << ", base64: \"" << base64 << "\" )";
+ expected << "BinData( type: " << BinDataGeneral << ", base64: \"" << base64 << "\" )";
ASSERT_EQUALS( expected.str(), s->getString( "q" ) );
stringstream scriptBuilder;
- scriptBuilder << "z = { c : new BinData( " << ByteArray << ", \"" << base64 << "\" ) };";
+ scriptBuilder << "z = { c : new BinData( " << BinDataGeneral << ", \"" << base64 << "\" ) };";
string script = scriptBuilder.str();
s->invokeSafe( script.c_str(), BSONObj() );
out = s->getObject( "z" );
@@ -879,7 +879,7 @@ namespace JSTests {
s->invoke( f , empty );
ASSERT_EQUALS( 11 , s->getNumber( "return" ) );
}
- cout << "speed1: " << ( n / t.millis() ) << " ops/ms" << endl;
+ //cout << "speed1: " << ( n / t.millis() ) << " ops/ms" << endl;
}
};

0 comments on commit 2388295

Please sign in to comment.