plist

package module
v0.0.0-...-63fa881 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: BSD-2-Clause-Views, BSD-3-Clause Imports: 16 Imported by: 79

README

OS X XML Plist library for Go

Go

The plist library is used for decoding and encoding XML Plists, usually from HTTP streams.

Example:

func someHTTPHandler(w http.ResponseWriter, r *http.Request) {
	var sparseBundleHeader struct {
		InfoDictionaryVersion *string `plist:"CFBundleInfoDictionaryVersion"`
		BandSize              *uint64 `plist:"band-size"`
		BackingStoreVersion   int     `plist:"bundle-backingstore-version"`
		DiskImageBundleType   string  `plist:"diskimage-bundle-type"`
		Size                  uint64  `plist:"unknownKey"`
	}

    // decode an HTTP request body into the sparseBundleHeader struct
	if err := plist.NewXMLDecoder(r.Body).Decode(&sparseBundleHeader); err != nil {
		log.Println(err)
        return
	}
}

Credit

This library is based of DHowett's library but has an API that's more similar to the XML and JSON libraries in the standard library. The plist.Decoder() accepts an io.Reader instead of an io.ReadSeeker

Documentation

Index

Constants

View Source
const (
	Invalid plistKind = iota
	Dictionary
	Array
	String
	Integer
	Real
	Boolean
	Data
	Date
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal ...

func MarshalIndent

func MarshalIndent(v interface{}, indent string) ([]byte, error)

MarshalIndent ...

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the plist-encoded data and stores the result in the value pointed to by v.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes Apple plist objects from an input stream. The plists can be in XML or binary format.

func NewBinaryDecoder

func NewBinaryDecoder(r io.ReadSeeker) *Decoder

NewBinaryDecoder returns a new decoder that reads a binary plist from r. No error checking is done to make sure that r is actually a binary plist.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new XML plist decoder. DEPRECATED: Please use NewXMLDecoder instead.

func NewXMLDecoder

func NewXMLDecoder(r io.Reader) *Decoder

NewXMLDecoder returns a new decoder that reads an XML plist from r.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

Decode reads the next plist-encoded value from its input and stores it in the value pointed to by v. Decode uses xml.Decoder to do the heavy lifting for XML plists, and uses binaryParser for binary plists.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder ...

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode ...

func (*Encoder) Indent

func (e *Encoder) Indent(indent string)

Indent ...

type MarshalFunc

type MarshalFunc func(interface{}) error

MarshalFunc is a function used to Unmarshal custom plist types.

type Marshaler

type Marshaler interface {
	MarshalPlist() (interface{}, error)
}

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value string // description of plist value - "true", "string", "date"
	Type  reflect.Type
}

An UnmarshalTypeError describes a plist value that was not appropriate for a value of a specific Go type.

func (UnmarshalTypeError) Error

func (e UnmarshalTypeError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalPlist(f func(interface{}) error) error
}

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

type UnsupportedValueError

type UnsupportedValueError struct {
	Value reflect.Value
	Str   string
}

UnsupportedValueError ...

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Jump to

Keyboard shortcuts

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