Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vng: Use uint64 for Data Lengths #5320

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions vng/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

const (
Version = 4
HeaderSize = 16
HeaderSize = 24
MaxMetaSize = 100 * 1024 * 1024
MaxDataSize = 2 * 1024 * 1024 * 1024
)

type Header struct {
Version uint32
MetaSize uint32
DataSize uint32
MetaSize uint64
DataSize uint64
}

func (h Header) Serialize() []byte {
Expand All @@ -26,8 +26,8 @@ func (h Header) Serialize() []byte {
bytes[1] = 'N'
bytes[2] = 'G'
binary.LittleEndian.PutUint32(bytes[4:], h.Version)
binary.LittleEndian.PutUint32(bytes[8:], h.MetaSize)
binary.LittleEndian.PutUint32(bytes[12:], h.DataSize)
binary.LittleEndian.PutUint64(bytes[8:], h.MetaSize)
binary.LittleEndian.PutUint64(bytes[16:], h.DataSize)
return bytes[:]
}

Expand All @@ -36,8 +36,8 @@ func (h *Header) Deserialize(bytes []byte) error {
return errors.New("invalid VNG header")
}
h.Version = binary.LittleEndian.Uint32(bytes[4:])
h.MetaSize = binary.LittleEndian.Uint32(bytes[8:])
h.DataSize = binary.LittleEndian.Uint32(bytes[12:])
h.MetaSize = binary.LittleEndian.Uint64(bytes[8:])
h.DataSize = binary.LittleEndian.Uint64(bytes[16:])
if h.Version != Version {
return fmt.Errorf("unsupport VNG version %d: expected version %d", h.Version, Version)
}
Expand Down
6 changes: 3 additions & 3 deletions vng/primitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func (p *PrimitiveEncoder) Metadata(off uint64) (uint64, Metadata) {
}
}
loc := Segment{
Offset: int64(off),
Length: int32(len(p.out)),
MemLength: int32(p.bytesLen),
Offset: off,
Length: uint64(len(p.out)),
MemLength: p.bytesLen,
CompressionFormat: p.format,
}
off += uint64(len(p.out))
Expand Down
12 changes: 6 additions & 6 deletions vng/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const (
)

type Segment struct {
Offset int64 // Offset relative to start of file
Length int32 // Length in file
MemLength int32 // Length in memory
CompressionFormat uint8 // Compression format in file
Offset uint64 // Offset relative to start of file
Length uint64 // Length in file
MemLength uint64 // Length in memory
CompressionFormat uint8 // Compression format in file
}

var zbufPool = sync.Pool{
Expand All @@ -36,13 +36,13 @@ func (s *Segment) Read(r io.ReaderAt, b []byte) error {
b = b[:s.MemLength]
switch s.CompressionFormat {
case CompressionFormatNone:
_, err := r.ReadAt(b, s.Offset)
_, err := r.ReadAt(b, int64(s.Offset))
return err
case CompressionFormatLZ4:
zbuf := zbufPool.Get().(*[]byte)
defer zbufPool.Put(zbuf)
*zbuf = slices.Grow((*zbuf)[:0], int(s.Length))[:s.Length]
if _, err := r.ReadAt(*zbuf, s.Offset); err != nil {
if _, err := r.ReadAt(*zbuf, int64(s.Offset)); err != nil {
return err
}
n, err := lz4.UncompressBlock(*zbuf, b)
Expand Down
2 changes: 1 addition & 1 deletion vng/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (w *Writer) finalize() error {
zw.EndStream()
metaSize := zw.Position()
// Header
if _, err := w.writer.Write(Header{Version, uint32(metaSize), uint32(dataSize)}.Serialize()); err != nil {
if _, err := w.writer.Write(Header{Version, uint64(metaSize), dataSize}.Serialize()); err != nil {
return fmt.Errorf("system error: could not write VNG header: %w", err)
}
// Metadata section
Expand Down
2 changes: 1 addition & 1 deletion vng/ztests/const.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ inputs:
outputs:
- name: stdout
data: |
{Version:4(uint32),MetaSize:35(uint32),DataSize:0(uint32)}
{Version:4(uint32),MetaSize:35(uint64),DataSize:0(uint64)}
{Value:1,Count:3(uint32)}(=Const)