@@ -237,6 +237,19 @@ public override BsonType ReadBsonType<TValue>(BsonTrie<TValue> bsonTrie, out boo
237
237
CurrentBsonType = BsonType . DateTime ;
238
238
_currentValue = ParseISODateTimeConstructor ( ) ;
239
239
break ;
240
+ case "MaxKey" :
241
+ CurrentBsonType = BsonType . MaxKey ;
242
+ _currentValue = BsonMaxKey . Value ;
243
+ break ;
244
+ case "MinKey" :
245
+ CurrentBsonType = BsonType . MinKey ;
246
+ _currentValue = BsonMinKey . Value ;
247
+ break ;
248
+ case "Number" :
249
+ case "NumberInt" :
250
+ CurrentBsonType = BsonType . Int32 ;
251
+ _currentValue = ParseNumberConstructor ( ) ;
252
+ break ;
240
253
case "NumberLong" :
241
254
CurrentBsonType = BsonType . Int64 ;
242
255
_currentValue = ParseNumberLongConstructor ( ) ;
@@ -249,6 +262,10 @@ public override BsonType ReadBsonType<TValue>(BsonTrie<TValue> bsonTrie, out boo
249
262
CurrentBsonType = BsonType . RegularExpression ;
250
263
_currentValue = ParseRegularExpressionConstructor ( ) ;
251
264
break ;
265
+ case "Timestamp" :
266
+ CurrentBsonType = BsonType . Timestamp ;
267
+ _currentValue = ParseTimestampConstructor ( ) ;
268
+ break ;
252
269
case "UUID" :
253
270
case "GUID" :
254
271
case "CSUUID" :
@@ -1036,12 +1053,14 @@ private BsonType ParseExtendedJson()
1036
1053
case "$binary" : _currentValue = ParseBinDataExtendedJson ( ) ; return BsonType . Binary ;
1037
1054
case "$code" : return ParseJavaScriptExtendedJson ( out _currentValue ) ;
1038
1055
case "$date" : _currentValue = ParseDateTimeExtendedJson ( ) ; return BsonType . DateTime ;
1039
- case "$maxkey" : _currentValue = ParseMaxKeyExtendedJson ( ) ; return BsonType . MaxKey ;
1040
- case "$minkey" : _currentValue = ParseMinKeyExtendedJson ( ) ; return BsonType . MinKey ;
1056
+ case "$maxkey" : case "$maxKey" : _currentValue = ParseMaxKeyExtendedJson ( ) ; return BsonType . MaxKey ;
1057
+ case "$minkey" : case "$minKey" : _currentValue = ParseMinKeyExtendedJson ( ) ; return BsonType . MinKey ;
1058
+ case "$numberLong" : _currentValue = ParseNumberLongExtendedJson ( ) ; return BsonType . Int64 ;
1041
1059
case "$oid" : _currentValue = ParseObjectIdExtendedJson ( ) ; return BsonType . ObjectId ;
1042
1060
case "$regex" : _currentValue = ParseRegularExpressionExtendedJson ( ) ; return BsonType . RegularExpression ;
1043
1061
case "$symbol" : _currentValue = ParseSymbolExtendedJson ( ) ; return BsonType . Symbol ;
1044
1062
case "$timestamp" : _currentValue = ParseTimestampExtendedJson ( ) ; return BsonType . Timestamp ;
1063
+ case "$undefined" : _currentValue = ParseUndefinedExtendedJson ( ) ; return BsonType . Undefined ;
1045
1064
}
1046
1065
}
1047
1066
PushToken ( nameToken ) ;
@@ -1242,6 +1261,9 @@ private BsonType ParseNew(out BsonValue value)
1242
1261
case "ISODate" :
1243
1262
value = ParseISODateTimeConstructor ( ) ;
1244
1263
return BsonType . DateTime ;
1264
+ case "NumberInt" :
1265
+ value = ParseNumberConstructor ( ) ;
1266
+ return BsonType . Int32 ;
1245
1267
case "NumberLong" :
1246
1268
value = ParseNumberLongConstructor ( ) ;
1247
1269
return BsonType . Int64 ;
@@ -1251,6 +1273,9 @@ private BsonType ParseNew(out BsonValue value)
1251
1273
case "RegExp" :
1252
1274
value = ParseRegularExpressionConstructor ( ) ;
1253
1275
return BsonType . RegularExpression ;
1276
+ case "Timestamp" :
1277
+ value = ParseTimestampConstructor ( ) ;
1278
+ return BsonType . Timestamp ;
1254
1279
case "UUID" :
1255
1280
case "GUID" :
1256
1281
case "CSUUID" :
@@ -1267,6 +1292,28 @@ private BsonType ParseNew(out BsonValue value)
1267
1292
}
1268
1293
}
1269
1294
1295
+ private BsonValue ParseNumberConstructor ( )
1296
+ {
1297
+ VerifyToken ( "(" ) ;
1298
+ var valueToken = PopToken ( ) ;
1299
+ int value ;
1300
+ if ( valueToken . IsNumber )
1301
+ {
1302
+ value = valueToken . Int32Value ;
1303
+ }
1304
+ else if ( valueToken . Type == JsonTokenType . String )
1305
+ {
1306
+ value = int . Parse ( valueToken . StringValue ) ;
1307
+ }
1308
+ else
1309
+ {
1310
+ var message = string . Format ( "JSON reader expected an integer or a string but found '{0}'." , valueToken . Lexeme ) ;
1311
+ throw new FileFormatException ( message ) ;
1312
+ }
1313
+ VerifyToken ( ")" ) ;
1314
+ return new BsonInt32 ( value ) ;
1315
+ }
1316
+
1270
1317
private BsonValue ParseNumberLongConstructor ( )
1271
1318
{
1272
1319
VerifyToken ( "(" ) ;
@@ -1289,6 +1336,19 @@ private BsonValue ParseNumberLongConstructor()
1289
1336
return new BsonInt64 ( value ) ;
1290
1337
}
1291
1338
1339
+ private BsonValue ParseNumberLongExtendedJson ( )
1340
+ {
1341
+ VerifyToken ( ":" ) ;
1342
+ var valueToken = PopToken ( ) ;
1343
+ if ( valueToken . Type != JsonTokenType . String )
1344
+ {
1345
+ var message = string . Format ( "JSON reader expected a string but found '{0}'." , valueToken . Lexeme ) ;
1346
+ throw new FileFormatException ( message ) ;
1347
+ }
1348
+ VerifyToken ( "}" ) ;
1349
+ return new BsonInt64 ( long . Parse ( valueToken . StringValue ) ) ;
1350
+ }
1351
+
1292
1352
private BsonValue ParseObjectIdConstructor ( )
1293
1353
{
1294
1354
VerifyToken ( "(" ) ;
@@ -1388,10 +1448,86 @@ private BsonValue ParseSymbolExtendedJson()
1388
1448
return new BsonString ( nameToken . StringValue ) ; // will be converted to a BsonSymbol at a higher level
1389
1449
}
1390
1450
1451
+ private BsonValue ParseTimestampConstructor ( )
1452
+ {
1453
+ VerifyToken ( "(" ) ;
1454
+ int secondsSinceEpoch ;
1455
+ var secondsSinceEpochToken = PopToken ( ) ;
1456
+ if ( secondsSinceEpochToken . IsNumber )
1457
+ {
1458
+ secondsSinceEpoch = secondsSinceEpochToken . Int32Value ;
1459
+ }
1460
+ else
1461
+ {
1462
+ var message = string . Format ( "JSON reader expected a number but found '{0}'." , secondsSinceEpochToken . Lexeme ) ;
1463
+ throw new FileFormatException ( message ) ;
1464
+ }
1465
+ VerifyToken ( "," ) ;
1466
+ int increment ;
1467
+ var incrementToken = PopToken ( ) ;
1468
+ if ( secondsSinceEpochToken . IsNumber )
1469
+ {
1470
+ increment = incrementToken . Int32Value ;
1471
+ }
1472
+ else
1473
+ {
1474
+ var message = string . Format ( "JSON reader expected a number but found '{0}'." , secondsSinceEpochToken . Lexeme ) ;
1475
+ throw new FileFormatException ( message ) ;
1476
+ }
1477
+ VerifyToken ( ")" ) ;
1478
+ return new BsonTimestamp ( secondsSinceEpoch , increment ) ;
1479
+ }
1480
+
1391
1481
private BsonValue ParseTimestampExtendedJson ( )
1392
1482
{
1393
1483
VerifyToken ( ":" ) ;
1394
- var valueToken = PopToken ( ) ;
1484
+ var nextToken = PopToken ( ) ;
1485
+ if ( nextToken . Type == JsonTokenType . BeginObject )
1486
+ {
1487
+ return ParseTimestampExtendedJsonNewRepresentation ( ) ;
1488
+ }
1489
+ else
1490
+ {
1491
+ return ParseTimestampExtendedJsonOldRepresentation ( nextToken ) ;
1492
+ }
1493
+ }
1494
+
1495
+ private BsonValue ParseTimestampExtendedJsonNewRepresentation ( )
1496
+ {
1497
+ VerifyString ( "t" ) ;
1498
+ VerifyToken ( ":" ) ;
1499
+ var secondsSinceEpochToken = PopToken ( ) ;
1500
+ int secondsSinceEpoch ;
1501
+ if ( secondsSinceEpochToken . IsNumber )
1502
+ {
1503
+ secondsSinceEpoch = secondsSinceEpochToken . Int32Value ;
1504
+ }
1505
+ else
1506
+ {
1507
+ var message = string . Format ( "JSON reader expected an integer but found '{0}'." , secondsSinceEpochToken . Lexeme ) ;
1508
+ throw new FileFormatException ( message ) ;
1509
+ }
1510
+ VerifyToken ( "," ) ;
1511
+ VerifyString ( "i" ) ;
1512
+ VerifyToken ( ":" ) ;
1513
+ var incrementToken = PopToken ( ) ;
1514
+ int increment ;
1515
+ if ( incrementToken . IsNumber )
1516
+ {
1517
+ increment = incrementToken . Int32Value ;
1518
+ }
1519
+ else
1520
+ {
1521
+ var message = string . Format ( "JSON reader expected an integer but found '{0}'." , incrementToken . Lexeme ) ;
1522
+ throw new FileFormatException ( message ) ;
1523
+ }
1524
+ VerifyToken ( "}" ) ;
1525
+ VerifyToken ( "}" ) ;
1526
+ return new BsonTimestamp ( secondsSinceEpoch , increment ) ;
1527
+ }
1528
+
1529
+ private BsonValue ParseTimestampExtendedJsonOldRepresentation ( JsonToken valueToken )
1530
+ {
1395
1531
long value ;
1396
1532
if ( valueToken . Type == JsonTokenType . Int32 || valueToken . Type == JsonTokenType . Int64 )
1397
1533
{
@@ -1410,6 +1546,14 @@ private BsonValue ParseTimestampExtendedJson()
1410
1546
return new BsonTimestamp ( value ) ;
1411
1547
}
1412
1548
1549
+ private BsonValue ParseUndefinedExtendedJson ( )
1550
+ {
1551
+ VerifyToken ( ":" ) ;
1552
+ VerifyToken ( "true" ) ;
1553
+ VerifyToken ( "}" ) ;
1554
+ return BsonMaxKey . Value ;
1555
+ }
1556
+
1413
1557
private BsonValue ParseUUIDConstructor ( string uuidConstructorName )
1414
1558
{
1415
1559
VerifyToken ( "(" ) ;
0 commit comments