Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
|
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.
| |
| 5 package protoutil | |
| 6 | |
| 7 import ( | |
| 8 "time" | |
| 9 | |
| 10 "github.com/luci/luci-go/common/logdog/protocol" | |
| 11 "github.com/luci/luci-go/common/logdog/types" | |
| 12 ) | |
| 13 | |
| 14 // DescriptorPath returns the StreamPath for a descriptor. | |
| 15 func DescriptorPath(d *protocol.LogStreamDescriptor) types.StreamPath { | |
| 16 if d == nil { | |
| 17 return types.StreamPath("") | |
| 18 } | |
| 19 return types.StreamName(d.GetPrefix()).Join(types.StreamName(d.GetName() )) | |
| 20 } | |
| 21 | |
| 22 // NewTimestamp creates a new Butler protocol Timestamp from a time.Time type. | |
| 23 func NewTimestamp(t time.Time) *protocol.Timestamp { | |
| 24 value := uint64(t.UTC().UnixNano()) / uint64(time.Microsecond) | |
| 25 return &protocol.Timestamp{ | |
| 26 UsFromEpoch: &value, | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 // TimeOffset returns the equivalent time offset in microseconds for a Duration. | |
| 31 // This is suitable for use in offset-since-microseconds protobuf fields. | |
| 32 func TimeOffset(d time.Duration) uint64 { | |
| 33 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.
| |
| 34 if offset < 0 { | |
| 35 offset = 0 | |
| 36 } | |
| 37 value := uint64(offset / int64(time.Microsecond)) | |
| 38 return value | |
| 39 } | |
| OLD | NEW |