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
cbor-gen
Commits
656e08ce
Commit
656e08ce
authored
Aug 14, 2020
by
whyrusleeping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use unix nanoseconds for encoding Cbortime
parent
9d087a72
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
28 deletions
+7
-28
utils.go
utils.go
+7
-28
No files found.
utils.go
View file @
656e08ce
...
...
@@ -696,43 +696,22 @@ func (ci *CborInt) UnmarshalCBOR(r io.Reader) error {
type
CborTime
time
.
Time
func
(
ct
*
CborTime
)
MarshalCBOR
(
w
io
.
Writer
)
error
{
b
,
err
:=
(
*
time
.
Time
)(
ct
)
.
MarshalBinary
()
if
err
!=
nil
{
return
err
}
nsecs
:=
ct
.
Time
()
.
UnixNano
()
if
err
:=
CborWriteHeader
(
w
,
MajByteString
,
uint64
(
len
(
b
)));
err
!=
nil
{
return
err
}
cbi
:=
CborInt
(
nsecs
)
if
_
,
err
:=
w
.
Write
(
b
);
err
!=
nil
{
return
err
}
return
nil
return
cbi
.
MarshalCBOR
(
w
)
}
func
(
ct
*
CborTime
)
UnmarshalCBOR
(
r
io
.
Reader
)
error
{
t
,
l
,
err
:=
CborReadHeader
(
r
)
if
err
!=
nil
{
var
cbi
CborInt
if
err
:=
cbi
.
UnmarshalCBOR
(
r
);
err
!=
nil
{
return
err
}
if
t
!=
MajByteString
{
return
fmt
.
Errorf
(
"CborTime expects to find a byte array (got %d)"
,
t
)
}
buf
:=
make
([]
byte
,
l
)
if
_
,
err
:=
io
.
ReadFull
(
r
,
buf
);
err
!=
nil
{
return
err
}
tm
:=
time
.
Time
{}
if
err
:=
tm
.
UnmarshalBinary
(
buf
);
err
!=
nil
{
return
err
}
t
:=
time
.
Unix
(
0
,
int64
(
cbi
))
*
ct
=
(
CborTime
)(
t
m
)
*
ct
=
(
CborTime
)(
t
)
return
nil
}
...
...
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