json2cbor

package module
v0.0.0-...-9d0dfa4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2015 License: MIT Imports: 4 Imported by: 0

README

json2cbor - recoder in go

This is a simple json2cbor recoder. All the heavy lifting is done by encoding/json and github.com/ugorji/go/codec.

Usage

package main

import j2c "github.com/jbenet/go-json2cbor"


func main() {
  switch os.Args[1] {
  default:
    return errors.New("arg must be j2c or c2j")
  case "j2c":
    return j2c.JsonToCbor(os.Stdout, os.Stdin)
  case "c2j":
    return j2c.CborToJson(os.Stdout, os.Stdin)
  }
}

json2cbor tool

go get github.com/jbenet/go-json2cbor/json2cbor

convert json to cbor

cat a_bunch_of.json | json2cbor j2c >a_bunch_of.cbor
cat a_bunch_of.cbor | json2cbor c2j >a_bunch_of.json

outputs newline-delimited json.

Test codec with:

random-json -o | json2cbor j2c | json2cbor c2j

Test JSON->CBOR->JSON roundtripping with:

random-json -o -c 10 | tee a.json | json2cbor j2c | json2cbor c2j >b.json && diff a.json b.json

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Codecs = []string{"dw", "ugorji"}
View Source
var ErrCodecNotSupported = errors.New("codec not supported")

Functions

func CborToJson

func CborToJson(codec string, w io.Writer, r io.Reader) error

func DWCborToJson

func DWCborToJson(w io.Writer, r io.Reader) error

func DWJsonToCbor

func DWJsonToCbor(w io.Writer, r io.Reader) error

func EDCborToJson

func EDCborToJson(w io.Writer, enc Encoder, dec Decoder) error

func EDJsonToCbor

func EDJsonToCbor(enc Encoder, dec Decoder) error

func JsonToCbor

func JsonToCbor(codec string, w io.Writer, r io.Reader) error

func UgorjiCborToJson

func UgorjiCborToJson(w io.Writer, r io.Reader) error

func UgorjiJsonToCbor

func UgorjiJsonToCbor(w io.Writer, r io.Reader) error

Types

type Decoder

type Decoder interface {
	Decode(interface{}) error
}

type Encoder

type Encoder interface {
	Encode(interface{}) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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