func (p *PackIndex) UnmarshalBinary(data []byte) error {
	b := bytes.NewBuffer(data)
	var psum sum.Sum
	if _, err := b.Read(psum[:]); err != nil {
		return err
	}
	size, err := getBinaryUint64(b)
	if err != nil {
		return err
	}
	nBlocks, err := getBinaryUint64(b)
	if err != nil {
		return err
	}
	if nBlocks > maxBlocks {
		return fmt.Errorf("number of blocks %d exceeds limit %d", nBlocks, maxBlocks)
	}
	blocks := make([]BlockInfo, nBlocks)
	for i := uint64(0); i < nBlocks; i++ {
		block := &blocks[i]
		block.unmarshalBinary(b)
	}
	p.Sum = psum
	p.Blocks = blocks
	p.Size = size
	return nil
}
UnmarshalBinary reads a pack index from its binary format.
package object
import (
	"bytes"
	"encoding/binary"
	"fmt"
	"io"
	"github.com/jotfs/jotfs/internal/compress"
	"github.com/jotfs/jotfs/internal/sum"
)
const maxBlocks = 10_000
type BlockInfo struct {
	Sum sum.Sum
	ChunkSize uint64
	Sequence uint64
	Offset uint64
	Size uint64
	Mode compress.Mode
}
type PackIndex struct {
	Blocks []BlockInfo
	Sum sum.Sum
	Size uint64
}
func (p *PackIndex) MarshalBinary() []byte {
	b := make([]byte, 0)
	b = append(b, p.Sum[:]...)
	b = append(b, uint64Binary(p.Size)...)
	b = append(b, uint64Binary(uint64(len(p.Blocks)))...)
	for _, bck := range p.Blocks {
		b = bck.marshalBinary(b)
	}
	return b
}