cbor

package module
v0.0.0-...-0777a72 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2015 License: BSD-3-Clause Imports: 3 Imported by: 0

README

cbor

GoDoc

cbor is a thin wrapper around cbor and exposes a familiar Encoder/Decoder API (a la json.)

Installation

$ go get github.com/gonuts/cbor

Documentation

Documentation is available on godoc: https://godoc.org/github.com/gonuts/cbor

Example

package main

import (
	"bytes"
	"fmt"

	"github.com/gonuts/cbor"
)

func main() {
	buf := new(bytes.Buffer)
	enc := cbor.NewEncoder(buf)
	err := enc.Encode(42)
	if err != nil {
		panic(err)
	}

	val := 0
	dec := cbor.NewDecoder(buf)
	err = dec.Decode(&val)
	if err != nil {
		panic(err)
	}

	fmt.Printf("val=%#v\n", val)
}

Documentation

Overview

Package cbor implements encoding and decoding of CBOR objects as defined in RFC 7049.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

Marshal returns the CBOR encoding of v.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the CBOR-encoded data and stores the result in the value pointed to by v.

Types

type Decoder

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

Decoder reads and decodes CBOR objects from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

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

Decode reads the next CBOR-encoded value from its input and stores it in the value pointed to by v.

type Encoder

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

An Encoder writes CBOR objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

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

Encode writes the CBOR encoding of v to the stream.

Jump to

Keyboard shortcuts

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