plist.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. //
  54. // UIDs cannot be serialized in OpenStepFormat or GNUStepFormat property lists.
  55. type UID uint64
  56. // Marshaler is the interface implemented by types that can marshal themselves into valid
  57. // property list objects. The returned value is marshaled in place of the original value
  58. // implementing Marshaler
  59. //
  60. // If an error is returned by MarshalPlist, marshaling stops and the error is returned.
  61. type Marshaler interface {
  62. MarshalPlist() (interface{}, error)
  63. }
  64. // Unmarshaler is the interface implemented by types that can unmarshal themselves from
  65. // property list objects. The UnmarshalPlist method receives a function that may
  66. // be called to unmarshal the original property list value into a field or variable.
  67. //
  68. // It is safe to call the unmarshal function more than once.
  69. type Unmarshaler interface {
  70. UnmarshalPlist(unmarshal func(interface{}) error) error
  71. }