2010-09-30 13:43:17 +00:00
|
|
|
// RubyBSONDecoder.java
|
|
|
|
|
|
|
|
package org.jbson;
|
|
|
|
|
|
|
|
import static org.bson.BSON.*;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import org.jruby.*;
|
|
|
|
|
|
|
|
import org.bson.*;
|
|
|
|
import org.bson.io.*;
|
|
|
|
import org.bson.types.*;
|
|
|
|
|
|
|
|
public class RubyBSONDecoder extends BSONDecoder {
|
|
|
|
|
2011-05-11 14:59:21 +00:00
|
|
|
protected void _binary( String name )
|
|
|
|
throws IOException {
|
|
|
|
final int totalLen = _in.readInt();
|
|
|
|
final byte bType = _in.read();
|
|
|
|
|
|
|
|
if( bType == 2 ) {
|
|
|
|
final int len = _in.readInt();
|
|
|
|
if ( len + 4 != totalLen )
|
|
|
|
throw new IllegalArgumentException( "bad data size subtype 2 len: " + len + "totalLen: " + totalLen );
|
|
|
|
|
|
|
|
final byte[] data = new byte[len];
|
|
|
|
_in.fill( data );
|
|
|
|
_callback.gotBinary( name, (byte)2, data );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
byte[] data = new byte[totalLen];
|
|
|
|
_in.fill( data );
|
|
|
|
_callback.gotBinary( name, bType, data );
|
|
|
|
}
|
|
|
|
}
|
2010-09-30 13:43:17 +00:00
|
|
|
}
|