Commits

Liam Staskawicz  committed f629a05

* only need to update remaining count outside read methods

  • Participants
  • Parent commits 018c10d

Comments (0)

Files changed (1)

File fan/bson/BsonReader.fan

       switch (type)
       {
         case Bson.MINKEY:
-          remaining = readMinKey(ins, remaining, bson)
+          remaining -= readMinKey(ins, bson)
         case Bson.EOO:
           if (remaining > 0)
             log.warn("Bson.read() - got EOO with $remaining bytes remaining")
           break // end of object - return whatever we have
         case Bson.DOUBLE:
-          remaining = readFloat(ins, remaining, bson)
+          remaining -= readFloat(ins, bson)
         case Bson.SYMBOL:
         case Bson.STRING:
-          remaining = readStr(ins, remaining, bson)
+          remaining -= readStr(ins, bson)
         case Bson.OBJECT:
-          remaining = readMap(ins, remaining, bson)
+          remaining -= readMap(ins, bson)
         case Bson.ARRAY:
-          remaining = readArray(ins, remaining, bson)
+          remaining -= readArray(ins, bson)
         case Bson.BINARY:
-          remaining = readBuf(ins, remaining, bson)
+          remaining -= readBuf(ins, bson)
         case Bson.OID:
-          remaining = readOID(ins, remaining, bson)
+          remaining -= readOID(ins, bson)
         case Bson.BOOLEAN:
-          remaining = readBool(ins, remaining, bson)
+          remaining -= readBool(ins, bson)
         case Bson.TIMESTAMP: // both have the same format
         case Bson.DATE:
-          remaining = readDate(ins, remaining, bson)
+          remaining -= readDate(ins, bson)
         case Bson.UNDEFINED:
         case Bson.NULL:
-          remaining = readNull(ins, remaining, bson)
+          remaining -= readNull(ins, bson)
         // case Bson.REGEX:
-          // remaining = readRegex(ins, remaining, bson)
+          // remaining = readRegex(ins, bson)
         case Bson.CODE_W_SCOPE:
-          remaining = readCode(ins, remaining, bson)
+          remaining -= readCode(ins, bson)
         case Bson.NUMBER_LONG:
-          remaining = readLong(ins, remaining, bson)
+          remaining -= readLong(ins, bson)
         case Bson.NUMBER_INT:
-          remaining = readInt(ins, remaining, bson)
+          remaining -= readInt(ins, bson)
         case Bson.MAXKEY:
-          remaining = readMaxKey(ins, remaining, bson)
+          remaining -= readMaxKey(ins, bson)
         default:
           throw Err("Unknown BSON type received - ${type}")
       }
     return str
   }
   
-  static private Int readStr(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readStr(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     val := ins.readChars(ins.readU4 - 1)
     ins.skip(1) // eat the null terminator...worth validating that this is 0?
     bson[name] = val
-    return remaining - (name.size + val.size + 6) // 6 == 1 null, 1 null, 4 strlen
+    return (name.size + val.size + 6) // 6 == 1 null, 1 null, 4 strlen
   }
   
-  static private Int readInt(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readInt(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = ins.readS4
-    return remaining - (name.size + 5) // 5 == 1 null, 4 int len
+    return (name.size + 5) // 5 == 1 null, 4 int len
   }
   
-  static private Int readLong(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readLong(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = ins.readS8
-    return remaining - (name.size + 9) // 9 == 1 null, 8 long len
+    return (name.size + 9) // 9 == 1 null, 8 long len
   }
   
-  static private Int readFloat(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readFloat(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = ins.readF8
-    return remaining - (name.size + 9) // 9 == 1 null, 8 floatlen
+    return (name.size + 9) // 9 == 1 null, 8 floatlen
   }
   
-  static private Int readBool(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readBool(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = (ins.read == 0x01) ? true : false
-    return remaining - (name.size + 2) // 2 == 1 null, 1 bool
+    return (name.size + 2) // 2 == 1 null, 1 bool
   }
   
-  static private Int readBuf(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readBuf(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     totallen := ins.readS4
         val = ins.readBufFully(null, totallen)
     }
     bson[name] = val
-    return remaining - (name.size + totallen + 6)  // 6 == 1 null, 4 len, 1 type
+    return (name.size + totallen + 6)  // 6 == 1 null, 4 len, 1 type
   }
   
-  static private Int readDate(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readDate(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = DateTime.fromJava(ins.readS8)
-    return remaining - (name.size + 9) // 9 == 1 null, 8 date len
+    return (name.size + 9) // 9 == 1 null, 8 date len
   }
   
-  static private Int readNull(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readNull(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = null
-    return remaining - (name.size + 1)
+    return (name.size + 1)
   }
   
-  static private Int readOID(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readOID(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = ObjectID.fromStream(ins)
-    return remaining - (name.size + 1 + ObjectID.SIZE)
+    return (name.size + 1 + ObjectID.SIZE)
   }
   
-  static private Int readArray(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readArray(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     arr := Str:Obj?[:] { ordered = true }
     arraylen := readObject(ins, arr)
     bson[name] = arr.vals
-    return remaining - (name.size + 1 + arraylen)
+    return (name.size + 1 + arraylen)
   }
   
-  static private Int readMap(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readMap(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     v := Str:Obj?[:] { ordered = true }
     objlen := readObject(ins, v)
     bson[name] = v
-    return remaining - (name.size + 1 + objlen)
+    return (name.size + 1 + objlen)
   }
   
-  static private Int readCode(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readCode(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     totalsize := ins.readS4
     scope := Str:Obj?[:] { ordered = true }
     readObject(ins, scope)
     bson[name] = Code(code, scope)
-    return remaining - (name.size + 1 + totalsize + 4 + 4) // 4 - totalsize, 4 - strsize
+    return (name.size + 1 + totalsize + 4 + 4) // 4 - totalsize, 4 - strsize
   }
   
-  static private Int readMinKey(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readMinKey(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = MinKey() // todo - figure this out
-    return remaining - (name.size + 1)
+    return (name.size + 1)
   }
   
-  static private Int readMaxKey(InStream ins, Int remaining, Str:Obj? bson)
+  static private Int readMaxKey(InStream ins, Str:Obj? bson)
   {
     name := readCStr(ins)
     bson[name] = MaxKey() // todo - figure this out
-    return remaining - (name.size + 1)
+    return (name.size + 1)
   }
   
 }