Chromium Code Reviews| Index: common/logdog/protocol/protoutil/utils.go |
| diff --git a/common/logdog/protocol/protoutil/utils.go b/common/logdog/protocol/protoutil/utils.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..69ffae8d6e836102223045471ca502516d206454 |
| --- /dev/null |
| +++ b/common/logdog/protocol/protoutil/utils.go |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
|
tandrii(chromium)
2015/08/11 17:41:37
// package protoutil is a library to operate on pr
dnj
2015/08/11 18:20:37
Done.
|
| +package protoutil |
| + |
| +import ( |
| + "time" |
| + |
| + "github.com/luci/luci-go/common/logdog/protocol" |
| + "github.com/luci/luci-go/common/logdog/types" |
| +) |
| + |
| +// DescriptorPath returns the StreamPath for a descriptor. |
| +func DescriptorPath(d *protocol.LogStreamDescriptor) types.StreamPath { |
| + if d == nil { |
| + return types.StreamPath("") |
| + } |
| + return types.StreamName(d.GetPrefix()).Join(types.StreamName(d.GetName())) |
| +} |
| + |
| +// NewTimestamp creates a new Butler protocol Timestamp from a time.Time type. |
| +func NewTimestamp(t time.Time) *protocol.Timestamp { |
| + value := uint64(t.UTC().UnixNano()) / uint64(time.Microsecond) |
| + return &protocol.Timestamp{ |
| + UsFromEpoch: &value, |
| + } |
| +} |
| + |
| +// TimeOffset returns the equivalent time offset in microseconds for a Duration. |
| +// This is suitable for use in offset-since-microseconds protobuf fields. |
| +func TimeOffset(d time.Duration) uint64 { |
| + offset := d.Nanoseconds() |
|
tandrii(chromium)
2015/08/11 17:41:37
bummer, i didn't expect time.Duration to miss .Mic
dnj
2015/08/11 18:20:37
Acknowledged.
|
| + if offset < 0 { |
| + offset = 0 |
| + } |
| + value := uint64(offset / int64(time.Microsecond)) |
| + return value |
| +} |