Liam Staskawicz avatar Liam Staskawicz committed a0e5da4

* binary didn't implement spec correctly

Comments (0)

Files changed (2)

fan/bson/BsonReader.fan

   static private Int readBuf(InStream ins, Int remaining, Str:Obj? bson)
   {
     name := readCStr(ins)
-    len := ins.readS4()
-    type := ins.read() // type ... todo - handle special types
-    val := ins.readBufFully(null, len)
+    totallen := ins.readS4()
+    Buf? val
+    switch(ins.read()) { // read type
+      case Bson.BIN_LENGTH:
+        len := ins.readS4()
+        if(len + 4 != totallen)
+          throw MongoOpErr("BSON - bad data size got subtype 0x02 len: $len, totallen: $totallen")
+        val = ins.readBufFully(null, len)
+    }
+    
     bson[name] = val
-    return remaining - (name.size + val.size + 6) // 6 == 1 null, 1 buf type, 4 buflen
+    return remaining - (name.size + totallen + 6)  // 6 == 1 null, 4 len, 1 type
   }
   
   static private Int readDate(InStream ins, Int remaining, Str:Obj? bson)

fan/bson/BsonWriter.fan

   {
     b.write(Bson.BINARY)
     writeCStr(b.out, key)
-    b.writeI4(bin.size).write(bbt)
+    b.writeI4(bin.size + 4).write(bbt).writeI4(bin.size)
     // don't disturb the pos
     p := bin.pos
     b.writeBuf(bin)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.