Skip to content

Commit

Permalink
Merge pull request #804 from Cysharp/feature/FixHeartbeatSequence
Browse files Browse the repository at this point in the history
Fix heartbeat sequence error
  • Loading branch information
mayuki authored Jul 5, 2024
2 parents 031788f + de4b4a3 commit 764456c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ public StreamingHubMessageType ReadMessageType()
return (clientRequestMessageId, methodId, data.Slice(offset));
}

public (byte Sequence, long ServerSentAt, ReadOnlyMemory<byte> Metadata) ReadServerHeartbeat()
public (short Sequence, long ServerSentAt, ReadOnlyMemory<byte> Metadata) ReadServerHeartbeat()
{
//var type = reader.ReadByte(); // Type is already read by ReadMessageType
var sequence = reader.ReadByte(); // Sequence
var sequence = reader.ReadInt16(); // Sequence
var serverSentAt = reader.ReadInt64(); // ServerSentAt (2)
reader.Skip(); // Dummy (3)

return (sequence, serverSentAt, data.Slice((int)reader.Consumed));
}

public (byte Sequence, long ClientSentAt) ReadClientHeartbeatResponse()
public (short Sequence, long ClientSentAt) ReadClientHeartbeatResponse()
{
//var type = reader.ReadByte(); // Type is already read by ReadMessageType
var sequence = reader.ReadByte(); // Sequence
var sequence = reader.ReadInt16(); // Sequence
var clientSentAt = reader.ReadInt64(); // ClientSentAt (2)
reader.Skip(); // Reserved (3)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public StreamingHubMessageType ReadMessageType()

public (short Sequence, long ClientSentAt, ReadOnlyMemory<byte> Extra) ReadClientHeartbeat()
{
// [Sequence(int8), ClientSentAt(long), <Extra>]
// [Sequence(int16), ClientSentAt(long), <Extra>]
var sequence = reader.ReadInt16(); // Sequence
var clientSentAt = reader.ReadInt64(); // ClientSentAt
var extra = data.Slice((int)reader.Consumed);
Expand All @@ -89,7 +89,7 @@ public StreamingHubMessageType ReadMessageType()

public short ReadServerHeartbeatResponse()
{
// [Sequence(int8), Nil, Nil]
// [Sequence(int16), Nil, Nil]
var sequence = reader.ReadInt16(); // Sequence
reader.Skip(); // Dummy
reader.Skip(); // Dummy
Expand Down
8 changes: 4 additions & 4 deletions src/MagicOnion.Internal/StreamingHubClientMessageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ public StreamingHubMessageType ReadMessageType()
return (clientRequestMessageId, methodId, data.Slice(offset));
}

public (byte Sequence, long ServerSentAt, ReadOnlyMemory<byte> Metadata) ReadServerHeartbeat()
public (short Sequence, long ServerSentAt, ReadOnlyMemory<byte> Metadata) ReadServerHeartbeat()
{
//var type = reader.ReadByte(); // Type is already read by ReadMessageType
var sequence = reader.ReadByte(); // Sequence
var sequence = reader.ReadInt16(); // Sequence
var serverSentAt = reader.ReadInt64(); // ServerSentAt (2)
reader.Skip(); // Dummy (3)

return (sequence, serverSentAt, data.Slice((int)reader.Consumed));
}

public (byte Sequence, long ClientSentAt) ReadClientHeartbeatResponse()
public (short Sequence, long ClientSentAt) ReadClientHeartbeatResponse()
{
//var type = reader.ReadByte(); // Type is already read by ReadMessageType
var sequence = reader.ReadByte(); // Sequence
var sequence = reader.ReadInt16(); // Sequence
var clientSentAt = reader.ReadInt64(); // ClientSentAt (2)
reader.Skip(); // Reserved (3)

Expand Down
4 changes: 2 additions & 2 deletions src/MagicOnion.Internal/StreamingHubServerMessageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public StreamingHubMessageType ReadMessageType()

public (short Sequence, long ClientSentAt, ReadOnlyMemory<byte> Extra) ReadClientHeartbeat()
{
// [Sequence(int8), ClientSentAt(long), <Extra>]
// [Sequence(int16), ClientSentAt(long), <Extra>]
var sequence = reader.ReadInt16(); // Sequence
var clientSentAt = reader.ReadInt64(); // ClientSentAt
var extra = data.Slice((int)reader.Consumed);
Expand All @@ -89,7 +89,7 @@ public StreamingHubMessageType ReadMessageType()

public short ReadServerHeartbeatResponse()
{
// [Sequence(int8), Nil, Nil]
// [Sequence(int16), Nil, Nil]
var sequence = reader.ReadInt16(); // Sequence
reader.Skip(); // Dummy
reader.Skip(); // Dummy
Expand Down

0 comments on commit 764456c

Please sign in to comment.