Skip to content

Commit

Permalink
Limit C# message length
Browse files Browse the repository at this point in the history
  • Loading branch information
irahopkinson committed May 26, 2023
1 parent c898034 commit 7162118
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion c-sharp/MessageHandlers/MessageHandlerEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IEnumerable<Message> HandleMessage(Message message)
if (message.Type != MessageType.Event)
throw new ArgumentException("Incorrect message type", nameof(message));

Console.WriteLine($"Event received: {message}");
Console.WriteLine($"Event received: {StringUtils.LimitLength(message.ToString(), 180)}");

MessageEvent evt = (MessageEvent)message;
Delegate[]? handlersToRun = null;
Expand Down
10 changes: 8 additions & 2 deletions c-sharp/MessageTransports/PapiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ private async Task SendOutgoingMessageAsync(Message message)
{
message.SenderId = _clientId;
string jsonData = JsonSerializer.Serialize(message, s_serializationOptions);
Console.WriteLine("Sending message over websocket: {0}", jsonData);
Console.WriteLine(
"Sending message over websocket: {0}",
StringUtils.LimitLength(jsonData, 180)
);
byte[] data = s_utf8WithoutBOM.GetBytes(jsonData);
await _webSocket.SendAsync(data, WebSocketMessageType.Text, true, _cancellationToken);
}
Expand Down Expand Up @@ -429,7 +432,10 @@ private async void HandleIncomingMessages()
} while (!result.EndOfMessage);

string jsonData = s_utf8WithoutBOM.GetString(message.GetBuffer(), 0, (int)message.Position);
Console.WriteLine("Received message over websocket: {0}", jsonData);
Console.WriteLine(
"Received message over websocket: {0}",
StringUtils.LimitLength(jsonData, 180)
);
return JsonSerializer.Deserialize<Message>(jsonData, s_serializationOptions);
}

Expand Down

0 comments on commit 7162118

Please sign in to comment.