zc

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package zc provides helpers for working with zero-copy ranges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtractFrom

type ExtractFrom struct {
	Src *byte
}

ExtractFrom is a helper for creating extraction funcs. It exists to work around an inliner limitation.

func (ExtractFrom) Bytes

func (e ExtractFrom) Bytes(raw uint64) []byte

ExtractBytes returns a func that calls Range.Bytes.

This exists to work around inlining failure in certain places in the parser.

type Range

type Range uint64

Range is a representation of a []byte as a slice relative to some larger byte array, such as the source of a parsed message.

This is a packed representation of a value with the layout

struct {
  offset, len uint32
}

The zero value faithfully represents an empty slice.

func New

func New(src *byte, start *byte, len int) Range

New creates a new Range over the given source buffer with the given start and length.

func NewRaw

func NewRaw(offset, len int) Range

NewRaw is like newZC, but it only takes the offset and length.

func (Range) Bytes

func (r Range) Bytes(src *byte) []byte

Bytes converts this Range into a byte slice, given its source.

NOTE: Go refuses to inline this function sometimes. Range.String does not appear to have this problem.

func (Range) End

func (r Range) End() int

End returns the end offset of this slice within its source.

func (Range) Format

func (r Range) Format(s fmt.State, verb rune)

Format implements fmt.Formatter.

func (Range) Len

func (r Range) Len() int

Len returns the length of this Range.

func (Range) Start

func (r Range) Start() int

Start returns the start offset of this slice within its source.

func (Range) String

func (r Range) String(src *byte) string

String converts this Range into a string, given its source.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL