Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1684)

Unified Diff: common/logdog/protocol/protoutil/utils.go

Issue 1272893004: LogDog: Update protobufs, add support library. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« common/logdog/protocol/butler.proto ('K') | « common/logdog/protocol/butler.pb.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+}
« common/logdog/protocol/butler.proto ('K') | « common/logdog/protocol/butler.pb.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698