plist.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package plist
  2. import (
  3. "reflect"
  4. )
  5. // Property list format constants
  6. const (
  7. // Used by Decoder to represent an invalid property list.
  8. InvalidFormat int = 0
  9. // Used to indicate total abandon with regards to Encoder's output format.
  10. AutomaticFormat = 0
  11. XMLFormat = 1
  12. BinaryFormat = 2
  13. OpenStepFormat = 3
  14. GNUStepFormat = 4
  15. )
  16. var FormatNames = map[int]string{
  17. InvalidFormat: "unknown/invalid",
  18. XMLFormat: "XML",
  19. BinaryFormat: "Binary",
  20. OpenStepFormat: "OpenStep",
  21. GNUStepFormat: "GNUStep",
  22. }
  23. type unknownTypeError struct {
  24. typ reflect.Type
  25. }
  26. func (u *unknownTypeError) Error() string {
  27. return "plist: can't marshal value of type " + u.typ.String()
  28. }
  29. type invalidPlistError struct {
  30. format string
  31. err error
  32. }
  33. func (e invalidPlistError) Error() string {
  34. s := "plist: invalid " + e.format + " property list"
  35. if e.err != nil {
  36. s += ": " + e.err.Error()
  37. }
  38. return s
  39. }
  40. type plistParseError struct {
  41. format string
  42. err error
  43. }
  44. func (e plistParseError) Error() string {
  45. s := "plist: error parsing " + e.format + " property list"
  46. if e.err != nil {
  47. s += ": " + e.err.Error()
  48. }
  49. return s
  50. }
  51. // A UID represents a unique object identifier. UIDs are serialized in a manner distinct from
  52. // that of integers.
  53. type UID uint64
  54. // Marshaler is the interface implemented by types that can marshal themselves into valid
  55. // property list objects. The returned value is marshaled in place of the original value
  56. // implementing Marshaler
  57. //
  58. // If an error is returned by MarshalPlist, marshaling stops and the error is returned.
  59. type Marshaler interface {
  60. MarshalPlist() (interface{}, error)
  61. }
  62. // Unmarshaler is the interface implemented by types that can unmarshal themselves from
  63. // property list objects. The UnmarshalPlist method receives a function that may
  64. // be called to unmarshal the original property list value into a field or variable.
  65. //
  66. // It is safe to call the unmarshal function more than once.
  67. type Unmarshaler interface {
  68. UnmarshalPlist(unmarshal func(interface{}) error) error
  69. }