Skip to content

Commit

Permalink
Merge pull request #53 from philippseith/bugfix/MsgPack_LenEncoding
Browse files Browse the repository at this point in the history
Bugfix/msg pack len encoding
  • Loading branch information
philippseith authored Aug 26, 2021
2 parents 2410339 + 5e8b36c commit 32baa81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions messagepackhubprotocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,18 @@ func (m *messagePackHubProtocol) parseMessage(buf *bytes.Buffer) (interface{}, e
if err != nil {
return nil, err
}
msgType8, err := decoder.DecodeInt8()
msgType, err := decoder.DecodeInt()
if err != nil {
return nil, err
}
// Ignore Header for all messages, except ping message that has no header
// see message spec at https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/HubProtocol.md#message-headers
if msgType8 != 6 {
if msgType != 6 {
_, err = decoder.DecodeMap()
if err != nil {
return nil, err
}
}
msgType := int(msgType8)
switch msgType {
case 1, 4:
if msgLen < 5 {
Expand Down Expand Up @@ -345,7 +344,10 @@ func (m *messagePackHubProtocol) WriteMessage(message interface{}, writer io.Wri
return err
}
case hubMessage:
if err := encoder.EncodeInt8(int8(6)); err != nil {
if err := encoder.EncodeArrayLen(1); err != nil {
return err
}
if err := encoder.EncodeInt(6); err != nil {
return err
}
case closeMessage:
Expand Down Expand Up @@ -376,7 +378,7 @@ func encodeMsgHeader(e *msgpack.Encoder, msgLen int, msgType int) (err error) {
if err = e.EncodeArrayLen(msgLen); err != nil {
return err
}
if err = e.EncodeInt8(int8(msgType)); err != nil {
if err = e.EncodeInt(int64(msgType)); err != nil {
return err
}
headers := make(map[string]interface{})
Expand Down
6 changes: 6 additions & 0 deletions signalr_test/spec/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function runE2E(protocol: signalR.IHubProtocol) {
const pong = await connection.invoke("ping");
expect(pong).toEqual("Pong!");
})
it("should send correct ping messages", async () => {
const pong = await connection.invoke("ping");
expect(pong).toEqual("Pong!");
// Wait for a ping
await new Promise(r => setTimeout(r, 5000));
})
it("should answer a simple request with multiple results", async () => {
const triple = await connection.invoke("triumphantTriple", "1.FC Bayern München");
expect(triple).toEqual(["German Championship", "DFB Cup", "Champions League"]);
Expand Down

0 comments on commit 32baa81

Please sign in to comment.