Load longer messages
This commit is contained in:
parent
158189ae7d
commit
56fa617f26
1 changed files with 21 additions and 6 deletions
27
main.go
27
main.go
|
@ -77,16 +77,31 @@ func (c *Client) Send(msgType MessageType, data *string, subType *string, metada
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) rawReceive(messageEnding string) (string, error) {
|
||||||
|
received := ""
|
||||||
|
|
||||||
|
for !strings.HasSuffix(received, messageEnding) {
|
||||||
|
data := make([]byte, 20480)
|
||||||
|
_, err := c.Con.Read(data)
|
||||||
|
if err != nil {
|
||||||
|
return received, err
|
||||||
|
}
|
||||||
|
|
||||||
|
received = received + string(bytes.Trim(data, "\x00"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return received, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) ReceivePlain() ([]RawMessage, error) {
|
func (c *Client) ReceivePlain() ([]RawMessage, error) {
|
||||||
data := make([]byte, 20480)
|
received, err := c.rawReceive("}")
|
||||||
_, err := c.Con.Read(data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
messages := []RawMessage{}
|
messages := []RawMessage{}
|
||||||
|
|
||||||
for _, message := range strings.Split(string(bytes.Trim(data, "\x00")), "}") {
|
for _, message := range strings.Split(received, "}") {
|
||||||
if strings.TrimSpace(message) == "" {
|
if strings.TrimSpace(message) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -104,15 +119,14 @@ func (c *Client) ReceivePlain() ([]RawMessage, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Receive() ([]RawMessage, error) {
|
func (c *Client) Receive() ([]RawMessage, error) {
|
||||||
data := make([]byte, 20480)
|
received, err := c.rawReceive("]")
|
||||||
_, err := c.Con.Read(data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
messages := []RawMessage{}
|
messages := []RawMessage{}
|
||||||
|
|
||||||
for _, message := range strings.Split(string(bytes.Trim(data, "\x00")), "]") {
|
for _, message := range strings.Split(received, "]") {
|
||||||
if strings.TrimSpace(message) == "" {
|
if strings.TrimSpace(message) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -174,6 +188,7 @@ func (c *Client) HandshakeLoop(clientVersion string, password string) error {
|
||||||
c.Username,
|
c.Username,
|
||||||
password,
|
password,
|
||||||
clientVersion,
|
clientVersion,
|
||||||
|
"",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue