...
1
2
3
4
5
6
7 package bsonrw
8
9 import (
10 "go.mongodb.org/mongo-driver/bson/bsontype"
11 "go.mongodb.org/mongo-driver/bson/primitive"
12 )
13
14
15
16
17 type ArrayWriter interface {
18 WriteArrayElement() (ValueWriter, error)
19 WriteArrayEnd() error
20 }
21
22
23
24
25 type DocumentWriter interface {
26 WriteDocumentElement(string) (ValueWriter, error)
27 WriteDocumentEnd() error
28 }
29
30
31
32
33 type ValueWriter interface {
34 WriteArray() (ArrayWriter, error)
35 WriteBinary(b []byte) error
36 WriteBinaryWithSubtype(b []byte, btype byte) error
37 WriteBoolean(bool) error
38 WriteCodeWithScope(code string) (DocumentWriter, error)
39 WriteDBPointer(ns string, oid primitive.ObjectID) error
40 WriteDateTime(dt int64) error
41 WriteDecimal128(primitive.Decimal128) error
42 WriteDouble(float64) error
43 WriteInt32(int32) error
44 WriteInt64(int64) error
45 WriteJavascript(code string) error
46 WriteMaxKey() error
47 WriteMinKey() error
48 WriteNull() error
49 WriteObjectID(primitive.ObjectID) error
50 WriteRegex(pattern, options string) error
51 WriteString(string) error
52 WriteDocument() (DocumentWriter, error)
53 WriteSymbol(symbol string) error
54 WriteTimestamp(t, i uint32) error
55 WriteUndefined() error
56 }
57
58
59
60
61 type ValueWriterFlusher interface {
62 ValueWriter
63 Flush() error
64 }
65
66
67
68
69
70
71 type BytesWriter interface {
72 WriteValueBytes(t bsontype.Type, b []byte) error
73 }
74
75
76
77
78 type SliceWriter []byte
79
80
81
82
83 func (sw *SliceWriter) Write(p []byte) (int, error) {
84 written := len(p)
85 *sw = append(*sw, p...)
86 return written, nil
87 }
88
View as plain text