func decodeCaseACK(c *client.Conn, fields client.Fields, statusCode int, errorText string) (client.Packet, error) { if len(errorText) > 0 { return nil, &client.ServerError{ MessageType: "ack", Origin: c.Origin(), Message: errorText, StatusCode: statusCode, } } return nil, nil }
func decodeServerInvalidACK(c *client.Conn, fields client.Fields, statusCode int, errorText string) (client.Packet, error) { if len(errorText) == 0 { return nil, nil } updates, hasUpdates := fields["updates"].([]interface{}) if !hasUpdates { return nil, &client.IncompleteError{ MessageType: "ack", Origin: c.Origin(), Field: "updates"} } reply := ServerInvalidACK{ Updates: make([]client.Update, len(updates)), StatusCode: statusCode, } for index, field := range updates { var ( update map[string]interface{} channelId string version float64 ok bool ) if update, ok = field.(map[string]interface{}); !ok { return nil, &client.IncompleteError{MessageType: "ack", Origin: c.Origin(), Field: "update"} } if channelId, ok = update["channelID"].(string); !ok { return nil, &client.IncompleteError{MessageType: "ack", Origin: c.Origin(), Field: "channelID"} } if version, ok = update["version"].(float64); !ok { return nil, &client.IncompleteError{MessageType: "ack", Origin: c.Origin(), Field: "version"} } reply.Updates[index] = client.Update{ChannelId: channelId, Version: int64(version)} } return reply, nil }
func decodeUnregisterReply(c *client.Conn, fields client.Fields, statusCode int, errorText string) (client.Packet, error) { if len(errorText) > 0 { return nil, &client.ServerError{"unregister", c.Origin(), errorText, statusCode} } channelId, hasChannelId := fields["channelID"].(string) if !hasChannelId { return nil, &client.IncompleteError{"register", c.Origin(), "channelID"} } reply := ServerUnregister{ StatusCode: statusCode, ChannelId: channelId, } return reply, nil }
func decodeCaseACK(c *client.Conn, fields client.Fields, statusCode int, errorText string) (client.Packet, error) { if len(errorText) > 0 { return nil, &client.ServerError{"ack", c.Origin(), errorText, statusCode} } return nil, nil }
func decodePing(c *client.Conn, fields client.Fields, statusCode int, errorText string) (client.Packet, error) { if len(errorText) > 0 { return nil, &client.ServerError{"ping", c.Origin(), errorText, statusCode} } return ServerPing{statusCode}, nil }