-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop.go
More file actions
42 lines (32 loc) · 857 Bytes
/
Copy pathop.go
File metadata and controls
42 lines (32 loc) · 857 Bytes
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
package deltadiff
import (
"encoding/binary"
)
const (
OP_WRITE uint16 = 0
OP_READ uint16 = 1
)
func opRead(from, to int) []byte {
opcodeBytes := make([]byte, 2)
fromBytes := make([]byte, 4)
toBytes := make([]byte, 4)
binary.BigEndian.PutUint16(opcodeBytes, OP_READ)
binary.BigEndian.PutUint32(fromBytes, uint32(from))
binary.BigEndian.PutUint32(toBytes, uint32(to))
op := make([]byte, 0)
op = append(op, opcodeBytes...)
op = append(op, fromBytes...)
op = append(op, toBytes...)
return op
}
func opWrite(data []byte) []byte {
opcodeBytes := make([]byte, 2)
datalenBytes := make([]byte, 4)
binary.BigEndian.PutUint16(opcodeBytes, OP_WRITE)
binary.BigEndian.PutUint32(datalenBytes, uint32(len(data)))
op := make([]byte, 0)
op = append(op, opcodeBytes...)
op = append(op, datalenBytes...)
op = append(op, data...)
return op
}