Documentation
¶
Overview ¶
Package source owns the original encoded bytes used by the YAML engine.
It is the source/decoder checkpoint of wiki spec 0008 (D3, D78, D79 and D182), not a YAML parser. The existing public package is not yet wired to this engine. Buffers are immutable; returned byte slices are copies. Admission requires an explicit byte limit until measured public defaults have been approved.
Index ¶
- Variables
- func Encode(text string, encoding Encoding, limit int) ([]byte, error)
- type Buffer
- type Character
- type Cursor
- func (c *Cursor) Bytes(span Span) ([]byte, error)
- func (c *Cursor) Next() (Character, error)
- func (c *Cursor) Relocate(buffer *Buffer, offset int, position Position) (Cursor, error)
- func (c *Cursor) RelocateOnto(buffer *Buffer, offset int, position Position) (Cursor, error)
- func (c *Cursor) Run(accept func(byte) bool) int
- func (c *Cursor) SetVersion(version Version) error
- func (c *Cursor) View(span Span) ([]byte, error)
- type Encoding
- type Fault
- type Location
- type Position
- type Span
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEncoding identifies malformed original code units, not scalar errors. ErrEncoding = errors.NewSentinel("yamldoc.source.encoding", "invalid source encoding") // ErrVersion identifies an unsupported coordinate line-break convention. ErrVersion = errors.NewSentinel("yamldoc.source.version", "invalid source language version") // ErrCursor identifies an uninitialized cursor. ErrCursor = errors.NewSentinel("yamldoc.source.cursor", "uninitialized source cursor") )
var ( // ErrInputLimit identifies refusal before source ownership is acquired. ErrInputLimit = errors.NewSentinel("yamldoc.source.input_limit", "source exceeds byte limit") // ErrInvalidLimit identifies an absent or nonpositive admission budget. ErrInvalidLimit = errors.NewSentinel("yamldoc.source.invalid_limit", "source byte limit must be positive") // ErrSpan identifies a range outside the retained source. ErrSpan = errors.NewSentinel("yamldoc.source.span", "invalid source byte span") )
var ErrEncode = errors.NewSentinel("yamldoc.source.encode", "invalid text or replacement encoding")
Functions ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer retains source independently of caller-owned memory.
func (*Buffer) Encoding ¶
Encoding reports the detected source encoding without rewriting its bytes.
func (*Buffer) Preamble ¶
Preamble returns the original encoding marker's span, empty when unmarked.
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor decodes incrementally without retaining a second copy of the text. Separate cursors may read a Buffer concurrently; one cursor is not shared.
func (*Cursor) Bytes ¶
Bytes copies an original source range from this cursor's owned buffer snapshot, without advancing it or exposing the caller's replaceable Buffer handle.
func (*Cursor) Relocate ¶
Relocate copies a cursor onto a planned revision's buffer at known coordinates. Returning the cursor by value avoids a temporary heap allocation per token. It preserves language and CRLF state. This checks range admission, not whether the supplied position matches a fresh decode; commit validation establishes that.
func (*Cursor) RelocateOnto ¶
RelocateOnto is Relocate without the defensive copy: the caller owns buffer, never writes it, and keeps it for the cursor's lifetime. A reviser relocating every token of a file onto one private snapshot uses it; the copy per token was the largest allocation of a working revision.
func (*Cursor) Run ¶
Run advances over consecutive UTF-8 ASCII bytes accepted by the predicate, each one column and never a line break, and returns the count. It is the scanner's fast path through the body of a plain scalar; a rune that needs decoding, or a byte the predicate refuses, ends the run untouched. The predicate must refuse '\r' and '\n' so the position stays right.
func (*Cursor) SetVersion ¶
SetVersion changes the convention for unread characters only. Prior source coordinates and CRLF state survive; copied cursors retain their own version. Invalid selection leaves the cursor unchanged and never clears a failure.
type Encoding ¶
type Encoding uint8
Encoding identifies the original code-unit representation.
The supported encodings cover the YAML 1.1/1.2 input encoding repertoire.
type Fault ¶
type Fault struct {
// contains filtered or unexported fields
}
Fault retains admitted source after decoding fails. Its lifetime can retain the whole input; accessors expose copies, not mutable inspection state.
type Location ¶
Location distinguishes reliable source coordinates from unavailable ones. Byte spans always refer to existing original bytes, including any preamble.
type Position ¶
type Position struct{ Line, Column int }
Position counts one-based source lines and Unicode code-point columns.