-
Notifications
You must be signed in to change notification settings - Fork 17
/
tlv_test.go
100 lines (80 loc) · 1.87 KB
/
tlv_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package betwixt
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreateIdentifierField(t *testing.T) {
var id []byte
id = CreateTlvIdentifierField(1)
assert.Equal(t, []byte{1}, id)
id = CreateTlvIdentifierField(10)
assert.Equal(t, []byte{10}, id)
id = CreateTlvIdentifierField(100)
assert.Equal(t, []byte{100}, id)
id = CreateTlvIdentifierField(1000)
assert.Equal(t, []byte{232, 3}, id)
id = CreateTlvIdentifierField(10000)
assert.Equal(t, []byte{16, 39}, id)
}
func TestCreateTlvTypeField(t *testing.T) {
/*
func CreateTlvTypeField(identType byte, value interface{}, ident uint16) byte {
var typeField byte
valueTypeLength, _ := typeval.GetValueByteLength(value)
// Bit 7-6: identifier
typeField |= identType
// Bit 5
if ident > 255 {
typeField |= 32
}
// Bit 4-3
if valueTypeLength > 7 {
if valueTypeLength < 256 {
typeField |= 8
} else {
if valueTypeLength < 65535 {
typeField |= 16
} else {
if valueTypeLength > 16777215 {
// Error, size exceeds allowed (> 16.7MB)
} else {
// Size is 16777215 or less
typeField |= 24
}
}
}
} else {
// Set bit 2-0 instead
b := byte(valueTypeLength)
typeField |= b
}
return typeField
}
*/
}
func TestCreateTlvLengthField(t *testing.T) {
}
/*
func CreateTlvLengthField(value interface{}) []byte {
valueTypeLength, _ := typeval.GetValueByteLength(value)
if valueTypeLength > 7 {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, valueTypeLength)
return bytes.Trim(buf.Bytes(), "\x00")
}
return []byte{}
}
*/
func TestCreateTlvValueField(t *testing.T) {
}
/*
func CreateTlvValueField(value int) []byte {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, uint64(value))
if value == 0 {
return []byte{0}
} else {
return bytes.Trim(buf.Bytes(), "\x00")
}
}
*/