plist.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 = 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. // FormatNames for plist
  17. var FormatNames = map[int]string{
  18. InvalidFormat: "unknown/invalid",
  19. XMLFormat: "XML",
  20. BinaryFormat: "Binary",
  21. OpenStepFormat: "OpenStep",
  22. GNUStepFormat: "GNUStep",
  23. }
  24. type unknownTypeError struct {
  25. typ reflect.Type
  26. }
  27. func (u *unknownTypeError) Error() string {
  28. return "plist: can't marshal value of type " + u.typ.String()
  29. }
  30. type invalidPlistError struct {
  31. format string
  32. err error
  33. }
  34. func (e invalidPlistError) Error() string {
  35. s := "plist: invalid " + e.format + " property list"
  36. if e.err != nil {
  37. s += ": " + e.err.Error()
  38. }
  39. return s
  40. }
  41. type plistParseError struct {
  42. format string
  43. err error
  44. }
  45. func (e plistParseError) Error() string {
  46. s := "plist: error parsing " + e.format + " property list"
  47. if e.err != nil {
  48. s += ": " + e.err.Error()
  49. }
  50. return s
  51. }
  52. // A UID represents a unique object identifier. UIDs are serialized in a manner distinct from
  53. // that of integers.
  54. //
  55. // UIDs cannot be serialized in OpenStepFormat or GNUStepFormat property lists.
  56. type UID uint64
  57. // Marshaler is the interface implemented by types that can marshal themselves into valid
  58. // property list objects. The returned value is marshaled in place of the original value
  59. // implementing Marshaler
  60. //
  61. // If an error is returned by MarshalPlist, marshaling stops and the error is returned.
  62. type Marshaler interface {
  63. MarshalPlist() (interface{}, error)
  64. }
  65. // Unmarshaler is the interface implemented by types that can unmarshal themselves from
  66. // property list objects. The UnmarshalPlist method receives a function that may
  67. // be called to unmarshal the original property list value into a field or variable.
  68. //
  69. // It is safe to call the unmarshal function more than once.
  70. type Unmarshaler interface {
  71. UnmarshalPlist(unmarshal func(interface{}) error) error
  72. }