Commits

Liam Staskawicz committed 7330123

* use implicit conversions in BsonWriter instead of 'v as Type'

Comments (0)

Files changed (1)

fan/bson/BsonWriter.fan

   
   private static Buf writeObject(Buf b, Str:Obj? obj)
   {
-    lenpos := b.pos()
+    lenpos := b.pos
     b.writeI4(0) // placeholder for len
     obj.each |val, key| { writeKeyVal(b, key, val) }
     b.write(Bson.EOO) // end of object
   {
     if (val == null) writeNull(b, key)
     else if (val is Str) writeStr(b, key, val)
-    else if (val is Date) writeDateTime(b, key, val as DateTime) // convert to DateTime
-    else if (val is DateTime) writeDateTime(b, key, val)
+    // implicit conversion to DateTime
+    else if (val is Date || val is DateTime) writeDateTime(b, key, val)
     else if (val is Buf) writeBinary(b, key, val)
     else if (val is Int) writeInt(b, key, val)
-    else if (val is Decimal) writeFloat(b, key, (val as Decimal).toFloat())
-    // todo - maybe maintain Decimal somehow?
-    else if (val is Float) writeFloat(b, key, val)
+    // implicit conversion to Float - maybe maintain Decimal somehow?
+    else if (val is Float || val is Decimal) writeFloat(b, key, val)
     else if (val is ObjectID) writeOID(b, key, val)
     else if (val is List) writeArray(b, key, val)
     else if (val is Bool) writeBool(b, key, val)
   {
     b.write(Bson.DATE)
     writeCStr(b.out, key)
-    b.writeI8(d.toJava())
+    b.writeI8(d.toJava)
   }
   
   // bson array is really a map with stringified indexes
   {
     b.write(Bson.BINARY)
     writeCStr(b.out, key)
-    switch(bbt) {
+    switch (bbt) {
       case Bson.BIN_LENGTH:
         b.writeI4(bin.size + 4).write(bbt).writeI4(bin.size)
       default:
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.