mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-27 07:06:42 +00:00
remove echo :P
This commit is contained in:
parent
ed45314d5a
commit
ee5d4af631
@ -56,8 +56,6 @@ proc deltaEncode*(value: SyncPayload): seq[byte] =
|
|||||||
buf = uint64(lastTimestamp).toBytes(Leb128)
|
buf = uint64(lastTimestamp).toBytes(Leb128)
|
||||||
output &= @buf
|
output &= @buf
|
||||||
|
|
||||||
#echo "First Timestamp: " & $lastTimestamp
|
|
||||||
|
|
||||||
# implicit first fingerprint is always 0 and range type is always skip
|
# implicit first fingerprint is always 0 and range type is always skip
|
||||||
|
|
||||||
for (bound, rangeType) in value.ranges:
|
for (bound, rangeType) in value.ranges:
|
||||||
@ -68,8 +66,6 @@ proc deltaEncode*(value: SyncPayload): seq[byte] =
|
|||||||
buf = timeDiff.toBytes(Leb128)
|
buf = timeDiff.toBytes(Leb128)
|
||||||
output &= @buf
|
output &= @buf
|
||||||
|
|
||||||
#echo "Timestamp: " & $timeDiff
|
|
||||||
|
|
||||||
if timeDiff == 0:
|
if timeDiff == 0:
|
||||||
var sameBytes = 0
|
var sameBytes = 0
|
||||||
for (byte1, byte2) in zip(lastHash, bound.b.fingerprint):
|
for (byte1, byte2) in zip(lastHash, bound.b.fingerprint):
|
||||||
@ -81,8 +77,6 @@ proc deltaEncode*(value: SyncPayload): seq[byte] =
|
|||||||
# encode number of same bytes
|
# encode number of same bytes
|
||||||
output &= byte(sameBytes)
|
output &= byte(sameBytes)
|
||||||
|
|
||||||
#echo "Same Bytes: " & $sameBytes
|
|
||||||
|
|
||||||
# encode fingerprint bytes
|
# encode fingerprint bytes
|
||||||
output &= bound.b.fingerprint[0 ..< sameBytes]
|
output &= bound.b.fingerprint[0 ..< sameBytes]
|
||||||
|
|
||||||
@ -91,14 +85,11 @@ proc deltaEncode*(value: SyncPayload): seq[byte] =
|
|||||||
|
|
||||||
case rangeType
|
case rangeType
|
||||||
of skipRange:
|
of skipRange:
|
||||||
#echo "Skip Range"
|
|
||||||
continue
|
continue
|
||||||
of fingerprintRange:
|
of fingerprintRange:
|
||||||
let fingerprint = value.fingerprints[i]
|
let fingerprint = value.fingerprints[i]
|
||||||
i.inc()
|
i.inc()
|
||||||
|
|
||||||
#echo "Encode Fingerprint"
|
|
||||||
|
|
||||||
output &= fingerprint
|
output &= fingerprint
|
||||||
of itemSetRange:
|
of itemSetRange:
|
||||||
let itemSet = value.itemSets[j]
|
let itemSet = value.itemSets[j]
|
||||||
@ -108,12 +99,8 @@ proc deltaEncode*(value: SyncPayload): seq[byte] =
|
|||||||
buf = uint64(itemSet.elements.len).toBytes(Leb128)
|
buf = uint64(itemSet.elements.len).toBytes(Leb128)
|
||||||
output &= @buf
|
output &= @buf
|
||||||
|
|
||||||
#echo "Set elements: " & $itemSet.elements.len
|
|
||||||
|
|
||||||
let encodedSet = itemSet.deltaEncode()
|
let encodedSet = itemSet.deltaEncode()
|
||||||
|
|
||||||
#echo "Encoded Set"
|
|
||||||
|
|
||||||
output &= encodedSet
|
output &= encodedSet
|
||||||
|
|
||||||
continue
|
continue
|
||||||
@ -135,18 +122,12 @@ proc deltaDecode*(itemSet: var ItemSet, buffer: seq[byte], setLength: int): int
|
|||||||
let time = lastTime + Timestamp(val)
|
let time = lastTime + Timestamp(val)
|
||||||
lastTime = time
|
lastTime = time
|
||||||
|
|
||||||
#echo "Timestamp: " & $time
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
slice = buffer[idx ..< idx + 32]
|
slice = buffer[idx ..< idx + 32]
|
||||||
idx += 32
|
idx += 32
|
||||||
var fingerprint = EmptyFingerprint
|
var fingerprint = EmptyFingerprint
|
||||||
for i, bytes in slice:
|
for i, bytes in slice:
|
||||||
fingerprint[i] = bytes
|
fingerprint[i] = bytes
|
||||||
|
|
||||||
#echo "Hash: " & $fingerprint
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
let id = ID(time: time, fingerprint: fingerprint)
|
let id = ID(time: time, fingerprint: fingerprint)
|
||||||
|
|
||||||
itemSet.elements.add(id)
|
itemSet.elements.add(id)
|
||||||
@ -154,14 +135,9 @@ proc deltaDecode*(itemSet: var ItemSet, buffer: seq[byte], setLength: int): int
|
|||||||
itemSet.reconciled = bool(buffer[idx])
|
itemSet.reconciled = bool(buffer[idx])
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
#echo "Reconciled: " & $itemSet.reconciled
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
||||||
#echo "buffer length: " & $buffer.len
|
|
||||||
|
|
||||||
if buffer.len == 1:
|
if buffer.len == 1:
|
||||||
return SyncPayload()
|
return SyncPayload()
|
||||||
|
|
||||||
@ -178,9 +154,6 @@ proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
|||||||
idx += len
|
idx += len
|
||||||
lastTime = Timestamp(val)
|
lastTime = Timestamp(val)
|
||||||
|
|
||||||
#echo "First Range Timestamp: " & $lastTime
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
# implicit first fingerprint is always 0
|
# implicit first fingerprint is always 0
|
||||||
# implicit first range mode is alway skip
|
# implicit first range mode is alway skip
|
||||||
|
|
||||||
@ -194,32 +167,21 @@ proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
|||||||
idx += len
|
idx += len
|
||||||
let timeDiff = Timestamp(val)
|
let timeDiff = Timestamp(val)
|
||||||
|
|
||||||
#echo "Range Timestamp diff: " & $timeDiff
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
var fingerprint = EmptyFingerprint
|
var fingerprint = EmptyFingerprint
|
||||||
if timeDiff == 0:
|
if timeDiff == 0:
|
||||||
# decode number of same bytes
|
# decode number of same bytes
|
||||||
let sameBytes = int(buffer[idx])
|
let sameBytes = int(buffer[idx])
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
#echo "Same Bytes Count: " & $sameBytes
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
# decode same bytes
|
# decode same bytes
|
||||||
slice = buffer[idx ..< idx + sameBytes]
|
slice = buffer[idx ..< idx + sameBytes]
|
||||||
idx += sameBytes
|
idx += sameBytes
|
||||||
for i, bytes in slice:
|
for i, bytes in slice:
|
||||||
fingerprint[i] = bytes
|
fingerprint[i] = bytes
|
||||||
|
|
||||||
#echo "Same Bytes: " & $fingerprint
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
let thisTime = lastTime + timeDiff
|
let thisTime = lastTime + timeDiff
|
||||||
lastTime = thisTime
|
lastTime = thisTime
|
||||||
|
|
||||||
#echo "Range Timestamp: " & $thisTime
|
|
||||||
|
|
||||||
let upperRangeBound = ID(time: thisTime, fingerprint: fingerprint)
|
let upperRangeBound = ID(time: thisTime, fingerprint: fingerprint)
|
||||||
|
|
||||||
let bounds = lowerRangeBound .. upperRangeBound
|
let bounds = lowerRangeBound .. upperRangeBound
|
||||||
@ -228,9 +190,6 @@ proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
|||||||
let rangeType = RangeType(buffer[idx])
|
let rangeType = RangeType(buffer[idx])
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
#echo "Range Type: " & $rangeType
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
payload.ranges.add((bounds, rangeType))
|
payload.ranges.add((bounds, rangeType))
|
||||||
|
|
||||||
if rangeType == fingerprintRange:
|
if rangeType == fingerprintRange:
|
||||||
@ -241,9 +200,6 @@ proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
|||||||
for i, bytes in slice:
|
for i, bytes in slice:
|
||||||
fingerprint[i] = bytes
|
fingerprint[i] = bytes
|
||||||
|
|
||||||
#echo "Fingerprint: " & $fingerprint
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
payload.fingerprints.add(fingerprint)
|
payload.fingerprints.add(fingerprint)
|
||||||
elif rangeType == itemSetRange:
|
elif rangeType == itemSetRange:
|
||||||
# decode item set length
|
# decode item set length
|
||||||
@ -253,18 +209,12 @@ proc deltaDecode*(T: type SyncPayload, buffer: seq[byte]): T =
|
|||||||
idx += len
|
idx += len
|
||||||
let itemSetLength = int(val)
|
let itemSetLength = int(val)
|
||||||
|
|
||||||
#echo "Set length: " & $itemSetLength
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
# decode item set
|
# decode item set
|
||||||
var itemSet = ItemSet()
|
var itemSet = ItemSet()
|
||||||
slice = buffer[idx ..< buffer.len]
|
slice = buffer[idx ..< buffer.len]
|
||||||
let count = deltaDecode(itemSet, slice, itemSetLength)
|
let count = deltaDecode(itemSet, slice, itemSetLength)
|
||||||
idx += count
|
idx += count
|
||||||
|
|
||||||
#echo "Set Decoded"
|
|
||||||
#echo "IDX: " & $idx
|
|
||||||
|
|
||||||
payload.itemSets.add(itemSet)
|
payload.itemSets.add(itemSet)
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
|
Loading…
x
Reference in New Issue
Block a user