-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
65 lines (51 loc) · 1.68 KB
/
utils.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
// Copyright 2020 Erin Shepherd
// SPDX-License-Identifier: ISC
package xdr
import (
"io"
"reflect"
xdrinterfaces "go.e43.eu/xdr/interfaces"
"go.e43.eu/xdr/internal/coder"
)
type defaultCoder struct {
coder.Coder
}
func (d *defaultCoder) RegisterCodec(template interface{}, c xdrinterfaces.Codec) {
panic("Cannot register type on default codec")
}
func (d *defaultCoder) RegisterCodecReflect(type_ reflect.Type, c xdrinterfaces.Codec) {
panic("Cannot register type on default codec")
}
// The default coder (used by the package global functions)
//
// This behaves identically to a coder created using NewCoder, except
// that it is not permitted to register any codecs upon it.
var DefaultCoder defaultCoder
// Marshal marshals o into the returned buffer using DefaultCoder
func Marshal(o interface{}) ([]byte, error) {
return DefaultCoder.Marshal(o)
}
// Unmarshal unmarshals buf into the object pointed to by op using DefaultCoder
func Unmarshal(buf []byte, op interface{}) error {
return DefaultCoder.Unmarshal(buf, op)
}
// Write marshals o into the passed writer using DefaultCoder
func Write(w io.Writer, o interface{}) error {
return DefaultCoder.Write(w, o)
}
// Read unmarshals *op out of the passed reader using DefaultCoder
func Read(r io.Reader, op interface{}) error {
return DefaultCoder.Read(r, op)
}
// NewEncoder constructs a new encoder which writes to w using DefaultCoder
func NewEncoder(w io.Writer) Encoder {
return DefaultCoder.NewEncoder(w)
}
// Constructs a new decoder which reads from r using DefaultCoder
func NewDecoder(r io.Reader) Decoder {
return DefaultCoder.NewDecoder(r)
}
// NewCoder Construct a new Coder
func NewCoder() Coder {
return coder.NewCoder()
}