Liam Staskawicz avatar Liam Staskawicz committed 018c10d

* bson: use DOUBLE instead of NUMBER as per docs

Comments (0)

Files changed (3)

fan/bson/Bson.fan

   // data types
   static const Int MINKEY        := -1
   static const Int EOO           := 0
-  static const Int NUMBER        := 1
+  static const Int DOUBLE        := 1
   static const Int STRING        := 2
   static const Int OBJECT        := 3
   static const Int ARRAY         := 4

fan/bson/BsonReader.fan

           if (remaining > 0)
             log.warn("Bson.read() - got EOO with $remaining bytes remaining")
           break // end of object - return whatever we have
-        case Bson.NUMBER:
+        case Bson.DOUBLE:
           remaining = readFloat(ins, remaining, bson)
         case Bson.SYMBOL:
         case Bson.STRING:
         case Bson.UNDEFINED:
         case Bson.NULL:
           remaining = readNull(ins, remaining, bson)
-        // case BsonType.REGEX.val:
-        // case BsonType.CODE.val:
+        // case Bson.REGEX:
+          // remaining = readRegex(ins, remaining, bson)
         case Bson.CODE_W_SCOPE:
           remaining = readCode(ins, remaining, bson)
         case Bson.NUMBER_LONG:
   }
   
 }
-
-
-

fan/bson/BsonWriter.fan

     else if (val is Buf) writeBinary(b, key, val)
     else if (val is Int) writeInt(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 Float) writeFloat(b, key, val)
+    else if (val is Decimal) writeFloat(b, key, (val as Decimal).toFloat)
     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)
     else if (val is Map) writeMap(b, key, val)
     else if (val is Code) writeCode(b, key, val)
-    // else if (val is Regex) writeRegex(out, key, val)
+    // else if (val is Regex) writeRegex(b, key, val)
     else throw Err("unknown BSON type - can't serialize ${Type.of(val).qname}")
   }
   
   
   private static Void writeFloat(Buf b, Str key, Float f)
   {
-    b.write(Bson.NUMBER)
+    b.write(Bson.DOUBLE)
     writeCStr(b.out, key)
     b.writeF8(f)
   }
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.