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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« 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