@@ -1204,184 +1204,185 @@ func TestValueReader(t *testing.T) {
1204
1204
cwsbytes := bsoncore .AppendCodeWithScope (nil , "var hellow = world;" , docb )
1205
1205
strbytes := []byte {0x04 , 0x00 , 0x00 , 0x00 , 'f' , 'o' , 'o' , 0x00 }
1206
1206
testCases := []struct {
1207
- name string
1208
- t bsontype.Type
1209
- data []byte
1210
- err error
1211
- offset int64
1207
+ name string
1208
+ t bsontype.Type
1209
+ data []byte
1210
+ err error
1211
+ offset int64
1212
+ startingOffset int64
1212
1213
}{
1213
1214
{
1214
1215
"Array/invalid length" ,
1215
1216
bsontype .Array ,
1216
1217
[]byte {0x01 , 0x02 , 0x03 },
1217
- io .EOF , 0 ,
1218
+ io .EOF , 0 , 0 ,
1218
1219
},
1219
1220
{
1220
1221
"Array/not enough bytes" ,
1221
1222
bsontype .Array ,
1222
1223
[]byte {0x0F , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 },
1223
- io .EOF , 0 ,
1224
+ io .EOF , 0 , 0 ,
1224
1225
},
1225
1226
{
1226
1227
"Array/success" ,
1227
1228
bsontype .Array ,
1228
1229
[]byte {0x08 , 0x00 , 0x00 , 0x00 , 0x0A , '1' , 0x00 , 0x00 },
1229
- nil , 8 ,
1230
+ nil , 8 , 0 ,
1230
1231
},
1231
1232
{
1232
1233
"EmbeddedDocument/invalid length" ,
1233
1234
bsontype .EmbeddedDocument ,
1234
1235
[]byte {0x01 , 0x02 , 0x03 },
1235
- io .EOF , 0 ,
1236
+ io .EOF , 0 , 0 ,
1236
1237
},
1237
1238
{
1238
1239
"EmbeddedDocument/not enough bytes" ,
1239
1240
bsontype .EmbeddedDocument ,
1240
1241
[]byte {0x0F , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 },
1241
- io .EOF , 0 ,
1242
+ io .EOF , 0 , 0 ,
1242
1243
},
1243
1244
{
1244
1245
"EmbeddedDocument/success" ,
1245
1246
bsontype .EmbeddedDocument ,
1246
1247
[]byte {0x08 , 0x00 , 0x00 , 0x00 , 0x0A , 'A' , 0x00 , 0x00 },
1247
- nil , 8 ,
1248
+ nil , 8 , 0 ,
1248
1249
},
1249
1250
{
1250
1251
"CodeWithScope/invalid length" ,
1251
1252
bsontype .CodeWithScope ,
1252
1253
[]byte {0x01 , 0x02 , 0x03 },
1253
- io .EOF , 0 ,
1254
+ io .EOF , 0 , 0 ,
1254
1255
},
1255
1256
{
1256
1257
"CodeWithScope/not enough bytes" ,
1257
1258
bsontype .CodeWithScope ,
1258
1259
[]byte {0x0F , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 },
1259
- io .EOF , 0 ,
1260
+ io .EOF , 0 , 0 ,
1260
1261
},
1261
1262
{
1262
1263
"CodeWithScope/success" ,
1263
1264
bsontype .CodeWithScope ,
1264
1265
cwsbytes ,
1265
- nil , 41 ,
1266
+ nil , 41 , 0 ,
1266
1267
},
1267
1268
{
1268
1269
"Binary/invalid length" ,
1269
1270
bsontype .Binary ,
1270
1271
[]byte {0x01 , 0x02 , 0x03 },
1271
- io .EOF , 0 ,
1272
+ io .EOF , 0 , 0 ,
1272
1273
},
1273
1274
{
1274
1275
"Binary/not enough bytes" ,
1275
1276
bsontype .Binary ,
1276
1277
[]byte {0x0F , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 },
1277
- io .EOF , 0 ,
1278
+ io .EOF , 0 , 0 ,
1278
1279
},
1279
1280
{
1280
1281
"Binary/success" ,
1281
1282
bsontype .Binary ,
1282
1283
[]byte {0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 },
1283
- nil , 8 ,
1284
+ nil , 8 , 0 ,
1284
1285
},
1285
1286
{
1286
1287
"Boolean/invalid length" ,
1287
1288
bsontype .Boolean ,
1288
1289
[]byte {},
1289
- io .EOF , 0 ,
1290
+ io .EOF , 0 , 0 ,
1290
1291
},
1291
1292
{
1292
1293
"Boolean/success" ,
1293
1294
bsontype .Boolean ,
1294
1295
[]byte {0x01 },
1295
- nil , 1 ,
1296
+ nil , 1 , 0 ,
1296
1297
},
1297
1298
{
1298
1299
"DBPointer/invalid length" ,
1299
1300
bsontype .DBPointer ,
1300
1301
[]byte {0x01 , 0x02 , 0x03 },
1301
- io .EOF , 0 ,
1302
+ io .EOF , 0 , 0 ,
1302
1303
},
1303
1304
{
1304
1305
"DBPointer/not enough bytes" ,
1305
1306
bsontype .DBPointer ,
1306
1307
[]byte {0x0F , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 },
1307
- io .EOF , 0 ,
1308
+ io .EOF , 0 , 0 ,
1308
1309
},
1309
1310
{
1310
1311
"DBPointer/success" ,
1311
1312
bsontype .DBPointer ,
1312
1313
[]byte {0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A , 0x0B , 0x0C },
1313
- nil , 17 ,
1314
+ nil , 17 , 0 ,
1314
1315
},
1315
- {"DBPointer/not enough bytes" , bsontype .DateTime , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 },
1316
- {"DBPointer/success" , bsontype .DateTime , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 },
1317
- {"Double/not enough bytes" , bsontype .Double , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 },
1318
- {"Double/success" , bsontype .Double , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 },
1319
- {"Int64/not enough bytes" , bsontype .Int64 , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 },
1320
- {"Int64/success" , bsontype .Int64 , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 },
1321
- {"Timestamp/not enough bytes" , bsontype .Timestamp , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 },
1322
- {"Timestamp/success" , bsontype .Timestamp , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 },
1316
+ {"DBPointer/not enough bytes" , bsontype .DateTime , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 , 0 },
1317
+ {"DBPointer/success" , bsontype .DateTime , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 , 0 },
1318
+ {"Double/not enough bytes" , bsontype .Double , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 , 0 },
1319
+ {"Double/success" , bsontype .Double , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 , 0 },
1320
+ {"Int64/not enough bytes" , bsontype .Int64 , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 , 0 },
1321
+ {"Int64/success" , bsontype .Int64 , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 , 0 },
1322
+ {"Timestamp/not enough bytes" , bsontype .Timestamp , []byte {0x01 , 0x02 , 0x03 , 0x04 }, io .EOF , 0 , 0 },
1323
+ {"Timestamp/success" , bsontype .Timestamp , []byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, nil , 8 , 0 },
1323
1324
{
1324
1325
"Decimal128/not enough bytes" ,
1325
1326
bsontype .Decimal128 ,
1326
1327
[]byte {0x01 , 0x02 , 0x03 , 0x04 },
1327
- io .EOF , 0 ,
1328
+ io .EOF , 0 , 0 ,
1328
1329
},
1329
1330
{
1330
1331
"Decimal128/success" ,
1331
1332
bsontype .Decimal128 ,
1332
1333
[]byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F , 0x10 },
1333
- nil , 16 ,
1334
- },
1335
- {"Int32/not enough bytes" , bsontype .Int32 , []byte {0x01 , 0x02 }, io .EOF , 0 },
1336
- {"Int32/success" , bsontype .Int32 , []byte {0x01 , 0x02 , 0x03 , 0x04 }, nil , 4 },
1337
- {"Javascript/invalid length" , bsontype .JavaScript , strbytes [:2 ], io .EOF , 0 },
1338
- {"Javascript/not enough bytes" , bsontype .JavaScript , strbytes [:5 ], io .EOF , 0 },
1339
- {"Javascript/success" , bsontype .JavaScript , strbytes , nil , 8 },
1340
- {"String/invalid length" , bsontype .String , strbytes [:2 ], io .EOF , 0 },
1341
- {"String/not enough bytes" , bsontype .String , strbytes [:5 ], io .EOF , 0 },
1342
- {"String/success" , bsontype .String , strbytes , nil , 8 },
1343
- {"Symbol/invalid length" , bsontype .Symbol , strbytes [:2 ], io .EOF , 0 },
1344
- {"Symbol/not enough bytes" , bsontype .Symbol , strbytes [:5 ], io .EOF , 0 },
1345
- {"Symbol/success" , bsontype .Symbol , strbytes , nil , 8 },
1346
- {"MaxKey/success" , bsontype .MaxKey , []byte {}, nil , 0 },
1347
- {"MinKey/success" , bsontype .MinKey , []byte {}, nil , 0 },
1348
- {"Null/success" , bsontype .Null , []byte {}, nil , 0 },
1349
- {"Undefined/success" , bsontype .Undefined , []byte {}, nil , 0 },
1334
+ nil , 16 , 0 ,
1335
+ },
1336
+ {"Int32/not enough bytes" , bsontype .Int32 , []byte {0x01 , 0x02 }, io .EOF , 0 , 0 },
1337
+ {"Int32/success" , bsontype .Int32 , []byte {0x01 , 0x02 , 0x03 , 0x04 }, nil , 4 , 0 },
1338
+ {"Javascript/invalid length" , bsontype .JavaScript , strbytes [:2 ], io .EOF , 0 , 0 },
1339
+ {"Javascript/not enough bytes" , bsontype .JavaScript , strbytes [:5 ], io .EOF , 0 , 0 },
1340
+ {"Javascript/success" , bsontype .JavaScript , strbytes , nil , 8 , 0 },
1341
+ {"String/invalid length" , bsontype .String , strbytes [:2 ], io .EOF , 0 , 0 },
1342
+ {"String/not enough bytes" , bsontype .String , strbytes [:5 ], io .EOF , 0 , 0 },
1343
+ {"String/success" , bsontype .String , strbytes , nil , 8 , 0 },
1344
+ {"Symbol/invalid length" , bsontype .Symbol , strbytes [:2 ], io .EOF , 0 , 0 },
1345
+ {"Symbol/not enough bytes" , bsontype .Symbol , strbytes [:5 ], io .EOF , 0 , 0 },
1346
+ {"Symbol/success" , bsontype .Symbol , strbytes , nil , 8 , 0 },
1347
+ {"MaxKey/success" , bsontype .MaxKey , []byte {}, nil , 0 , 0 },
1348
+ {"MinKey/success" , bsontype .MinKey , []byte {}, nil , 0 , 0 },
1349
+ {"Null/success" , bsontype .Null , []byte {}, nil , 0 , 0 },
1350
+ {"Undefined/success" , bsontype .Undefined , []byte {}, nil , 0 , 0 },
1350
1351
{
1351
1352
"ObjectID/not enough bytes" ,
1352
1353
bsontype .ObjectID ,
1353
1354
[]byte {0x01 , 0x02 , 0x03 , 0x04 },
1354
- io .EOF , 0 ,
1355
+ io .EOF , 0 , 0 ,
1355
1356
},
1356
1357
{
1357
1358
"ObjectID/success" ,
1358
1359
bsontype .ObjectID ,
1359
1360
[]byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A , 0x0B , 0x0C },
1360
- nil , 12 ,
1361
+ nil , 12 , 0 ,
1361
1362
},
1362
1363
{
1363
1364
"Regex/not enough bytes (first string)" ,
1364
1365
bsontype .Regex ,
1365
1366
[]byte {'f' , 'o' , 'o' },
1366
- io .EOF , 0 ,
1367
+ io .EOF , 0 , 0 ,
1367
1368
},
1368
1369
{
1369
1370
"Regex/not enough bytes (second string)" ,
1370
1371
bsontype .Regex ,
1371
1372
[]byte {'f' , 'o' , 'o' , 0x00 , 'b' , 'a' , 'r' },
1372
- io .EOF , 0 ,
1373
+ io .EOF , 0 , 0 ,
1373
1374
},
1374
1375
{
1375
1376
"Regex/success" ,
1376
1377
bsontype .Regex ,
1377
- []byte {'f' , 'o' , 'o' , 0x00 , 'b' , 'a' , 'r ' , 0x00 },
1378
- nil , 8 ,
1378
+ []byte {0x00 , 0x00 , 0x00 , 'f' , 'o' , 'o' , 0x00 , 'i ' , 0x00 },
1379
+ nil , 9 , 3 ,
1379
1380
},
1380
1381
{
1381
1382
"Unknown Type" ,
1382
1383
bsontype .Type (0 ),
1383
1384
nil ,
1384
- fmt .Errorf ("attempted to read bytes of unknown BSON type %v" , bsontype .Type (0 )), 0 ,
1385
+ fmt .Errorf ("attempted to read bytes of unknown BSON type %v" , bsontype .Type (0 )), 0 , 0 ,
1385
1386
},
1386
1387
}
1387
1388
@@ -1394,7 +1395,8 @@ func TestValueReader(t *testing.T) {
1394
1395
{mode : mTopLevel },
1395
1396
{mode : mElement , vType : tc .t },
1396
1397
},
1397
- frame : 1 ,
1398
+ frame : 1 ,
1399
+ offset : tc .startingOffset ,
1398
1400
}
1399
1401
1400
1402
err := vr .Skip ()
@@ -1412,7 +1414,8 @@ func TestValueReader(t *testing.T) {
1412
1414
{mode : mTopLevel },
1413
1415
{mode : mElement , vType : tc .t },
1414
1416
},
1415
- frame : 1 ,
1417
+ frame : 1 ,
1418
+ offset : tc .startingOffset ,
1416
1419
}
1417
1420
1418
1421
_ , got , err := vr .ReadValueBytes (nil )
@@ -1422,8 +1425,8 @@ func TestValueReader(t *testing.T) {
1422
1425
if tc .err == nil && vr .offset != tc .offset {
1423
1426
t .Errorf ("Offset not set at correct position; got %d; want %d" , vr .offset , tc .offset )
1424
1427
}
1425
- if tc .err == nil && ! bytes .Equal (got , tc .data ) {
1426
- t .Errorf ("Did not receive expected bytes. got %v; want %v" , got , tc .data )
1428
+ if tc .err == nil && ! bytes .Equal (got , tc .data [ tc . startingOffset :] ) {
1429
+ t .Errorf ("Did not receive expected bytes. got %v; want %v" , got , tc .data [ tc . startingOffset :] )
1427
1430
}
1428
1431
})
1429
1432
})
0 commit comments