parser

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type SourceCtx

type SourceCtx struct {
	*sourcev1.SourceContext
	// contains filtered or unexported fields
}

func Find

func Find[T proto.Message](r io.Reader, match func(T) bool, out T, opts ...UnmarshalOpt) (SourceCtx, error)

Find a single document from the multi-document stream. TODO(cell): Optimize! For our use case, this could be optimized by storing the offset of each document and directly seeking to that offset. However, there are a couple of problems with that:

  1. The offsets reported by the parser are not always reliable (I am yet to figure out why)
  2. If YAML anchors have been used, we need to resolve those first by reading through the entire file anyway However, this is a relatively niche case and we can handle that case lazily (seek first, read, and resolve anchors only if they exist in the doc)

In the interest of time, I am leaving those optimizations for later.

func NewEmptySourceCtx

func NewEmptySourceCtx() SourceCtx

func Unmarshal

func Unmarshal[T proto.Message](r io.Reader, factory func() T, opts ...UnmarshalOpt) ([]T, []SourceCtx, error)

func UnmarshalBytes

func UnmarshalBytes[T proto.Message](contents []byte, factory func() T, opts ...UnmarshalOpt) (_ []T, _ []SourceCtx, outErr error)

func (SourceCtx) ContextForYAMLPath

func (sc SourceCtx) ContextForYAMLPath(path string) string

func (SourceCtx) PositionAndContextForProtoPath

func (sc SourceCtx) PositionAndContextForProtoPath(path string) (pos *sourcev1.Position, context string)

func (SourceCtx) PositionForProtoPath

func (sc SourceCtx) PositionForProtoPath(path string) *sourcev1.Position

func (SourceCtx) StartPosition

func (sc SourceCtx) StartPosition() *sourcev1.Position

type UnmarshalError

type UnmarshalError struct {
	Err *sourcev1.Error
}

func NewUnmarshalError

func NewUnmarshalError(err *sourcev1.Error) UnmarshalError

func (UnmarshalError) Error

func (ue UnmarshalError) Error() string

func (UnmarshalError) Format

func (ue UnmarshalError) Format(state fmt.State, verb rune)

func (UnmarshalError) StringWithoutContext

func (ue UnmarshalError) StringWithoutContext() string

type UnmarshalOpt

type UnmarshalOpt func(*unmarshalOpts)

func WithIgnoreUnknownFields

func WithIgnoreUnknownFields() UnmarshalOpt

WithIgnoreUnknownFields ignores unknown fields not defined in the protobuf schema.

func WithValidator

func WithValidator(validator *protovalidate.Validator) UnmarshalOpt

WithValidate validates the unmarshaled message using protovalidate.

Jump to

Keyboard shortcuts

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