MCPcopy Create free account
hub / github.com/DNAProject/DNA / TestSerialize

Function TestSerialize

common/serialization/serialize_test.go:122–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestSerialize(t *testing.T) {
123 b := new(bytes.Buffer)
124 a3 := uint8(100)
125 a4 := uint16(65535)
126 a5 := uint32(4294967295)
127 a6 := uint64(18446744073709551615)
128 a7 := uint64(18446744073709551615)
129 a8 := []byte{10, 11, 12}
130 a9 := "hello onchain."
131
132 WriteVarUint(b, uint64(a3))
133 WriteVarUint(b, uint64(a4))
134 WriteVarUint(b, uint64(a5))
135 WriteVarUint(b, uint64(a6))
136 WriteVarUint(b, uint64(a7))
137 WriteVarBytes(b, a8)
138 WriteString(b, a9)
139
140 fmt.Println(ReadVarUint(b, math.MaxUint64))
141 fmt.Println(ReadVarUint(b, math.MaxUint64))
142 fmt.Println(ReadVarUint(b, math.MaxUint64))
143 fmt.Println(ReadVarUint(b, math.MaxUint64))
144 fmt.Println(ReadVarUint(b, math.MaxUint32))
145 fmt.Println(ReadVarBytes(b))
146 fmt.Println(ReadString(b))
147
148 fmt.Printf("100 size is %d byte.\t\n", GetVarUintSize(uint64(100)))
149 fmt.Printf("65535 size is %d byte.\t\n", GetVarUintSize(uint64(65535)))
150 fmt.Printf("4294967295 size is %d byte.\t\n", GetVarUintSize(uint64(4294967295)))
151 fmt.Printf("18446744073709551615 size is %d byte.\t\n", GetVarUintSize(uint64(18446744073709551615)))
152
153 b.WriteByte(20)
154 b.WriteByte(21)
155 b.WriteByte(22)
156 fmt.Println(ReadBytes(b, uint64(3)))
157
158}
159
160func TestReadWriteInt(t *testing.T) {
161 b3 := new(bytes.Buffer)

Callers

nothing calls this directly

Calls 9

WriteVarUintFunction · 0.85
WriteVarBytesFunction · 0.85
WriteStringFunction · 0.85
ReadVarUintFunction · 0.85
ReadVarBytesFunction · 0.85
ReadStringFunction · 0.85
GetVarUintSizeFunction · 0.85
ReadBytesFunction · 0.85
WriteByteMethod · 0.80

Tested by

no test coverage detected