| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package streamclient | 5 package streamclient |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "io" | 9 "io" |
| 10 | 10 |
| 11 "github.com/luci/luci-go/common/data/recordio" | 11 "github.com/luci/luci-go/common/data/recordio" |
| 12 "github.com/luci/luci-go/logdog/api/logpb" | 12 "github.com/luci/luci-go/logdog/api/logpb" |
| 13 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" | 13 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" |
| 14 ) | 14 ) |
| 15 | 15 |
| 16 // Stream is an individual LogDog Butler stream. | 16 // Stream is an individual LogDog Butler stream. |
| 17 type Stream interface { | 17 type Stream interface { |
| 18 io.WriteCloser | 18 io.WriteCloser |
| 19 | 19 |
| 20 // WriteDatagram writes a LogDog Butler streaming datagram to the underl
ying | 20 // WriteDatagram writes a LogDog Butler streaming datagram to the underl
ying |
| 21 // Writer. | 21 // Writer. |
| 22 WriteDatagram([]byte) error | 22 WriteDatagram([]byte) error |
| 23 |
| 24 // Properties returns a copy of this Stream's properties. |
| 25 Properties() *streamproto.Properties |
| 23 } | 26 } |
| 24 | 27 |
| 25 // streamImpl is the standard implementation of the Stream interface. | 28 // streamImpl is the standard implementation of the Stream interface. |
| 26 type streamImpl struct { | 29 type streamImpl struct { |
| 27 *streamproto.Properties | |
| 28 io.WriteCloser | 30 io.WriteCloser |
| 29 | 31 |
| 32 // props is this stream's properties. |
| 33 props *streamproto.Properties |
| 34 |
| 30 // rioW is a recordio.Writer bound to the WriteCloser. This will be | 35 // rioW is a recordio.Writer bound to the WriteCloser. This will be |
| 31 // initialized on the first writeRecord invocation. | 36 // initialized on the first writeRecord invocation. |
| 32 rioW recordio.Writer | 37 rioW recordio.Writer |
| 33 } | 38 } |
| 34 | 39 |
| 35 var _ Stream = (*streamImpl)(nil) | 40 var _ Stream = (*streamImpl)(nil) |
| 36 | 41 |
| 37 func (s *streamImpl) WriteDatagram(dg []byte) error { | 42 func (s *streamImpl) WriteDatagram(dg []byte) error { |
| 38 if !s.isDatagramStream() { | 43 if !s.isDatagramStream() { |
| 39 return errors.New("not a datagram stream") | 44 return errors.New("not a datagram stream") |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 if s.rioW == nil { | 63 if s.rioW == nil { |
| 59 s.rioW = recordio.NewWriter(s.WriteCloser) | 64 s.rioW = recordio.NewWriter(s.WriteCloser) |
| 60 } | 65 } |
| 61 if _, err := s.rioW.Write(r); err != nil { | 66 if _, err := s.rioW.Write(r); err != nil { |
| 62 return err | 67 return err |
| 63 } | 68 } |
| 64 return s.rioW.Flush() | 69 return s.rioW.Flush() |
| 65 } | 70 } |
| 66 | 71 |
| 67 func (s *streamImpl) isDatagramStream() bool { | 72 func (s *streamImpl) isDatagramStream() bool { |
| 68 » return s.StreamType == logpb.StreamType_DATAGRAM | 73 » return s.props.StreamType == logpb.StreamType_DATAGRAM |
| 69 } | 74 } |
| 75 |
| 76 func (s *streamImpl) Properties() *streamproto.Properties { return s.props.Clone
() } |
| OLD | NEW |