Skip to content

Commit

Permalink
fix: fix client 'retry' tag (#16)
Browse files Browse the repository at this point in the history
* fix: fix client 'retry' tag

* feat: optimize client_test
  • Loading branch information
ViolaPioggia authored Mar 10, 2024
1 parent 800cc5a commit e4da4d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"bytes"
"context"
"encoding/base64"
"encoding/binary"
"fmt"
"io"
"strconv"
"sync/atomic"

"github.com/cloudwego/hertz/pkg/network/standard"
Expand Down Expand Up @@ -288,7 +288,10 @@ func (c *Client) processEvent(msg []byte) (event *Event, err error) {
case bytes.HasPrefix(line, headerEvent):
e.Event = string(append([]byte(nil), trimHeader(len(headerEvent), line)...))
case bytes.HasPrefix(line, headerRetry):
e.Retry = binary.BigEndian.Uint64(append([]byte(nil), trimHeader(len(headerRetry), line)...))
e.Retry, err = strconv.ParseUint(b2s(append([]byte(nil), trimHeader(len(headerRetry), line)...)), 10, 64)
if err != nil {
return nil, fmt.Errorf("process message `retry` failed, err is %s", err)
}
default:
// Ignore any garbage that doesn't match what we're looking for.
}
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func publishMsgs(s *Stream, empty bool, count int) {
if empty {
s.Publish(&Event{Data: []byte("\n")})
} else {
s.Publish(&Event{Data: []byte("ping")})
s.Publish(&Event{Data: []byte("ping"), Retry: uint64(3000), Event: "test", ID: "1111"})
}
}
}
Expand Down

0 comments on commit e4da4d0

Please sign in to comment.