diff --git a/pmtiles/makesync.go b/pmtiles/makesync.go index bab39a0..d56602d 100644 --- a/pmtiles/makesync.go +++ b/pmtiles/makesync.go @@ -43,19 +43,15 @@ func SerializeSyncBlocks(output io.Writer, blocks []SyncBlock) { var n int lastStartId := uint64(0) - lastOffset := uint64(0) for _, block := range blocks { n = binary.PutUvarint(tmp, uint64(block.Start-lastStartId)) output.Write(tmp[:n]) - n = binary.PutUvarint(tmp, uint64(block.Offset-lastOffset)) - output.Write(tmp[:n]) n = binary.PutUvarint(tmp, uint64(block.Length)) output.Write(tmp[:n]) binary.LittleEndian.PutUint64(tmp, block.Hash) output.Write(tmp[0:8]) lastStartId = block.Start - lastOffset = block.Offset } } @@ -63,18 +59,17 @@ func DeserializesyncBlocks(num_blocks int, reader *bufio.Reader) []SyncBlock { blocks := make([]SyncBlock, 0) lastStartId := uint64(0) - lastOffset := uint64(0) + offset := uint64(0) buf := make([]byte, 8) for i := 0; i < num_blocks; i++ { start, _ := binary.ReadUvarint(reader) - offset, _ := binary.ReadUvarint(reader) length, _ := binary.ReadUvarint(reader) _, _ = io.ReadFull(reader, buf) - blocks = append(blocks, SyncBlock{Start: lastStartId + start, Offset: lastOffset + offset, Length: length, Hash: binary.LittleEndian.Uint64(buf)}) + blocks = append(blocks, SyncBlock{Start: lastStartId + start, Offset: offset, Length: length, Hash: binary.LittleEndian.Uint64(buf)}) lastStartId = lastStartId + start - lastOffset = lastOffset + offset + offset = offset + length } return blocks