Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 30.76% |
Changes | 0 |
1 | package encode |
||
2 | |||
3 | import ( |
||
4 | "encoding" |
||
5 | "reflect" |
||
6 | |||
7 | "github.com/et-nik/binngo/binn" |
||
8 | ) |
||
9 | |||
10 | func String(s string) []byte { |
||
11 | 1 | var t []byte |
|
12 | |||
13 | 1 | t = append(t, Size(len(s), false)...) |
|
14 | 1 | t = append(t, []byte(s)...) |
|
15 | |||
16 | 1 | return t |
|
17 | } |
||
18 | |||
19 | func textMarshalerEncoder(v reflect.Value) ([]byte, error) { |
||
20 | if v.Kind() == reflect.Ptr && v.IsNil() { |
||
21 | return []byte{binn.Null}, nil |
||
22 | } |
||
23 | |||
24 | m, ok := v.Interface().(encoding.TextMarshaler) |
||
25 | if !ok { |
||
26 | return []byte{binn.Null}, nil |
||
27 | } |
||
28 | b, err := m.MarshalText() |
||
29 | if err != nil { |
||
30 | return nil, err |
||
31 | } |
||
32 | |||
33 | return String(string(b)), nil |
||
34 | } |
||
35 |