+5
-3
atproto/data/blob.go
+5
-3
atproto/data/blob.go
···
10
10
cbg "github.com/whyrusleeping/cbor-gen"
11
11
)
12
12
13
-
// used in schemas, and can represent either a legacy blob or a "new" (lex
14
-
// refactor) blob. size=-1 indicates that this is (and should be serialized as)
15
-
// a legacy blob (string CID, no size, etc).
13
+
// Represents the "blob" type from the atproto data model.
14
+
//
15
+
// This struct does not get marshaled/unmarshaled directly in to JSON or CBOR; see the BlobSchema and LegacyBlobSchema structs. This is the type that should be included in golang struct definitions.
16
+
//
17
+
// When representing a "legacy" blob (no size field, string CID), size == -1.
16
18
type Blob struct {
17
19
Ref CIDLink
18
20
MimeType string
+5
atproto/data/bytes.go
+5
atproto/data/bytes.go
···
9
9
cbg "github.com/whyrusleeping/cbor-gen"
10
10
)
11
11
12
+
// Represents the "bytes" type from the atproto data model.
13
+
//
14
+
// In JSON, marshals to an object with $bytes key and base64-encoded data.
15
+
//
16
+
// In CBOR, marshals to a byte array.
12
17
type Bytes []byte
13
18
14
19
type JsonBytes struct {
+19
-6
atproto/data/cidlink.go
+19
-6
atproto/data/cidlink.go
···
9
9
cbg "github.com/whyrusleeping/cbor-gen"
10
10
)
11
11
12
+
// Represents the "cid-link" type from the atproto data model.
13
+
//
14
+
// Implementation is a simple wrapper around the github.com/ipfs/go-cid "cid.Cid" type.
12
15
type CIDLink cid.Cid
13
16
14
17
type jsonLink struct {
15
18
Link string `json:"$link"`
16
19
}
17
20
18
-
// convenience helper
21
+
// Unwraps the inner cid.Cid type (github.com/ipfs/go-cid)
22
+
func (ll CIDLink) CID() cid.Cid {
23
+
return cid.Cid(ll)
24
+
}
25
+
26
+
// Returns string representation.
27
+
//
28
+
// If the CID is "undefined", returns an empty string (note that this is different from how cid.Cid works).
19
29
func (ll CIDLink) String() string {
20
-
return cid.Cid(ll).String()
30
+
if ll.IsDefined() {
31
+
return cid.Cid(ll).String()
32
+
}
33
+
return ""
21
34
}
22
35
23
-
// convenience helper
24
-
func (ll CIDLink) Defined() bool {
36
+
// Convenience helper, returns false if CID is "undefined" (golang zero value)
37
+
func (ll CIDLink) IsDefined() bool {
25
38
return cid.Cid(ll).Defined()
26
39
}
27
40
28
41
func (ll CIDLink) MarshalJSON() ([]byte, error) {
29
-
if !ll.Defined() {
42
+
if !ll.IsDefined() {
30
43
return nil, fmt.Errorf("tried to marshal nil or undefined cid-link")
31
44
}
32
45
jl := jsonLink{
···
54
67
_, err := w.Write(cbg.CborNull)
55
68
return err
56
69
}
57
-
if !ll.Defined() {
70
+
if !ll.IsDefined() {
58
71
return fmt.Errorf("tried to marshal nil or undefined cid-link")
59
72
}
60
73
cw := cbg.NewCborWriter(w)
+25
-12
atproto/data/const.go
+25
-12
atproto/data/const.go
···
1
1
package data
2
2
3
3
const (
4
-
MAX_OBJECT_KEY_LEN = 8192
5
-
MAX_CBOR_SIZE = 5 * 1024 * 1024
6
-
MAX_CBOR_RECORD_SIZE = 1 * 1024 * 1024
7
-
MAX_JSON_RECORD_SIZE = 2 * 1024 * 1024
4
+
// maximum size of any CBOR data, in any context, in atproto
5
+
MAX_CBOR_SIZE = 5 * 1024 * 1024
6
+
// maximum serialized size of an individual atproto record, in CBOR format
7
+
MAX_CBOR_RECORD_SIZE = 1 * 1024 * 1024
8
+
// maximum serialized size of an individual atproto record, in JSON format
9
+
MAX_JSON_RECORD_SIZE = 2 * 1024 * 1024
10
+
// maximum serialized size of blocks (raw bytes) in an atproto repo stream event
8
11
MAX_STREAM_REPO_DIFF_SIZE = 4 * 1024 * 1024
9
-
MAX_STREAM_FRAME_SIZE = MAX_CBOR_SIZE
10
-
MAX_RECORD_STRING_LEN = MAX_CBOR_RECORD_SIZE
11
-
MAX_RECORD_BYTES_LEN = MAX_CBOR_RECORD_SIZE
12
-
MAX_CID_BYTES = 100
13
-
MAX_CBOR_NESTED_LEVELS = 32
14
-
MAX_CBOR_CONTAINER_LEN = 128 * 1024
15
-
MAX_SAFE_INTEGER = 9007199254740991
16
-
MIN_SAFE_INTEGER = -9007199254740991
12
+
// maximum size of a WebSocket frame in atproto event streams
13
+
MAX_STREAM_FRAME_SIZE = MAX_CBOR_SIZE
14
+
// maximum size of any individual string inside an atproto record
15
+
MAX_RECORD_STRING_LEN = MAX_CBOR_RECORD_SIZE
16
+
// maximum size of any individual byte array (bytestring) inside an atproto record
17
+
MAX_RECORD_BYTES_LEN = MAX_CBOR_RECORD_SIZE
18
+
// limit on size of CID representation
19
+
MAX_CID_BYTES = 100
20
+
// limit on depth of nested containers (objects or arrays) for atproto data
21
+
MAX_CBOR_NESTED_LEVELS = 32
22
+
// maximum number of elements in an object or array in atproto data
23
+
MAX_CBOR_CONTAINER_LEN = 128 * 1024
24
+
// largest integer which can be represented in a float64. integers in atproto "should" not be larger than this.
25
+
MAX_SAFE_INTEGER = 9007199254740991
26
+
// largest negative integer which can be represented in a float64. integers in atproto "should" not go below this.
27
+
MIN_SAFE_INTEGER = -9007199254740991
28
+
// maximum length of string (UTF-8 bytes) in an atproto object (map)
29
+
MAX_OBJECT_KEY_LEN = 8192
17
30
)