forked from dfuse-io/eosws-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
44 lines (37 loc) · 997 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package eosws
import (
"encoding/json"
"fmt"
"reflect"
)
type CommonIn struct {
Type string `json:"type"`
ReqID string `json:"req_id"`
}
type MsgIn struct {
CommonIn
Data json.RawMessage `json:"data"`
}
type CommonOut struct {
Type string `json:"type"`
ReqID string `json:"req_id,omitempty"`
Fetch bool `json:"fetch,omitempty"`
Listen bool `json:"listen,omitempty"`
StartBlock int64 `json:"start_block,omitempty"`
IrreversibleOnly bool `json:"irreversible_only"`
WithProgress int64 `json:"with_progress,omitempty"`
}
func (c *CommonOut) SetType(v string) { c.Type = v }
func (c *CommonOut) SetReqID(v string) { c.ReqID = v }
func setType(msg OutgoingMessager) {
objType := reflect.TypeOf(msg).Elem()
typeName := OutgoingStructMap[objType]
if typeName == "" {
panic(fmt.Sprintf("invalid or unregistered message type: %T", msg))
}
msg.SetType(typeName)
}
type MsgOut struct {
CommonOut
Data interface{}
}