Documentation
¶
Overview ¶
CBOR is IETF RFC 7049, the "Concise Binary Object Representation" http://tools.ietf.org/html/rfc7049
In can be thought of as "binary JSON" but is a superset and somewhat richer representation than JSON.
import cbor "bitbucket.org/bodhisnarkva/cbor/go"
Other implementations and more information can also be found at: http://cbor.io/
Serialization and deserialization of structs uses the same tag format as the encoding/json package. If different json and cbor serialization names are needed, a tag `cbor:"fieldName"` can be specified. Example:
type DemoStruct struct {
FieldNeedsDifferentName string `json:"serialization_name"`
FieldNeedsJsonVsCborName int `json:"json_name" cbor:"cbor_name"`
}
This might generate json: {"serialization_name":"foo", "json_name":2}
And CBOR equivalent to: {"serialization_name":"foo", "cbor_name":2}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Decoder ¶
type Decoder struct {
// Extra processing for CBOR TAG objects.
TagDecoders map[uint64]TagDecoder
// contains filtered or unexported fields
}
func NewDecoder ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
Return new Encoder object for writing to supplied io.Writer.
TODO: set options on Encoder object.
type InvalidUnmarshalError ¶
copied from encoding/json/decode.go An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type TagDecoder ¶
type TagDecoder interface {
// Handle things which match this.
//
// Setup like this:
// var dec Decoder
// var myTagDec TagDecoder
// dec.TagDecoders[myTagDec.GetTag()] = myTagDec
GetTag() uint64
// Sub-object will be decoded onto the returned object.
DecodeTarget() interface{}
// Run after decode onto DecodeTarget has happened.
// The return value from this is returned in place of the
// raw decoded object.
PostDecode(interface{}) (interface{}, error)
}