xP: generate our own JSON marshallers
For non-trivial types, which are expensive to serialize with encoding/json's struct reflection.
This commit is contained in:
6
xP/xP.go
6
xP/xP.go
@@ -50,7 +50,7 @@ func relayReadJSON(conn net.Conn) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
j, err := json.Marshal(&m)
|
||||
j, err := m.MarshalJSON()
|
||||
if err != nil {
|
||||
log.Println("Event marshalling failed: " + err.Error())
|
||||
return nil
|
||||
@@ -126,7 +126,7 @@ func clientWriteJSON(ctx context.Context, ws *websocket.Conn, j []byte) bool {
|
||||
}
|
||||
|
||||
func clientWriteError(ctx context.Context, ws *websocket.Conn, err error) bool {
|
||||
j, err := json.Marshal(&RelayEventMessage{
|
||||
j, err := (&RelayEventMessage{
|
||||
EventSeq: 0,
|
||||
Data: RelayEventData{
|
||||
Interface: RelayEventDataError{
|
||||
@@ -135,7 +135,7 @@ func clientWriteError(ctx context.Context, ws *websocket.Conn, err error) bool {
|
||||
Error: err.Error(),
|
||||
},
|
||||
},
|
||||
})
|
||||
}).MarshalJSON()
|
||||
if err != nil {
|
||||
log.Println("Event marshalling failed: " + err.Error())
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user