CoreFoundation Property List support for Go

Overview
PACKAGE

package plist
    import "github.com/kballard/go-osx-plist"

    Package plist implements serializing and deserializing of property list
    objects using CoreFoundation.

    Property list objects are any object of type:

	- string
	- []byte
	- time.Time
	- bool
	- numeric type (except for 64-bit uint types)
	- a slice of any property list object
	- a map from a string to any property list object

    Note, a []byte (or []uint8) slice is always converted to a CFDataRef,
    but a slice of any other type is converted to a CFArrayRef

VARIABLES

var (
    // OpenStep format (use of this format is discouraged)
    OpenStepFormat = Format{1}
    // XML format version 1.0
    XMLFormat = Format{100}
    // Binary format version 1.0
    BinaryFormat = Format{200}
)


FUNCTIONS

func CFPropertyListCreateData(plist interface{}, format Format) ([]byte, error)
    CFPropertyListCreateData returns a []byte containing a serialized
    representation of a given property list in a specified format.

func CFPropertyListCreateWithData(data []byte) (plist interface{}, format Format, err error)
    CFPropertyListCreateWithData decodes the given data into a property list
    object.

func Marshal(v interface{}, format Format) ([]byte, error)
    Marshal returns the property list encoding of v.

    The Marshall interface is very heavily based off of
    encoding/json.Marshal.

    Marshal traverses the value v recursively. If an encountered value
    implements the Marshaler interface and is not a nil pointer, Marshal
    calls its MarshalPlist method to produce a property list object (as
    defined by CFPropertyListCreateData()). If the method returns any other
    object, that is considered an error.

    Otherwise, Marshal uses the following type-dependent default encodings:

    Boolean values encode as CFBooleans.

    Floating point and integer values encode as CFNumbers, except for 64-bit
    unsigned integers which cause Marshal to return an
    UnsupportedValueError.

    String values encode as CFStrings, with each invalid UTF-8 sequence
    replaced by the encoding of the Unicode replacement character U+FFFD.

    Time values encode as CFDate, with millisecond precision. Far-future or
    far-past dates may have less than millisecond precision.

    Array and slice values encode as CFArrays, except that []byte encodes as
    a CFData.

    Struct values encode as CFDictionaries. Each exported struct field
    becomes a member of the object unless

	- the field's tag is "-"
	- the field is empty and its tag specifies the "omitempty" option.

    The empty values are false, 0, any nil pointer or interface value, and
    any array, slice, map, or string of length zero. The object's default
    key string is the struct field name but can be specified in the struct
    field's tag value. The "plist" key in the struct field's tag value is
    the key name, followed by an optional comma and options. Examples:

	// Field is ignored by this package.
	Field int `plist:"-"`
	// Field appears in plist as key "myName".
	Field int `plist:"myName"`
	// Field appears in plist as key "myName" and
	// the field is omitted from the object if its value is empty,
	// as defined above.
	Field int `plist:"myName,omitempty"`
	// Field appears in plist as key "Field" (the default), but
	// the field is skipped if empty.
	// Note the leading comma.
	Field int `plist:",omitempty"`

    The key name will be used if it's a non-empty string consisting of only
    Unicode letters, digits, dollar signs, percent signs, hyphens,
    underscores and slashes.

    Map values encode as CFDictionaries. The map's key type must be string.

    Pointer values encode as the value pointed to. A nil pointer causes
    Marshal to return an UnsupportedValueError.

    Interface values encode as the value contained in the interface. A nil
    interface value causes Marshal to return an UnsupportedValueError.

    Channel, complex, and function values cannot be encoded in a plist.
    Attempting to encode such a value causes Marshal to return an
    UnsupportedTypeError.

    Property lists cannot represent cyclic data structures and Marshal does
    not handle them. Passing cyclic structures to Marshal will result in an
    infinite recursion.


TYPES

type CFError struct {
    Domain      string
    Code        int
    UserInfo    map[string]interface{}
    Description string // comes from CFErrorCopyDescription()
}

func NewCFError(c C.CFErrorRef) *CFError

func (e *CFError) Error() string

type Format struct {
    // contains filtered or unexported fields
}
    Format represents the format of the property list

func Unmarshal(data []byte, v interface{}) (format Format, err error)
    Unmarshal parses the plist-encoded data and stores the result in the
    value pointed to by v.

    Unmarshal uses the inverse of the encodings that Marshal uses,
    allocating maps, slices, and pointers as necessary, with the following
    additional rules:

    To unmarshal a plist into a pointer, Unmarshal unmarshals the plist into
    the value pointed at by the pointer. If the pointer is nil, Unmarshal
    allocates a new value for it to point to.

    To unmarshal a plist into an interface value, Unmarshal unmarshals the
    plist into the concrete value contained in the interface value. If the
    interface value is nil, that is, has no concrete value stored in it,
    Unmarshal stores one of these in the interface value:

	bool, for CFBooleans
	int8, int16, int32, int64, float32, or float64 for CFNumbers
	string, for CFStrings
	[]byte, for CFDatas
	time.Time, for CFDates
	[]interface{}, for CFArrays
	map[string]interface{}, for CFDictionaries

    If a plist value is not appropriate for a given target type, or if a
    plist number overflows the target type, Unmarshal skips that field and
    completes the unmarshalling as best it can. If no more serious errors
    are encountered, Unmarshal returns an UnmarshalTypeError describing the
    earliest such error.

func (f Format) String() string

type InvalidUnmarshalError struct {
    Type reflect.Type
}
    An InvalidUnmarshalError describes an invalid argument passed to
    Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (e *InvalidUnmarshalError) Error() string

type Marshaler interface {
    MarshalPlist() (interface{}, error)
}
    Marshaler is the interface implemented by objects that can marshal
    themselves into a property list.}

type UnknownCFTypeError struct {
    CFTypeID C.CFTypeID
}

func (e *UnknownCFTypeError) Error() string

type UnmarshalFieldError struct {
    Key   string
    Type  reflect.Type
    Field reflect.StructField
}
    An UnmarshalFieldError describes a plist dictionary key that led to an
    unexported (and therefore unwritable) struct field.

func (e *UnmarshalFieldError) Error() string

type UnmarshalTypeError struct {
    Value string       // description of plist value - "CFBoolean, "CFArray", "CFNumber -5"
    Type  reflect.Type // type of Go value it could not be assigned to
}
    An UnmarshalTypeError describes a plist value that was not appropriate
    for a value of a specific Go type.

func (e *UnmarshalTypeError) Error() string

type Unmarshaler interface {
    UnmarshalPlist(interface{}) error
}
    Unmarshaler is the interface implemented by objects that can unmarshal a
    plist representation of themselves. The input can be assumed to be a
    valid basic property list object.

type UnsupportedKeyTypeError struct {
    CFTypeID int
}
    UnsupportedKeyTypeError represents the case where a CFDictionary is
    being converted back into a map[string]interface{} but its key type is
    not a CFString.

    This should never occur in practice, because the only CFDictionaries
    that should be handled are coming from property lists, which require the
    keys to be strings.

func (e *UnsupportedKeyTypeError) Error() string

type UnsupportedTypeError struct {
    Type reflect.Type
}

func (e *UnsupportedTypeError) Error() string

type UnsupportedValueError struct {
    Value reflect.Value
    Str   string
}

func (e *UnsupportedValueError) Error() string


BUGS

    This package ignores anonymous (embedded) struct fields during encoding
    and decoding. This is done to maintain parity with the encoding/json
    package. At such time that encoding/json changes behavior, this package
    may also change. To force an anonymous field to be ignored in all future
    versions of this package, use an explicit `plist:"-"` tag in the struct
    definition.


You might also like...
🏆 A decentralized layer to support NFT on Mixin Messenger and Kernel.

NFO A decentralized layer to support NFT on Mixin Kernel. This MTG sends back an NFT to the receiver whenever it receives a transaction with valid min

Support CI generation of SBOMs via golang tooling.
Support CI generation of SBOMs via golang tooling.

SPDX Software Bill of Materials (SBOM) Generator Overview Software Package Data Exchange (SPDX) is an open standard for communicating software bill of

Functional Programming support for golang.(Streaming API)

Funtional Api for Golang Functional Programming support for golang.(Streaming API) The package can only be used with go 1.18. Do not try in lower vers

The Bhojpur BSS is a software-as-a-service product used as an Business Support System based on Bhojpur.NET Platform for application delivery.

Bhojpur BSS - Business Support System The Bhojpur BSS is a software-as-a-service product used as an Business Support System based on Bhojpur.NET Platf

Plist - A pure Go property list transcoder

plist - A pure Go property list transcoder INSTALL $ go get howett.net/plist FEATURES Supports encoding/decoding property lists (Apple XML, Apple Bin

Access and modify property values in deeply nested maps, using dot-separated paths

Dig lets you access and modify property values in deeply nested, unstructured maps, using dot-separated paths: source := make(map[string]interface{})

A distributed Configuration Center server that manages config in a container. The container is composed of fields (abstract layer includes: KV, LIST, DICT type). The Field contains basic datatypes (int, float, bool, string, list, dict).
Simple to do list API with Gin and Gorm (with Postgres)Simple to do list API with Gin and Gorm (with Postgres)

go-todo Simple to do list API with Gin and Gorm (with Postgres) Docker Clone this repository and run: docker-compose up You can then hit the followin

concurrent map implementation using bucket list like a skip list.

Skip List Map in Golang Skip List Map is an ordered and concurrent map. this Map is goroutine safety for reading/updating/deleting, no-require locking

Todo-list - In this project using golang and mySql to create todo-list to Add and remove
Todo-list - In this project using golang and mySql to create todo-list to Add and remove

TODO-Fullstack-App-Go-Gin-Postgres-React This fullstack application creates a TODO List Web Page using the Go/Gin/Postgres/React Stack. Starting the a

Go-generics-simple-doubly-linked-list - A simple doubly linked list implemented using generics (Golang)

Welcome to Go-Generics-Simple-Doubly-Linked-List! Hi, This repository contains a

List-Utils - 🔧 Utilities for maintaining the list of repost sites

SMR List Utils This is a Go CLI tool that helps with managing the StopModReposts blacklist. Install Use GitHub Releases and download binary. Linux Qui

Shopping-list - Shopping List as part of the training

ShoppingList Shopping List as part of the training Requirements User should be a

A simple shopping list that keeps track of a users shopping list using charm.sh tools

Terminal Shopping List This repo is a practise project for learning practical Go. I have chosen to use a toolset called Charm as it provides a rich se

Generic-list-go - Go container/list but with generics

generic-list-go Go container/list but with generics. The code is based on contai

🎨 Terminal color rendering tool library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染
Database Abstraction Layer (dbal) for Go. Support SQL builder and get result easily (now only support mysql)

godbal Database Abstraction Layer (dbal) for go (now only support mysql) Motivation I wanted a DBAL that No ORM、No Reflect、Concurrency Save, support S

Replacement of ApacheBench(ab), support for transactional requests, support for command line and package references to HTTP stress testing tool.

stress stress is an HTTP stress testing tool. Through this tool, you can do a stress test on the HTTP service and get detailed test results. It is ins

🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows.
🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows.

🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染

Comments
  • Mavericks (10.9) support

    Mavericks (10.9) support

    Hi Kevin,

    I've been playing around with binary plists the last couple of days in Go, and came across this repo. Unfortunately, it doesn't work on Mavericks, so I've started work on fixing that.

    I've coerced kCFAbsoluteTimeIntervalSince1970 to a double because otherwise the code won't compile.

    There's a failing tests now, which relates to converting invalid CFStrings.

    --- FAIL: TestCFString_Invalid (0.00 seconds)
        convert_test.go:67: failed on input: "hello\x00world". Output: "hello". Expected: "hello\x00world"
    FAIL
    exit status 1
    FAIL    _/Users/jcf/Code/go-osx-plist   0.094s
    

    I'm not sure why the string gets split on \x00. Any thoughts?

    opened by jcf 3
  • go v1.10

    go v1.10

    When cloned with go v1.10, the library throw some errors :

    github.com/kballard/go-osx-plist/convert.go:20: cannot convert nil to type cfTypeRef
    github.com/kballard/go-osx-plist/convert.go:27: cannot use nil as type cfTypeRef in return argument
    github.com/kballard/go-osx-plist/convert.go:44: cannot use nil as type cfTypeRef in return argument
    github.com/kballard/go-osx-plist/convert.go:49: cannot convert nil to type _Ctype_CFStringRef
    github.com/kballard/go-osx-plist/convert.go:50: cannot use nil as type cfTypeRef in return argument
    github.com/kballard/go-osx-plist/convert.go:70: cannot use nil as type cfTypeRef in return argument
    github.com/kballard/go-osx-plist/convert.go:74: cannot use nil as type cfTypeRef in return argument
    github.com/kballard/go-osx-plist/convert.go:358: cannot use nil as type _Ctype_CFArrayRef in return argument
    github.com/kballard/go-osx-plist/convert.go:365: cannot convert &plists[0] (type *cfTypeRef) to type *unsafe.Pointer
    github.com/kballard/go-osx-plist/convert.go:394: cannot convert &cfTypes[0] (type *cfTypeRef) to type *unsafe.Pointer
    github.com/kballard/go-osx-plist/convert.go:394: too many errors
    

    FIX The solution was to downgrade go to the v1.8.3 (just download and install said version)

    opened by CGuidi 1
Owner
Lily Ballard
iOS Developer at Twitch. Open source contributor. Programming language aficionado. She/her.
Lily Ballard
Functional programming library for Go including a lazy list implementation and some of the most usual functions.

functional A functional programming library including a lazy list implementation and some of the most usual functions. import FP "github.com/tcard/fun

Toni Cárdenas 31 May 21, 2022
A simplistic todo list manager written in Go

Tasks Tasks is a simplistic Go webapp to manage tasks, I built this tool to manage tasks which I wanted to do, there are many good kanban style boards

Suraj Patil 536 Nov 25, 2022
Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Danger 2 Oct 1, 2021
Onboarding exercise to create todo list using golang and postgres

Todo List API Description A RESTful API that allows a user to create, update, view, filter, and delete todos API Documentation Copy the contents of th

null 0 Dec 1, 2021
Listmonk - a standalone, self-hosted, newsletter and mailing list manager

listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a Postg

null 0 Jan 13, 2022
Takes a list of poker hands for two players in STDIN and scores them

Poker Hand Sorter Takes a list of poker hands for two players in STDIN and scores them. Returns the number of hands won by each player. Prerequisites

Rylee 0 Jan 16, 2022
An application dedicated to the trivial and boring task of meal planning 📅 and generating shoppings list 🛒.

An application dedicated to the trivial and boring task of meal planning ?? and generating shoppings list ??.

Anders Wiggers 1 Mar 1, 2022
Prometheus support for go-metrics

go-metrics-prometheus This is a reporter for the go-metrics library which will post the metrics to the prometheus client registry . It just updates th

Csergő Bálint 76 Nov 13, 2022
Support CI generation of SBOMs via golang tooling.

Software Package Data Exchange (SPDX) is an open standard for communicating software bill of materials (SBOM) information that supports accurate identification of software components, explicit mapping of relationships between components, and the association of security and licensing information with each component.

SPDX 220 Dec 1, 2022
Library to work with MimeHeaders and another mime types. Library support wildcards and parameters.

Mime header Motivation This library created to help people to parse media type data, like headers, and store and match it. The main features of the li

Anton Ohorodnyk 25 Nov 9, 2022