Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9d528223
Commit
9d528223
authored
May 10, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reproduce time issue with protobufs.
parent
17c3f19c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
time_proto.go
pkg/api/unversioned/time_proto.go
+17
-2
time_test.go
pkg/api/unversioned/time_test.go
+26
-0
No files found.
pkg/api/unversioned/time_proto.go
View file @
9d528223
...
...
@@ -47,24 +47,39 @@ func (m *Time) ProtoTime() *Timestamp {
}
// Size implements the protobuf marshalling interface.
func
(
m
*
Time
)
Size
()
(
n
int
)
{
return
m
.
ProtoTime
()
.
Size
()
}
func
(
m
*
Time
)
Size
()
(
n
int
)
{
if
m
==
nil
||
m
.
Time
.
IsZero
()
{
return
0
}
return
m
.
ProtoTime
()
.
Size
()
}
// Reset implements the protobuf marshalling interface.
func
(
m
*
Time
)
Unmarshal
(
data
[]
byte
)
error
{
if
len
(
data
)
==
0
{
m
.
Time
=
time
.
Time
{}
return
nil
}
p
:=
Timestamp
{}
if
err
:=
p
.
Unmarshal
(
data
);
err
!=
nil
{
return
err
}
m
.
Time
=
time
.
Unix
(
p
.
Seconds
,
int64
(
p
.
Nanos
))
m
.
Time
=
time
.
Unix
(
p
.
Seconds
,
int64
(
p
.
Nanos
))
.
Local
()
return
nil
}
// Marshal implements the protobuf marshalling interface.
func
(
m
*
Time
)
Marshal
()
(
data
[]
byte
,
err
error
)
{
if
m
==
nil
||
m
.
Time
.
IsZero
()
{
return
nil
,
nil
}
return
m
.
ProtoTime
()
.
Marshal
()
}
// MarshalTo implements the protobuf marshalling interface.
func
(
m
*
Time
)
MarshalTo
(
data
[]
byte
)
(
int
,
error
)
{
if
m
==
nil
||
m
.
Time
.
IsZero
()
{
return
0
,
nil
}
return
m
.
ProtoTime
()
.
MarshalTo
(
data
)
}
pkg/api/unversioned/time_test.go
View file @
9d528223
...
...
@@ -18,6 +18,7 @@ package unversioned
import
(
"encoding/json"
"reflect"
"testing"
"time"
...
...
@@ -145,3 +146,28 @@ func TestTimeMarshalJSONUnmarshalYAML(t *testing.T) {
}
}
}
func
TestTimeProto
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
input
Time
}{
{
Time
{}},
{
Date
(
1998
,
time
.
May
,
5
,
1
,
5
,
5
,
50
,
time
.
Local
)},
{
Date
(
1998
,
time
.
May
,
5
,
5
,
5
,
5
,
0
,
time
.
Local
)},
}
for
_
,
c
:=
range
cases
{
input
:=
c
.
input
data
,
err
:=
input
.
Marshal
()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to marshal input: '%v': %v"
,
input
,
err
)
}
time
:=
Time
{}
if
err
:=
time
.
Unmarshal
(
data
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to unmarshal output: '%v': %v"
,
input
,
err
)
}
if
!
reflect
.
DeepEqual
(
input
,
time
)
{
t
.
Errorf
(
"Marshal->Unmarshal is not idempotent: '%v' vs '%v'"
,
input
,
time
)
}
}
}
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