Skip to content

Commit df02633

Browse files
authored
Merge pull request #69 from rykov/et-unmarshal
Implement EventTime.UnmarshalBinary
2 parents cca4fbf + 123be27 commit df02633

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fluent/proto.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package fluent
44

55
import (
6+
"fmt"
67
"time"
78

89
"github.com/tinylib/msgp/msgp"
@@ -93,8 +94,19 @@ func (t *EventTime) MarshalBinaryTo(b []byte) error {
9394
return nil
9495
}
9596

96-
// UnmarshalBinary is not implemented since decoding messages is not supported
97-
// by this library.
97+
// Although decoding messages is not officially supported by this library,
98+
// UnmarshalBinary is implemented for testing and general completeness.
9899
func (t *EventTime) UnmarshalBinary(b []byte) error {
100+
if len(b) != length {
101+
return fmt.Errorf("Invalid EventTime byte length: %d", len(b))
102+
}
103+
104+
sec := (int32(b[0]) << 24) | (int32(b[1]) << 16)
105+
sec = sec | (int32(b[2]) << 8) | int32(b[3])
106+
107+
nsec := (int32(b[4]) << 24) | (int32(b[5]) << 16)
108+
nsec = nsec | (int32(b[6]) << 8) | int32(b[7])
109+
110+
*t = EventTime(time.Unix(int64(sec), int64(nsec)))
99111
return nil
100112
}

0 commit comments

Comments
 (0)