mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 16:34:51 +01:00
Cleanup delta compression
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
package deltacomp
|
package deltacomp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func checkReadUint8(r *bytes.Reader) (uint8, error) {
|
func checkReadUint8(r *bytes.Reader) (uint8, error) {
|
||||||
b, err := r.ReadByte()
|
b, err := r.ReadByte()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -73,7 +72,7 @@ func ApplyDataDiff(diff []byte, baseData []byte) []byte {
|
|||||||
// No more data
|
// No more data
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
differentCount -= 1
|
differentCount--
|
||||||
|
|
||||||
// Apply the patch bytes.
|
// Apply the patch bytes.
|
||||||
for i := 0; i < differentCount; i++ {
|
for i := 0; i < differentCount; i++ {
|
||||||
@@ -90,85 +89,3 @@ func ApplyDataDiff(diff []byte, baseData []byte) []byte {
|
|||||||
|
|
||||||
return baseCopy
|
return baseCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
func checkReadUint8(bf *byteframe.ByteFrame) (uint8, error) {
|
|
||||||
if len(bf.DataFromCurrent()) >= 1 {
|
|
||||||
return bf.ReadUint8(), nil
|
|
||||||
}
|
|
||||||
return 0, errors.New("Not enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkReadUint16(bf *byteframe.ByteFrame) (uint16, error) {
|
|
||||||
if len(bf.DataFromCurrent()) >= 2 {
|
|
||||||
return bf.ReadUint16(), nil
|
|
||||||
}
|
|
||||||
return 0, errors.New("Not enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
func readCount(bf *byteframe.ByteFrame) (int, error) {
|
|
||||||
var count int
|
|
||||||
|
|
||||||
count8, err := checkReadUint8(bf)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
count = int(count8)
|
|
||||||
|
|
||||||
if count == 0 {
|
|
||||||
count16, err := checkReadUint16(bf)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
count = int(count16)
|
|
||||||
}
|
|
||||||
|
|
||||||
return int(count), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyDataDiff applies a delta data diff patch onto given base data.
|
|
||||||
func ApplyDataDiff(diff []byte, baseData []byte) []byte {
|
|
||||||
// Make a copy of the base data to return,
|
|
||||||
// (probably just make this modify the given slice in the future).
|
|
||||||
baseCopy := make([]byte, len(baseData))
|
|
||||||
copy(baseCopy, baseData)
|
|
||||||
|
|
||||||
patch := byteframe.NewByteFrameFromBytes(diff)
|
|
||||||
|
|
||||||
// The very first matchCount is +1 more than it should be, so we start at -1.
|
|
||||||
dataOffset := -1
|
|
||||||
for {
|
|
||||||
// Read the amount of matching bytes.
|
|
||||||
matchCount, err := readCount(patch)
|
|
||||||
if err != nil {
|
|
||||||
// No more data
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
dataOffset += matchCount
|
|
||||||
|
|
||||||
// Read the amount of differing bytes.
|
|
||||||
differentCount, err := readCount(patch)
|
|
||||||
if err != nil {
|
|
||||||
// No more data
|
|
||||||
break
|
|
||||||
}
|
|
||||||
differentCount -= 1
|
|
||||||
|
|
||||||
// Apply the patch bytes.
|
|
||||||
for i := 0; i < differentCount; i++ {
|
|
||||||
b, err := checkReadUint8(patch)
|
|
||||||
if err != nil {
|
|
||||||
panic("Invalid or misunderstood patch format!")
|
|
||||||
}
|
|
||||||
baseCopy[dataOffset+i] = b
|
|
||||||
}
|
|
||||||
|
|
||||||
dataOffset += differentCount - 1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseCopy
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user