Documentation
¶
Index ¶
- Constants
- func Marshal(v interface{}) ([]byte, error)
- func MarshalIndent(v interface{}, indent string) ([]byte, error)
- func Unmarshal(data []byte, v interface{}) error
- type Decoder
- type Encoder
- type MarshalFunc
- type Marshaler
- type UnmarshalTypeError
- type Unmarshaler
- type UnsupportedTypeError
- type UnsupportedValueError
Examples ¶
Constants ¶
const ( Invalid plistKind = iota Dictionary Array String Integer Real Boolean Data Date )
Variables ¶
This section is empty.
Functions ¶
func MarshalIndent ¶
MarshalIndent ...
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 ¶
NewDecoder returns a new XML plist decoder. DEPRECATED: Please use NewXMLDecoder instead.
func NewXMLDecoder ¶
NewXMLDecoder returns a new decoder that reads an XML plist from r.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder ...
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
type MarshalFunc ¶
type MarshalFunc func(interface{}) error
MarshalFunc is a function used to Unmarshal custom plist types.
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 ¶
Unmarshaler is the interface implemented by types that can unmarshal themselves from property list objects. The UnmarshalPlist method receives a function that may be called to unmarshal the original property list value into a field or variable.
It is safe to call the unmarshal function more than once.
Example ¶
ExampleUnmarshaler demonstrates using structs that use the Unmarshaler interface.
package main
import (
"fmt"
"github.com/micromdm/plist"
)
const data = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>typekey</key>
<string>A</string>
<key>typeAkey</key>
<string>VALUE-A</string>
</dict>
</plist>`
type TypeDecider struct {
ActualType interface{} `plist:"-"`
}
type TypeA struct {
TypeAKey string `plist:"typeAkey"`
}
type TypeB struct {
TypeBKey string `plist:"typeBkey"`
}
func (t *TypeDecider) UnmarshalPlist(f func(interface{}) error) error {
// stub struct for decoding a single key to tell which
// specific type we should umarshal into
typeKey := &struct {
TypeKey string `plist:"typekey"`
}{}
if err := f(typeKey); err != nil {
return err
}
// switch using the decoded value to determine the correct type
switch typeKey.TypeKey {
case "A":
t.ActualType = new(TypeA)
case "B":
t.ActualType = new(TypeB)
case "":
return fmt.Errorf("empty typekey (or wrong input data)")
default:
return fmt.Errorf("unknown typekey: %s", typeKey.TypeKey)
}
// decode into the actual type
return f(t.ActualType)
}
// ExampleUnmarshaler demonstrates using structs that use the Unmarshaler interface.
func main() {
decider := new(TypeDecider)
if err := plist.Unmarshal([]byte(data), decider); err != nil {
fmt.Println(err)
return
}
typeA, ok := decider.ActualType.(*TypeA)
if !ok {
fmt.Println("actual type is not TypeA")
return
}
fmt.Println(typeA.TypeAKey)
}
Output: VALUE-A
type UnsupportedTypeError ¶
An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶
UnsupportedValueError ...
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string