Skip to content

(*Decoder).Offset should return an error #193

Description

@oschwald

It is now resolving pointers, which could fail. We are ignoring the error currently to prevent a breaking API change:

func (d *Decoder) Offset() uint {
// Follow pointer chain to get resolved data location
dataOffset := d.offset
for {
kindNum, size, ctrlEndOffset, err := d.d.decodeCtrlData(dataOffset)
if err != nil {
// Return original offset to avoid breaking the public API.
// Offset() returns uint (not (uint, error)), so we can't propagate errors.
// In practice, errors here are rare and the original offset is still valid.
return d.offset
}
if kindNum != KindPointer {
// dataOffset is now pointing at the actual data (not a pointer)
// Return this offset, which is where the data's control bytes start
break
}
// Follow the pointer to get the target offset
dataOffset, _, err = d.d.decodePointer(size, ctrlEndOffset)
if err != nil {
// Return original offset to avoid breaking the public API.
// The caller will encounter the same error when they try to read.
return d.offset
}
// dataOffset is now the pointer target; loop to check if it's also a pointer
}
return dataOffset
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions