cbor

package
v0.0.0-...-113f422 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2017 License: Apache-2.0 Imports: 9 Imported by: 2

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

func Dumps

func Dumps(ob interface{}) ([]byte, error)

Write out an object to a new byte slice

func Encode

func Encode(out io.Writer, ob interface{}) error

Write out an object to an io.Writer

func Loads

func Loads(blob []byte, v interface{}) error

Load one object into v

Types

type CBORTag

type CBORTag struct {
	Tag           uint64
	WrappedObject interface{}
}

type Decoder

type Decoder struct {

	// Extra processing for CBOR TAG objects.
	TagDecoders map[uint64]TagDecoder
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode(v interface{}) error

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(out io.Writer) *Encoder

Return new Encoder object for writing to supplied io.Writer.

TODO: set options on Encoder object.

func (*Encoder) Encode

func (enc *Encoder) Encode(ob interface{}) error

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

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)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL