forked from dtn7/cboring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
primitives.go
71 lines (55 loc) · 1.99 KB
/
primitives.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
package cboring
import "io"
/*** Uint ***/
// ReadUInt expects an unsigned integer at the Reader's position and returns it.
func ReadUInt(r io.Reader) (n uint64, err error) {
return ReadExpectMajors(UInt, r)
}
// WriteUInt serializes an unsigned integer into the Writer.
func WriteUInt(n uint64, w io.Writer) error {
return WriteMajors(UInt, n, w)
}
/*** ByteString ***/
// ReadByteStringLen expects a byte string at the Reader's position and returns
// the byte string's length.
func ReadByteStringLen(r io.Reader) (n uint64, err error) {
return ReadExpectMajors(ByteString, r)
}
// WriteByteStringLen writes the type definition for a byte string with the
// given length into the Writer.
func WriteByteStringLen(n uint64, w io.Writer) error {
return WriteMajors(ByteString, n, w)
}
/*** TextString ***/
// ReadTextStringLen expects a text string at the Reader's position and returns
// the text string's length.
func ReadTextStringLen(r io.Reader) (n uint64, err error) {
return ReadExpectMajors(TextString, r)
}
// WriteTextStringLen writes the type definition for a text string with the
// given length into the Writer.
func WriteTextStringLen(n uint64, w io.Writer) error {
return WriteMajors(TextString, n, w)
}
/*** Array ***/
// ReadArrayLength expects an array at the Reader's position and returns its
// length.
func ReadArrayLength(r io.Reader) (n uint64, err error) {
return ReadExpectMajors(Array, r)
}
// WriteArrayLength writes the type definition for an array with the given
// length into the Writer.
func WriteArrayLength(n uint64, w io.Writer) error {
return WriteMajors(Array, n, w)
}
/*** Map ***/
// ReadMapPairLength expects a map at the Reader's position and returns the
// amount of pairs stored.
func ReadMapPairLength(r io.Reader) (n uint64, err error) {
return ReadExpectMajors(Map, r)
}
// WriteMapPairLength writes the type definition for a map with the given
// amount of pairs into the Writer.
func WriteMapPairLength(n uint64, w io.Writer) error {
return WriteMajors(Map, n, w)
}