mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 23:10:59 +00:00
add wire pkg with global codec
This commit is contained in:
46
wire/wire.go
Normal file
46
wire/wire.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package wire
|
||||
|
||||
import (
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire"
|
||||
)
|
||||
|
||||
// Expose access to a global wire codec
|
||||
// TODO: maybe introduce some Context object
|
||||
// containing logger, config, codec that can
|
||||
// be threaded through everything to avoid this global
|
||||
|
||||
var cdc *wire.Codec
|
||||
|
||||
func init() {
|
||||
cdc = wire.NewCodec()
|
||||
crypto.RegisterWire(cdc)
|
||||
}
|
||||
|
||||
func MarshalBinary(o interface{}) ([]byte, error) {
|
||||
return cdc.MarshalBinary(o)
|
||||
}
|
||||
|
||||
func UnmarshalBinary(bz []byte, ptr interface{}) error {
|
||||
return cdc.UnmarshalBinary(bz, ptr)
|
||||
}
|
||||
|
||||
func MarshalJSON(o interface{}) ([]byte, error) {
|
||||
return cdc.MarshalJSON(o)
|
||||
}
|
||||
|
||||
func UnmarshalJSON(jsonBz []byte, ptr interface{}) error {
|
||||
return cdc.UnmarshalJSON(jsonBz, ptr)
|
||||
}
|
||||
|
||||
func RegisterInterface(ptr interface{}, opts *wire.InterfaceOptions) {
|
||||
cdc.RegisterInterface(ptr, opts)
|
||||
}
|
||||
|
||||
func RegisterConcrete(o interface{}, name string, opts *wire.ConcreteOptions) {
|
||||
cdc.RegisterConcrete(o, name, opts)
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
|
||||
const RFC3339Millis = wire.RFC3339Millis
|
||||
Reference in New Issue
Block a user