cborutil

package module
v0.0.0-...-4d7bc9b Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: Apache-2.0, MIT Imports: 8 Imported by: 10

README

go-cbor-util

CircleCI codecov

CBOR utilities for reading and writing objects to CBOR representation, optimizing for fast path serialization/deserialization generated by cbor-gen

Install

Install this library with go mod

Usage

Write an object to a stream in cbor

import (
  cborutil "github.com/chenjianmei111/go-cbor-util"
  cbg "github.com/whyrusleeping/cbor-gen"
)

var w io.Writer
// some object type with cbg fastpath marshalling
var out cbg.CBORMarshaler
err := cborutil.WriteCborRPC(w, obj)

var slow interface{}
// will work but will be slower if slow does not support fast path marshalling
err := cborutil.WriteCborRPC(w, slow)

Read an object form a stream in cbor

import (
  cborutil "github.com/chenjianmei111/go-cbor-util"
  cbg "github.com/whyrusleeping/cbor-gen"
)

var r io.Reader
// some object type with cbg fastpath marshalling
var out cbg.CBORUnmarshaler
err := cborutil.ReadCborRPC(r, obj)

var slow interface{}
// will work but will be slower if slow does not support fast path unmarshalling
err := cborutil.ReadCborRPC(r, slow)

Project-level documentation

The chenjianmei111 has a community repo that documents in more detail our policies and guidelines, such as discussion forums and chat rooms and Code of Conduct.

License

This repository is dual-licensed under Apache 2.0 and MIT terms.

Copyright 2019. Protocol Labs, Inc.

Documentation

Index

Constants

View Source
const Debug = false

Debug will produce more debugging messages

Variables

This section is empty.

Functions

func AsIpld

func AsIpld(obj interface{}) (ipld.Node, error)

AsIpld converts an object to an ipld.Node interface TODO: this is a bit ugly, and this package is not exactly the best place

func Dump

func Dump(obj interface{}) ([]byte, error)

Dump returns the cbor bytes representation of an object

func Equals

func Equals(a cbg.CBORMarshaler, b cbg.CBORMarshaler) (bool, error)

Equals is true if two objects have the same cbor representation

func ReadCborRPC

func ReadCborRPC(r io.Reader, out interface{}) error

ReadCborRPC will read an object from the given io.Reader opting for fast path if possible

func WriteCborRPC

func WriteCborRPC(w io.Writer, obj interface{}) error

WriteCborRPC with encode an object to cbor, opting for fast path if possible and then write it into the given io.Writer

Types

This section is empty.

Jump to

Keyboard shortcuts

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