Documentation
¶
Index ¶
- Variables
- type PanicError
- type ProtoMessage
- type SourceCtx
- func Find[T any, M ProtoMessage[T]](r io.Reader, match func(M) bool, opts ...UnmarshalOpt) (M, SourceCtx, error)
- func NewEmptySourceCtx() SourceCtx
- func Single[T any, M ProtoMessage[T]](documents []M, contexts []SourceCtx, err error) (M, SourceCtx, error)
- func Unmarshal[T any, M ProtoMessage[T]](r io.Reader, opts ...UnmarshalOpt) ([]M, []SourceCtx, error)
- func UnmarshalBytes[T any, M ProtoMessage[T]](contents []byte, opts ...UnmarshalOpt) (_ []M, _ []SourceCtx, outErr error)
- func UnmarshalFile[T any, M ProtoMessage[T]](fsys fs.FS, path string, opts ...UnmarshalOpt) ([]M, []SourceCtx, error)
- func (sc SourceCtx) ContextForMapKeyAtYAMLPath(path string) string
- func (sc SourceCtx) ContextForValueAtYAMLPath(path string) string
- func (sc SourceCtx) PositionAndContextForMapKeyAtProtoPath(path string) (pos *sourcev1.Position, context string)
- func (sc SourceCtx) PositionAndContextForValueAtProtoPath(path string) (pos *sourcev1.Position, context string)
- func (sc SourceCtx) PositionOfMapKeyAtProtoPath(path string) *sourcev1.Position
- func (sc SourceCtx) PositionOfValueAtProtoPath(path string) *sourcev1.Position
- func (sc SourceCtx) StartPosition() *sourcev1.Position
- type UnmarshalError
- type UnmarshalOpt
Constants ¶
This section is empty.
Variables ¶
var ( ErrMultipleYAMLDocs = errors.New("more than one YAML document detected") ErrNotFound = errors.New("not found") )
Functions ¶
This section is empty.
Types ¶
type PanicError ¶ added in v0.36.0
func (PanicError) Error ¶ added in v0.36.0
func (pe PanicError) Error() string
type ProtoMessage ¶ added in v0.54.0
ProtoMessage allows allocation of proto.Message instances without reflection.
type SourceCtx ¶
type SourceCtx struct {
*sourcev1.SourceContext
// contains filtered or unexported fields
}
func Find ¶
func Find[T any, M ProtoMessage[T]](r io.Reader, match func(M) bool, opts ...UnmarshalOpt) (M, 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:
- The offsets reported by the parser are not always reliable (I am yet to figure out why)
- 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 Single ¶ added in v0.54.0
func Single[T any, M ProtoMessage[T]](documents []M, contexts []SourceCtx, err error) (M, SourceCtx, error)
Single wraps Unmarshal to return a single document, or an error if there are multiple documents.
func Unmarshal ¶
func Unmarshal[T any, M ProtoMessage[T]](r io.Reader, opts ...UnmarshalOpt) ([]M, []SourceCtx, error)
func UnmarshalBytes ¶
func UnmarshalBytes[T any, M ProtoMessage[T]](contents []byte, opts ...UnmarshalOpt) (_ []M, _ []SourceCtx, outErr error)
func UnmarshalFile ¶ added in v0.54.0
func UnmarshalFile[T any, M ProtoMessage[T]](fsys fs.FS, path string, opts ...UnmarshalOpt) ([]M, []SourceCtx, error)
func (SourceCtx) ContextForMapKeyAtYAMLPath ¶ added in v0.50.0
func (SourceCtx) ContextForValueAtYAMLPath ¶ added in v0.50.0
func (SourceCtx) PositionAndContextForMapKeyAtProtoPath ¶ added in v0.50.0
func (SourceCtx) PositionAndContextForValueAtProtoPath ¶ added in v0.50.0
func (SourceCtx) PositionOfMapKeyAtProtoPath ¶ added in v0.50.0
func (SourceCtx) PositionOfValueAtProtoPath ¶ added in v0.50.0
func (SourceCtx) StartPosition ¶
type UnmarshalError ¶
func NewUnmarshalError ¶
func NewUnmarshalError(err *sourcev1.Error) UnmarshalError
func (UnmarshalError) Error ¶
func (ue UnmarshalError) Error() string
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 WithoutValidate ¶ added in v0.54.0
func WithoutValidate() UnmarshalOpt
WithoutValidate skips validating the unmarshaled message using protovalidate.