You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
966 B
52 lines
966 B
package event |
|
|
|
import ( |
|
"encoding" |
|
"github.com/bytedance/sonic" |
|
) |
|
|
|
const ( |
|
TopicOnline = "postal:event:online" |
|
TopicOffline = "postal:event:offline" |
|
) |
|
|
|
type Event interface { |
|
Topic() string |
|
encoding.BinaryMarshaler |
|
encoding.BinaryUnmarshaler |
|
} |
|
|
|
// Online ==================================================== Online |
|
type Online struct { |
|
Uid string |
|
} |
|
|
|
func (o *Online) Topic() string { |
|
return TopicOnline |
|
} |
|
func (o *Online) MarshalBinary() (data []byte, err error) { |
|
data, err = sonic.Marshal(o) |
|
return |
|
} |
|
|
|
func (o *Online) UnmarshalBinary(data []byte) error { |
|
return sonic.Unmarshal(data, o) |
|
} |
|
|
|
// Offline ==================================================== Offline |
|
type Offline struct { |
|
Uid string |
|
} |
|
|
|
func (o *Offline) Topic() string { |
|
return TopicOffline |
|
} |
|
|
|
func (o *Offline) MarshalBinary() (data []byte, err error) { |
|
data, err = sonic.Marshal(o) |
|
return |
|
} |
|
|
|
func (o *Offline) UnmarshalBinary(data []byte) error { |
|
return sonic.Unmarshal(data, o) |
|
}
|
|
|