add String method

This commit is contained in:
lionsoul2014 2025-12-04 13:13:10 +08:00
parent a220db2345
commit 540831e6a9
2 changed files with 14 additions and 0 deletions

View File

@ -76,3 +76,10 @@ func NewHeader(input []byte) (*Header, error) {
RuntimePtrBytes: int(binary.LittleEndian.Uint16(input[18:])),
}, nil
}
func (h *Header) String() string {
return fmt.Sprintf(
"{version:%d, index_policy:%d, created_at:%d, start_index_ptr:%d, end_index_ptr:%d, ip_version:%d, runtime_ptr_bytes:%d}",
h.Version, h.IndexPolicy, h.CreatedAt, h.StartIndexPtr, h.EndIndexPtr, h.IPVersion, h.RuntimePtrBytes,
)
}

View File

@ -20,6 +20,13 @@ type Version struct {
IPCompare func([]byte, []byte) int
}
func (v *Version) String() string {
return fmt.Sprintf(
"id:%d, name:%s, bytes:%d, segment_index_size:%d",
v.Id, v.Name, v.Bytes, v.SegmentIndexSize,
)
}
const (
IPv4VersionNo = 4
IPv6VersionNo = 6