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
9d087a72
Commit
9d087a72
authored
Aug 14, 2020
by
whyrusleeping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add json marshalers to CborTime
parent
0eaa2b53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
testing/roundtrip_test.go
testing/roundtrip_test.go
+15
-0
utils.go
utils.go
+13
-0
No files found.
testing/roundtrip_test.go
View file @
9d087a72
...
...
@@ -2,6 +2,7 @@ package testing
import
(
"bytes"
"encoding/json"
"math/rand"
"reflect"
"testing"
...
...
@@ -146,4 +147,18 @@ func TestTimeIsh(t *testing.T) {
t
.
Fatal
(
"no"
)
}
b
,
err
:=
json
.
Marshal
(
val
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
out2
ThingWithSomeTime
if
err
:=
json
.
Unmarshal
(
b
,
&
out2
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
out2
.
When
!=
out
.
When
{
t
.
Fatal
(
err
)
}
}
utils.go
View file @
9d087a72
...
...
@@ -739,3 +739,16 @@ func (ct *CborTime) UnmarshalCBOR(r io.Reader) error {
func
(
ct
CborTime
)
Time
()
time
.
Time
{
return
(
time
.
Time
)(
ct
)
}
func
(
ct
CborTime
)
MarshalJSON
()
([]
byte
,
error
)
{
return
ct
.
Time
()
.
MarshalJSON
()
}
func
(
ct
*
CborTime
)
UnmarshalJSON
(
b
[]
byte
)
error
{
var
t
time
.
Time
if
err
:=
t
.
UnmarshalJSON
(
b
);
err
!=
nil
{
return
err
}
*
(
*
time
.
Time
)(
ct
)
=
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