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

Unified Diff: common/logdog/types/streamname.go

Issue 1272893004: LogDog: Update protobufs, add support library. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update comment. 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
« no previous file with comments | « common/logdog/protocol/types.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/types/streamname.go
diff --git a/common/logdog/types/streamname.go b/common/logdog/types/streamname.go
index 8e4db5c9e0126d17c7cea0bf23959710954a67ab..4732a8420f8d0cd9a0d4b7cca1ee4ca34ef3e089 100644
--- a/common/logdog/types/streamname.go
+++ b/common/logdog/types/streamname.go
@@ -5,6 +5,7 @@
package types
import (
+ "encoding/json"
"errors"
"fmt"
"strings"
@@ -209,6 +210,25 @@ func (s StreamName) SegmentCount() int {
return strings.Count(string(s), string(StreamNameSep)) + 1
}
+// UnmarshalJSON implements json.Unmarshaler.
+func (s *StreamName) UnmarshalJSON(data []byte) error {
+ v := ""
+ if err := json.Unmarshal(data, &v); err != nil {
+ return err
+ }
+ if err := StreamName(v).Validate(); err != nil {
+ return err
+ }
+ *s = StreamName(v)
+ return nil
+}
+
+// MarshalJSON implements json.Marshaler.
+func (s StreamName) MarshalJSON() ([]byte, error) {
+ v := string(s)
+ return json.Marshal(&v)
+}
+
// A StreamPath consists of two StreamName, joined via a StreamPathSep (+)
// separator.
type StreamPath string
@@ -239,3 +259,22 @@ func (p StreamPath) Validate() error {
}
return nil
}
+
+// UnmarshalJSON implements json.Unmarshaler.
+func (p *StreamPath) UnmarshalJSON(data []byte) error {
+ v := ""
+ if err := json.Unmarshal(data, &v); err != nil {
+ return err
+ }
+ if err := StreamPath(v).Validate(); err != nil {
+ return err
+ }
+ *p = StreamPath(v)
+ return nil
+}
+
+// MarshalJSON implements json.Marshaler.
+func (p StreamPath) MarshalJSON() ([]byte, error) {
+ v := string(p)
+ return json.Marshal(&v)
+}
« no previous file with comments | « common/logdog/protocol/types.pb.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698