packed: switch gogo/proto → google

This commit is contained in:
Laurence Withers 2026-06-06 11:00:04 +01:00
commit 357f702925
5 changed files with 345 additions and 1113 deletions

View file

@ -8,6 +8,7 @@ import (
"strings"
"golang.org/x/sys/unix"
"google.golang.org/protobuf/proto"
)
const (
@ -130,7 +131,7 @@ func Load(f *os.File) (*Header, *Directory, error) {
// as type LoadError.
func readHeader(f []byte) (*Header, error) {
hdr := new(Header)
if err := hdr.Unmarshal(f[:36]); err != nil {
if err := proto.Unmarshal(f[:36], hdr); err != nil {
return nil, &LoadError{
Cause: HeaderUnmarshalError,
Underlying: err,
@ -166,15 +167,17 @@ func readHeader(f []byte) (*Header, error) {
// read/checksummed).
func readDirectory(f []byte, hdr *Header) (*Directory, error) {
fileSize := uint64(len(f))
start := hdr.DirectoryOffset
end := start + hdr.DirectoryLength
if hdr.DirectoryOffset+hdr.DirectoryLength > fileSize {
if end > fileSize {
return nil, &LoadError{
Cause: BadOffsetError,
}
}
dir := new(Directory)
if err := dir.Unmarshal(f[hdr.DirectoryOffset : hdr.DirectoryOffset+hdr.DirectoryLength]); err != nil {
if err := proto.Unmarshal(f[start:end], dir); err != nil {
return nil, &LoadError{
Cause: DirectoryUnmarshalError,
Underlying: err,

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
syntax = "proto3";
package packed;
package lwithers.htpack.packed;
option go_package = "src.lwithers.me.uk/htpack/packed";
// Header at start of file. This must be a fixed, known size. Fields cannot
// be zero.
@ -54,6 +55,6 @@ message FileData {
// the pack.
fixed64 offset = 1;
// Length is the
// Length of the (possibly compressed) file data, in bytes.
fixed64 length = 2;
}