blob: ecae7391d5622327c36df25b54c94e46ff1a6fba [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package bsonrw
8
9import (
10 "github.com/mongodb/mongo-go-driver/bson/bsontype"
11 "github.com/mongodb/mongo-go-driver/bson/primitive"
12)
13
14// ArrayReader is implemented by types that allow reading values from a BSON
15// array.
16type ArrayReader interface {
17 ReadValue() (ValueReader, error)
18}
19
20// DocumentReader is implemented by types that allow reading elements from a
21// BSON document.
22type DocumentReader interface {
23 ReadElement() (string, ValueReader, error)
24}
25
26// ValueReader is a generic interface used to read values from BSON. This type
27// is implemented by several types with different underlying representations of
28// BSON, such as a bson.Document, raw BSON bytes, or extended JSON.
29type ValueReader interface {
30 Type() bsontype.Type
31 Skip() error
32
33 ReadArray() (ArrayReader, error)
34 ReadBinary() (b []byte, btype byte, err error)
35 ReadBoolean() (bool, error)
36 ReadDocument() (DocumentReader, error)
37 ReadCodeWithScope() (code string, dr DocumentReader, err error)
38 ReadDBPointer() (ns string, oid primitive.ObjectID, err error)
39 ReadDateTime() (int64, error)
40 ReadDecimal128() (primitive.Decimal128, error)
41 ReadDouble() (float64, error)
42 ReadInt32() (int32, error)
43 ReadInt64() (int64, error)
44 ReadJavascript() (code string, err error)
45 ReadMaxKey() error
46 ReadMinKey() error
47 ReadNull() error
48 ReadObjectID() (primitive.ObjectID, error)
49 ReadRegex() (pattern, options string, err error)
50 ReadString() (string, error)
51 ReadSymbol() (symbol string, err error)
52 ReadTimestamp() (t, i uint32, err error)
53 ReadUndefined() error
54}
55
56// BytesReader is a generic interface used to read BSON bytes from a
57// ValueReader. This imterface is meant to be a superset of ValueReader, so that
58// types that implement ValueReader may also implement this interface.
59//
60// The bytes of the value will be appended to dst.
61type BytesReader interface {
62 ReadValueBytes(dst []byte) (bsontype.Type, []byte, error)
63}