Unverified Commit 42a6b22e authored by Whyrusleeping's avatar Whyrusleeping Committed by GitHub

Merge pull request #64 from quorumcontrol/feature/fastpath

fastpath CBOR
parents 6fc53031 98475267
......@@ -24,8 +24,16 @@ func NewPooledCloner(atl atlas.Atlas) PooledCloner {
}
}
type selfCloner interface {
Clone(b interface{}) error
}
// Clone clones a into b using a cloner from the pool.
func (p *PooledCloner) Clone(a, b interface{}) error {
if self, ok := a.(selfCloner); ok {
return self.Clone(b)
}
c := p.pool.Get().(refmt.Cloner)
err := c.Clone(a, b)
p.pool.Put(c)
......
......@@ -30,10 +30,20 @@ func NewMarshallerAtlased(atl atlas.Atlas) *Marshaller {
return m
}
type cborMarshaler interface {
MarshalCBOR(w io.Writer) error
}
// Encode encodes the given object to the given writer.
func (m *Marshaller) Encode(obj interface{}, w io.Writer) error {
m.writer.w = w
err := m.marshal.Marshal(obj)
var err error
selfMarshaling, ok := obj.(cborMarshaler)
if ok {
err = selfMarshaling.MarshalCBOR(w)
} else {
err = m.marshal.Marshal(obj)
}
m.writer.w = nil
return err
}
......
......@@ -30,11 +30,20 @@ func NewUnmarshallerAtlased(atl atlas.Atlas) *Unmarshaller {
return m
}
type cborUnmarshaler interface {
UnmarshalCBOR(r io.Reader) error
}
// Decode reads a CBOR object from the given reader and decodes it into the
// given object.
func (m *Unmarshaller) Decode(r io.Reader, obj interface{}) error {
func (m *Unmarshaller) Decode(r io.Reader, obj interface{}) (err error) {
m.reader.r = r
err := m.unmarshal.Unmarshal(obj)
selfUnmarshaler, ok := obj.(cborUnmarshaler)
if ok {
err = selfUnmarshaler.UnmarshalCBOR(r)
} else {
err = m.unmarshal.Unmarshal(obj)
}
m.reader.r = nil
return err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment