File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,6 +74,18 @@ type PipToken Gostr
7474// - next 32 bytes as client identifier (random)
7575type PipMsg Gostr
7676
77+ // AsPipMsg typecast Gostr m to PipMsg.
78+ // m must be a 64 bytes hex string
79+ // (32b for msg + 32b for opaque-id).
80+ // Returns nil if the string m is nil or not a valid PipMsg.
81+ func AsPipMsg (m * Gostr ) * PipMsg {
82+ p := (* PipMsg )(m )
83+ if ! p .ok () {
84+ return nil
85+ }
86+ return p
87+ }
88+
7789// go.dev/play/p/OTMIv7FLtVs
7890func pipmsgof (m string ) * PipMsg {
7991 // 2 chars per byte in hex
@@ -85,6 +97,15 @@ func pipmsgof(m string) *PipMsg {
8597 return & PipMsg {S : m }
8698}
8799
100+ // Returns empty Gostr if p is nil or invalid PipMsg.
101+ func (p * PipMsg ) AsGostr () * Gostr {
102+ if ! p .ok () {
103+ return emptyGostr
104+ }
105+ // go.dev/play/p/hPFgE9s9tMP
106+ return (* Gostr )(p )
107+ }
108+
88109func (p * PipMsg ) v () string {
89110 if p == nil {
90111 return ""
You can’t perform that action at this time.
0 commit comments