Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ld-cbor
Commits
42a6b22e
Unverified
Commit
42a6b22e
authored
Sep 17, 2019
by
Whyrusleeping
Committed by
GitHub
Sep 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #64 from quorumcontrol/feature/fastpath
fastpath CBOR
parents
6fc53031
98475267
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
encoding/cloner.go
encoding/cloner.go
+8
-0
encoding/marshaller.go
encoding/marshaller.go
+11
-1
encoding/unmarshaller.go
encoding/unmarshaller.go
+11
-2
No files found.
encoding/cloner.go
View file @
42a6b22e
...
...
@@ -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
)
...
...
encoding/marshaller.go
View file @
42a6b22e
...
...
@@ -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
}
...
...
encoding/unmarshaller.go
View file @
42a6b22e
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment