-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsonrwtest.go
executable file
·847 lines (759 loc) · 20.7 KB
/
bsonrwtest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package bsonrwtest // import "go.mongodb.org/mongo-driver/bson/bsonrw/bsonrwtest"
import (
"testing"
"go.mongodb.org/mongo-driver/bson/bsonrw"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
var _ bsonrw.ValueReader = (*ValueReaderWriter)(nil)
var _ bsonrw.ValueWriter = (*ValueReaderWriter)(nil)
// Invoked is a type used to indicate what method was called last.
type Invoked byte
// These are the different methods that can be invoked.
const (
Nothing Invoked = iota
ReadArray
ReadBinary
ReadBoolean
ReadDocument
ReadCodeWithScope
ReadDBPointer
ReadDateTime
ReadDecimal128
ReadDouble
ReadInt32
ReadInt64
ReadJavascript
ReadMaxKey
ReadMinKey
ReadNull
ReadObjectID
ReadRegex
ReadString
ReadSymbol
ReadTimestamp
ReadUndefined
ReadElement
ReadValue
WriteArray
WriteBinary
WriteBinaryWithSubtype
WriteBoolean
WriteCodeWithScope
WriteDBPointer
WriteDateTime
WriteDecimal128
WriteDouble
WriteInt32
WriteInt64
WriteJavascript
WriteMaxKey
WriteMinKey
WriteNull
WriteObjectID
WriteRegex
WriteString
WriteDocument
WriteSymbol
WriteTimestamp
WriteUndefined
WriteDocumentElement
WriteDocumentEnd
WriteArrayElement
WriteArrayEnd
Skip
)
func (i Invoked) String() string {
switch i {
case Nothing:
return "Nothing"
case ReadArray:
return "ReadArray"
case ReadBinary:
return "ReadBinary"
case ReadBoolean:
return "ReadBoolean"
case ReadDocument:
return "ReadDocument"
case ReadCodeWithScope:
return "ReadCodeWithScope"
case ReadDBPointer:
return "ReadDBPointer"
case ReadDateTime:
return "ReadDateTime"
case ReadDecimal128:
return "ReadDecimal128"
case ReadDouble:
return "ReadDouble"
case ReadInt32:
return "ReadInt32"
case ReadInt64:
return "ReadInt64"
case ReadJavascript:
return "ReadJavascript"
case ReadMaxKey:
return "ReadMaxKey"
case ReadMinKey:
return "ReadMinKey"
case ReadNull:
return "ReadNull"
case ReadObjectID:
return "ReadObjectID"
case ReadRegex:
return "ReadRegex"
case ReadString:
return "ReadString"
case ReadSymbol:
return "ReadSymbol"
case ReadTimestamp:
return "ReadTimestamp"
case ReadUndefined:
return "ReadUndefined"
case ReadElement:
return "ReadElement"
case ReadValue:
return "ReadValue"
case WriteArray:
return "WriteArray"
case WriteBinary:
return "WriteBinary"
case WriteBinaryWithSubtype:
return "WriteBinaryWithSubtype"
case WriteBoolean:
return "WriteBoolean"
case WriteCodeWithScope:
return "WriteCodeWithScope"
case WriteDBPointer:
return "WriteDBPointer"
case WriteDateTime:
return "WriteDateTime"
case WriteDecimal128:
return "WriteDecimal128"
case WriteDouble:
return "WriteDouble"
case WriteInt32:
return "WriteInt32"
case WriteInt64:
return "WriteInt64"
case WriteJavascript:
return "WriteJavascript"
case WriteMaxKey:
return "WriteMaxKey"
case WriteMinKey:
return "WriteMinKey"
case WriteNull:
return "WriteNull"
case WriteObjectID:
return "WriteObjectID"
case WriteRegex:
return "WriteRegex"
case WriteString:
return "WriteString"
case WriteDocument:
return "WriteDocument"
case WriteSymbol:
return "WriteSymbol"
case WriteTimestamp:
return "WriteTimestamp"
case WriteUndefined:
return "WriteUndefined"
case WriteDocumentElement:
return "WriteDocumentElement"
case WriteDocumentEnd:
return "WriteDocumentEnd"
case WriteArrayElement:
return "WriteArrayElement"
case WriteArrayEnd:
return "WriteArrayEnd"
default:
return "<unknown>"
}
}
// ValueReaderWriter is a test implementation of a bsonrw.ValueReader and bsonrw.ValueWriter
type ValueReaderWriter struct {
T *testing.T
Invoked Invoked
Return interface{} // Can be a primitive or a bsoncore.Value
BSONType bsontype.Type
Err error
ErrAfter Invoked // error after this method is called
depth uint64
}
// prevent infinite recursion.
func (llvrw *ValueReaderWriter) checkdepth() {
llvrw.depth++
if llvrw.depth > 1000 {
panic("max depth exceeded")
}
}
// Type implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) Type() bsontype.Type {
llvrw.checkdepth()
return llvrw.BSONType
}
// Skip implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) Skip() error {
llvrw.checkdepth()
llvrw.Invoked = Skip
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// ReadArray implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadArray() (bsonrw.ArrayReader, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadArray
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// ReadBinary implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadBinary() (b []byte, btype byte, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadBinary
if llvrw.ErrAfter == llvrw.Invoked {
return nil, 0x00, llvrw.Err
}
switch tt := llvrw.Return.(type) {
case bsoncore.Value:
subtype, data, _, ok := bsoncore.ReadBinary(tt.Data)
if !ok {
llvrw.T.Error("Invalid Value provided for return value of ReadBinary.")
return nil, 0x00, nil
}
return data, subtype, nil
default:
llvrw.T.Errorf("Incorrect type provided for return value of ReadBinary: %T", llvrw.Return)
return nil, 0x00, nil
}
}
// ReadBoolean implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadBoolean() (bool, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadBoolean
if llvrw.ErrAfter == llvrw.Invoked {
return false, llvrw.Err
}
switch tt := llvrw.Return.(type) {
case bool:
return tt, nil
case bsoncore.Value:
b, _, ok := bsoncore.ReadBoolean(tt.Data)
if !ok {
llvrw.T.Error("Invalid Value provided for return value of ReadBoolean.")
return false, nil
}
return b, nil
default:
llvrw.T.Errorf("Incorrect type provided for return value of ReadBoolean: %T", llvrw.Return)
return false, nil
}
}
// ReadDocument implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadDocument() (bsonrw.DocumentReader, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadDocument
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// ReadCodeWithScope implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadCodeWithScope() (code string, dr bsonrw.DocumentReader, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadCodeWithScope
if llvrw.ErrAfter == llvrw.Invoked {
return "", nil, llvrw.Err
}
return "", llvrw, nil
}
// ReadDBPointer implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadDBPointer() (ns string, oid primitive.ObjectID, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadDBPointer
if llvrw.ErrAfter == llvrw.Invoked {
return "", primitive.ObjectID{}, llvrw.Err
}
switch tt := llvrw.Return.(type) {
case bsoncore.Value:
ns, oid, _, ok := bsoncore.ReadDBPointer(tt.Data)
if !ok {
llvrw.T.Error("Invalid Value instance provided for return value of ReadDBPointer")
return "", primitive.ObjectID{}, nil
}
return ns, oid, nil
default:
llvrw.T.Errorf("Incorrect type provided for return value of ReadDBPointer: %T", llvrw.Return)
return "", primitive.ObjectID{}, nil
}
}
// ReadDateTime implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadDateTime() (int64, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadDateTime
if llvrw.ErrAfter == llvrw.Invoked {
return 0, llvrw.Err
}
dt, ok := llvrw.Return.(int64)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadDateTime: %T", llvrw.Return)
return 0, nil
}
return dt, nil
}
// ReadDecimal128 implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadDecimal128() (primitive.Decimal128, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadDecimal128
if llvrw.ErrAfter == llvrw.Invoked {
return primitive.Decimal128{}, llvrw.Err
}
d128, ok := llvrw.Return.(primitive.Decimal128)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadDecimal128: %T", llvrw.Return)
return primitive.Decimal128{}, nil
}
return d128, nil
}
// ReadDouble implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadDouble() (float64, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadDouble
if llvrw.ErrAfter == llvrw.Invoked {
return 0, llvrw.Err
}
f64, ok := llvrw.Return.(float64)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadDouble: %T", llvrw.Return)
return 0, nil
}
return f64, nil
}
// ReadInt32 implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadInt32() (int32, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadInt32
if llvrw.ErrAfter == llvrw.Invoked {
return 0, llvrw.Err
}
i32, ok := llvrw.Return.(int32)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadInt32: %T", llvrw.Return)
return 0, nil
}
return i32, nil
}
// ReadInt64 implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadInt64() (int64, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadInt64
if llvrw.ErrAfter == llvrw.Invoked {
return 0, llvrw.Err
}
i64, ok := llvrw.Return.(int64)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadInt64: %T", llvrw.Return)
return 0, nil
}
return i64, nil
}
// ReadJavascript implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadJavascript() (code string, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadJavascript
if llvrw.ErrAfter == llvrw.Invoked {
return "", llvrw.Err
}
js, ok := llvrw.Return.(string)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadJavascript: %T", llvrw.Return)
return "", nil
}
return js, nil
}
// ReadMaxKey implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadMaxKey() error {
llvrw.checkdepth()
llvrw.Invoked = ReadMaxKey
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// ReadMinKey implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadMinKey() error {
llvrw.checkdepth()
llvrw.Invoked = ReadMinKey
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// ReadNull implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadNull() error {
llvrw.checkdepth()
llvrw.Invoked = ReadNull
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// ReadObjectID implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadObjectID() (primitive.ObjectID, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadObjectID
if llvrw.ErrAfter == llvrw.Invoked {
return primitive.ObjectID{}, llvrw.Err
}
oid, ok := llvrw.Return.(primitive.ObjectID)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadObjectID: %T", llvrw.Return)
return primitive.ObjectID{}, nil
}
return oid, nil
}
// ReadRegex implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadRegex() (pattern string, options string, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadRegex
if llvrw.ErrAfter == llvrw.Invoked {
return "", "", llvrw.Err
}
switch tt := llvrw.Return.(type) {
case bsoncore.Value:
pattern, options, _, ok := bsoncore.ReadRegex(tt.Data)
if !ok {
llvrw.T.Error("Invalid Value instance provided for ReadRegex")
return "", "", nil
}
return pattern, options, nil
default:
llvrw.T.Errorf("Incorrect type provided for return value of ReadRegex: %T", llvrw.Return)
return "", "", nil
}
}
// ReadString implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadString() (string, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadString
if llvrw.ErrAfter == llvrw.Invoked {
return "", llvrw.Err
}
str, ok := llvrw.Return.(string)
if !ok {
llvrw.T.Errorf("Incorrect type provided for return value of ReadString: %T", llvrw.Return)
return "", nil
}
return str, nil
}
// ReadSymbol implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadSymbol() (symbol string, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadSymbol
if llvrw.ErrAfter == llvrw.Invoked {
return "", llvrw.Err
}
switch tt := llvrw.Return.(type) {
case string:
return tt, nil
case bsoncore.Value:
symbol, _, ok := bsoncore.ReadSymbol(tt.Data)
if !ok {
llvrw.T.Error("Invalid Value instance provided for ReadSymbol")
return "", nil
}
return symbol, nil
default:
llvrw.T.Errorf("Incorrect type provided for return value of ReadSymbol: %T", llvrw.Return)
return "", nil
}
}
// ReadTimestamp implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadTimestamp() (t uint32, i uint32, err error) {
llvrw.checkdepth()
llvrw.Invoked = ReadTimestamp
if llvrw.ErrAfter == llvrw.Invoked {
return 0, 0, llvrw.Err
}
switch tt := llvrw.Return.(type) {
case bsoncore.Value:
t, i, _, ok := bsoncore.ReadTimestamp(tt.Data)
if !ok {
llvrw.T.Errorf("Invalid Value instance provided for return value of ReadTimestamp")
return 0, 0, nil
}
return t, i, nil
default:
llvrw.T.Errorf("Incorrect type provided for return value of ReadTimestamp: %T", llvrw.Return)
return 0, 0, nil
}
}
// ReadUndefined implements the bsonrw.ValueReader interface.
func (llvrw *ValueReaderWriter) ReadUndefined() error {
llvrw.checkdepth()
llvrw.Invoked = ReadUndefined
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteArray implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteArray() (bsonrw.ArrayWriter, error) {
llvrw.checkdepth()
llvrw.Invoked = WriteArray
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// WriteBinary implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteBinary(b []byte) error {
llvrw.checkdepth()
llvrw.Invoked = WriteBinary
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteBinaryWithSubtype implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteBinaryWithSubtype(b []byte, btype byte) error {
llvrw.checkdepth()
llvrw.Invoked = WriteBinaryWithSubtype
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteBoolean implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteBoolean(bool) error {
llvrw.checkdepth()
llvrw.Invoked = WriteBoolean
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteCodeWithScope implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteCodeWithScope(code string) (bsonrw.DocumentWriter, error) {
llvrw.checkdepth()
llvrw.Invoked = WriteCodeWithScope
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// WriteDBPointer implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteDBPointer(ns string, oid primitive.ObjectID) error {
llvrw.checkdepth()
llvrw.Invoked = WriteDBPointer
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteDateTime implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteDateTime(dt int64) error {
llvrw.checkdepth()
llvrw.Invoked = WriteDateTime
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteDecimal128 implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteDecimal128(primitive.Decimal128) error {
llvrw.checkdepth()
llvrw.Invoked = WriteDecimal128
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteDouble implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteDouble(float64) error {
llvrw.checkdepth()
llvrw.Invoked = WriteDouble
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteInt32 implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteInt32(int32) error {
llvrw.checkdepth()
llvrw.Invoked = WriteInt32
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteInt64 implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteInt64(int64) error {
llvrw.checkdepth()
llvrw.Invoked = WriteInt64
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteJavascript implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteJavascript(code string) error {
llvrw.checkdepth()
llvrw.Invoked = WriteJavascript
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteMaxKey implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteMaxKey() error {
llvrw.checkdepth()
llvrw.Invoked = WriteMaxKey
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteMinKey implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteMinKey() error {
llvrw.checkdepth()
llvrw.Invoked = WriteMinKey
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteNull implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteNull() error {
llvrw.checkdepth()
llvrw.Invoked = WriteNull
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteObjectID implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteObjectID(primitive.ObjectID) error {
llvrw.checkdepth()
llvrw.Invoked = WriteObjectID
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteRegex implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteRegex(pattern string, options string) error {
llvrw.checkdepth()
llvrw.Invoked = WriteRegex
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteString implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteString(string) error {
llvrw.checkdepth()
llvrw.Invoked = WriteString
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteDocument implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteDocument() (bsonrw.DocumentWriter, error) {
llvrw.checkdepth()
llvrw.Invoked = WriteDocument
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// WriteSymbol implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteSymbol(symbol string) error {
llvrw.checkdepth()
llvrw.Invoked = WriteSymbol
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteTimestamp implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteTimestamp(t uint32, i uint32) error {
llvrw.checkdepth()
llvrw.Invoked = WriteTimestamp
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// WriteUndefined implements the bsonrw.ValueWriter interface.
func (llvrw *ValueReaderWriter) WriteUndefined() error {
llvrw.checkdepth()
llvrw.Invoked = WriteUndefined
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// ReadElement implements the bsonrw.DocumentReader interface.
func (llvrw *ValueReaderWriter) ReadElement() (string, bsonrw.ValueReader, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadElement
if llvrw.ErrAfter == llvrw.Invoked {
return "", nil, llvrw.Err
}
return "", llvrw, nil
}
// WriteDocumentElement implements the bsonrw.DocumentWriter interface.
func (llvrw *ValueReaderWriter) WriteDocumentElement(string) (bsonrw.ValueWriter, error) {
llvrw.checkdepth()
llvrw.Invoked = WriteDocumentElement
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// WriteDocumentEnd implements the bsonrw.DocumentWriter interface.
func (llvrw *ValueReaderWriter) WriteDocumentEnd() error {
llvrw.checkdepth()
llvrw.Invoked = WriteDocumentEnd
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}
// ReadValue implements the bsonrw.ArrayReader interface.
func (llvrw *ValueReaderWriter) ReadValue() (bsonrw.ValueReader, error) {
llvrw.checkdepth()
llvrw.Invoked = ReadValue
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// WriteArrayElement implements the bsonrw.ArrayWriter interface.
func (llvrw *ValueReaderWriter) WriteArrayElement() (bsonrw.ValueWriter, error) {
llvrw.checkdepth()
llvrw.Invoked = WriteArrayElement
if llvrw.ErrAfter == llvrw.Invoked {
return nil, llvrw.Err
}
return llvrw, nil
}
// WriteArrayEnd implements the bsonrw.ArrayWriter interface.
func (llvrw *ValueReaderWriter) WriteArrayEnd() error {
llvrw.checkdepth()
llvrw.Invoked = WriteArrayEnd
if llvrw.ErrAfter == llvrw.Invoked {
return llvrw.Err
}
return nil
}