Skip to content

Commit f1a03ad

Browse files
committed
add bytes delta
1 parent 1811a6e commit f1a03ad

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

Diff for: byte.go

-39
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,3 @@ package delta
33
// ToByteSliceDelta 不单独实现了,直接认为是int的一种特殊情况,为了调用方的代码可读性这里就给个别名
44
var ToByteSliceDelta = ToIntegerSliceDelta[byte]
55
var FromByteSliceDelta = FromIntegerSliceDelta[byte]
6-
7-
//// ToByteSliceDelta 字节数组
8-
//func ToByteSliceDelta(bytes []byte, compareToType CompareToType) []byte {
9-
// deltaSlice := make([]byte, 0)
10-
// for index, byteValue := range bytes {
11-
// if index == 0 {
12-
// deltaSlice[index] = byteValue
13-
// continue
14-
// }
15-
// switch compareToType {
16-
// case CompareToFirst:
17-
// deltaSlice[index] = byteValue - bytes[0]
18-
// case CompareToLast:
19-
// deltaSlice[index] = byteValue - bytes[index-1]
20-
// default:
21-
// panic(fmt.Errorf("not support compare type: %#v", compareToType))
22-
// }
23-
// }
24-
// return deltaSlice
25-
//}
26-
27-
//func FromByteSliceDelta(deltaSlice []byte, compareToType CompareToType) []byte {
28-
// bytes := make([]byte, 0)
29-
// for index, delta := range deltaSlice {
30-
// if index == 0 {
31-
// bytes[index] = delta
32-
// continue
33-
// }
34-
// switch compareToType {
35-
// case CompareToFirst:
36-
// bytes[index] = bytes[index-1] + delta
37-
// case CompareToLast:
38-
// bytes[index] = bytes[index-1] + delta
39-
// default:
40-
// panic(fmt.Errorf("not support compare type: %#v", compareToType))
41-
// }
42-
// }
43-
// return bytes
44-
//}

Diff for: byte_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package delta
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestToByteSliceDelta(t *testing.T) {
9+
bytes := []byte{1, 2, 3, 4, 5}
10+
//t.Log(bytes)
11+
deltaSlice := ToByteSliceDelta(bytes, CompareToLast)
12+
//t.Log(deltaSlice)
13+
originalBytes := FromByteSliceDelta(deltaSlice, CompareToLast)
14+
//t.Log(originalBytes)
15+
assert.Equal(t, bytes, originalBytes)
16+
}

0 commit comments

Comments
 (0)