-
Notifications
You must be signed in to change notification settings - Fork 69
/
decoder.go
55 lines (43 loc) · 1008 Bytes
/
decoder.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
package dongle
import "fmt"
type Decoder struct {
dongle
}
type DecodeError struct {
}
func NewDecodeError() DecodeError {
return DecodeError{}
}
func (e DecodeError) ModeError(mode string) error {
return fmt.Errorf("decode: invalid decoding mode, the src can't be decoded by %s", mode)
}
var decodeError = NewDecodeError()
// newDecoder returns a new Decoder instance.
func newDecoder() Decoder {
return Decoder{}
}
// FromString decodes from string.
func (d Decoder) FromString(s string) Decoder {
d.src = string2bytes(s)
return d
}
// FromBytes decodes from byte slice.
func (d Decoder) FromBytes(b []byte) Decoder {
d.src = b
return d
}
// String implements Stringer interface for Decoder struct.
func (d Decoder) String() string {
return d.ToString()
}
// ToString outputs as string.
func (d Decoder) ToString() string {
return bytes2string(d.dst)
}
// ToBytes outputs as byte slice.
func (d Decoder) ToBytes() []byte {
if len(d.dst) == 0 {
return []byte("")
}
return d.dst
}