encode/ptr_encoder.go   A
last analyzed

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
cc 3
eloc 13
dl 0
loc 23
c 0
b 0
f 0
ccs 0
cts 5
cp 0
crap 12
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode.ptrEncoder.encode 0 6 2
A encode.newPtrEncoder 0 3 1
1
package encode
2
3
import (
4
	"reflect"
5
6
	"github.com/et-nik/binngo/binn"
7
)
8
9
type ptrEncoder struct {
10
	elemEnc encoderFunc
11
}
12
13
func newPtrEncoder(t reflect.Type) encoderFunc {
14
	enc := ptrEncoder{newTypeEncoder(t.Elem())}
15
	return enc.encode
16
}
17
18
func (pe ptrEncoder) encode(v reflect.Value) ([]byte, error) {
19
	if v.IsNil() {
20
		return []byte{binn.Null}, nil
21
	}
22
23
	return pe.elemEnc(v.Elem())
24
}
25