// Unmarshal unmarshals the given data // If v is a *map[string]interface{}, *[]interface{}, or *interface{} numbers // are converted to int64 or float64 func Unmarshal(data []byte, v interface{ … } // UnmarshalStrict unmarshals the given data // strictly (erroring when there are duplicate fields). func UnmarshalStrict(data []byte, v interface{ … } // ToJSON converts a single YAML document into a JSON document // or returns an error. If the document appears to be JSON the // YAML decoding path is not used (so that error messages are // JSON specific). func ToJSON(data []byte) ([]byte, error) { … } type YAMLToJSONDecoder … // NewYAMLToJSONDecoder decodes YAML documents from the provided // stream in chunks by converting each document (as defined by // the YAML spec) into its own chunk, converting it to JSON via // yaml.YAMLToJSON, and then passing it to json.Decoder. func NewYAMLToJSONDecoder(r io.Reader) *YAMLToJSONDecoder { … } // Decode reads a YAML document as JSON from the stream or returns // an error. The decoding rules match json.Unmarshal, not // yaml.Unmarshal. func (d *YAMLToJSONDecoder) Decode(into interface{ … } type YAMLDecoder … // NewDocumentDecoder decodes YAML documents from the provided // stream in chunks by converting each document (as defined by // the YAML spec) into its own chunk. io.ErrShortBuffer will be // returned if the entire buffer could not be read to assist // the caller in framing the chunk. func NewDocumentDecoder(r io.ReadCloser) io.ReadCloser { … } // Read reads the previous slice into the buffer, or attempts to read // the next chunk. // TODO: switch to readline approach. func (d *YAMLDecoder) Read(data []byte) (n int, err error) { … } func (d *YAMLDecoder) Close() error { … } const yamlSeparator … const separator … // splitYAMLDocument is a bufio.SplitFunc for splitting YAML streams into individual documents. func splitYAMLDocument(data []byte, atEOF bool) (advance int, token []byte, err error) { … } type decoder … type YAMLOrJSONDecoder … type JSONSyntaxError … func (e JSONSyntaxError) Error() string { … } type YAMLSyntaxError … func (e YAMLSyntaxError) Error() string { … } // NewYAMLOrJSONDecoder returns a decoder that will process YAML documents // or JSON documents from the given reader as a stream. bufferSize determines // how far into the stream the decoder will look to figure out whether this // is a JSON stream (has whitespace followed by an open brace). func NewYAMLOrJSONDecoder(r io.Reader, bufferSize int) *YAMLOrJSONDecoder { … } // Decode unmarshals the next object from the underlying stream into the // provide object, or returns an error. func (d *YAMLOrJSONDecoder) Decode(into interface{ … } type Reader … type YAMLReader … func NewYAMLReader(r *bufio.Reader) *YAMLReader { … } // Read returns a full YAML document. func (r *YAMLReader) Read() ([]byte, error) { … } type LineReader … // Read returns a single line (with '\n' ended) from the underlying reader. // An error is returned iff there is an error with the underlying reader. func (r *LineReader) Read() ([]byte, error) { … } // GuessJSONStream scans the provided reader up to size, looking // for an open brace indicating this is JSON. It will return the // bufio.Reader it creates for the consumer. func GuessJSONStream(r io.Reader, size int) (io.Reader, []byte, bool) { … } // IsJSONBuffer scans the provided buffer, looking // for an open brace indicating this is JSON. func IsJSONBuffer(buf []byte) bool { … } var jsonPrefix … // hasJSONPrefix returns true if the provided buffer appears to start with // a JSON open brace. func hasJSONPrefix(buf []byte) bool { … } // Return true if the first non-whitespace bytes in buf is // prefix. func hasPrefix(buf []byte, prefix []byte) bool { … }