Note that there are some explanatory texts on larger screens.

plurals
  1. POBSON Decoder exception
    primarykey
    data
    text
    <p>Since Mongo uses BSON, I am using the BSONDecoder from Java API to get the BSON document from the Mongo query and print the string output. In the following a byte[] array stores the bytes of the MongoDB document (when I print the hex values they are the same as in Wireshark)</p> <pre><code> byte[] array = byteBuffer.array(); BasicBSONDecoder decoder = new BasicBSONDecoder(); BSONObject bsonObject = decoder.readObject(array); System.out.println(bsonObject.toString()); </code></pre> <p>I get the following error:</p> <pre><code> org.bson.BSONException: should be impossible </code></pre> <p>Caused by: java.io.IOException: unexpected EOF at org.bson.BasicBSONDecoder$BSONInput._need(BasicBSONDecoder.java:327) at org.bson.BasicBSONDecoder$BSONInput.read(BasicBSONDecoder.java:364) at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:118) at org.bson.BasicBSONDecoder._decode(BasicBSONDecoder.java:79) at org.bson.BasicBSONDecoder.decode(BasicBSONDecoder.java:57) at org.bson.BasicBSONDecoder.readObject(BasicBSONDecoder.java:42) at org.bson.BasicBSONDecoder.readObject(BasicBSONDecoder.java:32) ... 4 more</p> <p>Looking on the implementation <a href="https://github.com/mongodb/mongo-java-driver/blob/master/src/main/org/bson/LazyBSONDecoder.java" rel="nofollow">https://github.com/mongodb/mongo-java-driver/blob/master/src/main/org/bson/LazyBSONDecoder.java</a> it looks that it is caught in </p> <pre><code> throw new BSONException( "should be impossible" , ioe ); </code></pre> <p>The above takes place in query to the database (by query I mean that byte[] array contains all the bytes after the document length). The query itself contains a string "ismaster" or in hex is "x10 ismaster x00 x01 x00 x00 x00 x00". I suspect it is the BSON format of {isMaster: 1}, but I still do not understand why it fails.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload