diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/api/Azure.Messaging.WebPubSub.Client.netstandard2.0.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/api/Azure.Messaging.WebPubSub.Client.netstandard2.0.cs index 0110be1c4dc3d..fd548ce588fc0 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/api/Azure.Messaging.WebPubSub.Client.netstandard2.0.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/api/Azure.Messaging.WebPubSub.Client.netstandard2.0.cs @@ -152,7 +152,7 @@ public WebPubSubJsonProtocol() { } public override string Name { get { throw null; } } public override Azure.Messaging.WebPubSub.Clients.WebPubSubProtocolMessageType WebSocketMessageType { get { throw null; } } public override System.ReadOnlyMemory GetMessageBytes(Azure.Messaging.WebPubSub.Clients.WebPubSubMessage message) { throw null; } - public override Azure.Messaging.WebPubSub.Clients.WebPubSubMessage ParseMessage(System.Buffers.ReadOnlySequence input) { throw null; } + public override System.Collections.Generic.IReadOnlyList ParseMessage(System.Buffers.ReadOnlySequence input) { throw null; } public override void WriteMessage(Azure.Messaging.WebPubSub.Clients.WebPubSubMessage message, System.Buffers.IBufferWriter output) { } } public partial class WebPubSubJsonReliableProtocol : Azure.Messaging.WebPubSub.Clients.WebPubSubProtocol @@ -162,7 +162,7 @@ public WebPubSubJsonReliableProtocol() { } public override string Name { get { throw null; } } public override Azure.Messaging.WebPubSub.Clients.WebPubSubProtocolMessageType WebSocketMessageType { get { throw null; } } public override System.ReadOnlyMemory GetMessageBytes(Azure.Messaging.WebPubSub.Clients.WebPubSubMessage message) { throw null; } - public override Azure.Messaging.WebPubSub.Clients.WebPubSubMessage ParseMessage(System.Buffers.ReadOnlySequence input) { throw null; } + public override System.Collections.Generic.IReadOnlyList ParseMessage(System.Buffers.ReadOnlySequence input) { throw null; } public override void WriteMessage(Azure.Messaging.WebPubSub.Clients.WebPubSubMessage message, System.Buffers.IBufferWriter output) { } } public abstract partial class WebPubSubMessage @@ -176,7 +176,7 @@ protected WebPubSubProtocol() { } public abstract string Name { get; } public abstract Azure.Messaging.WebPubSub.Clients.WebPubSubProtocolMessageType WebSocketMessageType { get; } public abstract System.ReadOnlyMemory GetMessageBytes(Azure.Messaging.WebPubSub.Clients.WebPubSubMessage message); - public abstract Azure.Messaging.WebPubSub.Clients.WebPubSubMessage ParseMessage(System.Buffers.ReadOnlySequence input); + public abstract System.Collections.Generic.IReadOnlyList ParseMessage(System.Buffers.ReadOnlySequence input); public abstract void WriteMessage(Azure.Messaging.WebPubSub.Clients.WebPubSubMessage message, System.Buffers.IBufferWriter output); } public enum WebPubSubProtocolMessageType diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocol.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocol.cs index e8dcab7c3dbf3..fc54a90b7d0a3 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocol.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocol.cs @@ -46,7 +46,7 @@ public override ReadOnlyMemory GetMessageBytes(WebPubSubMessage message) /// /// The serialized representation of the message. /// A - public override WebPubSubMessage ParseMessage(ReadOnlySequence input) + public override IReadOnlyList ParseMessage(ReadOnlySequence input) { return _processor.ParseMessage(input); } diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocolBase.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocolBase.cs index e3109c2172daa..49cc0152a92d2 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocolBase.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonProtocolBase.cs @@ -67,7 +67,7 @@ public ReadOnlyMemory GetMessageBytes(WebPubSubMessage message) return new Memory(writer.ToArray()); } - public virtual WebPubSubMessage ParseMessage(ReadOnlySequence input) + public virtual IReadOnlyList ParseMessage(ReadOnlySequence input) { try { @@ -264,7 +264,7 @@ public virtual WebPubSubMessage ParseMessage(ReadOnlySequence input) case DownstreamEventType.Ack: AssertNotNull(ackId, AckIdPropertyName); AssertNotNull(success, SuccessPropertyName); - return new AckMessage(ackId.Value, success.Value, errorDetail); + return new List { new AckMessage(ackId.Value, success.Value, errorDetail) }; case DownstreamEventType.Message: AssertNotNull(from, FromPropertyName); @@ -273,10 +273,10 @@ public virtual WebPubSubMessage ParseMessage(ReadOnlySequence input) switch (fromType) { case FromType.Server: - return new ServerDataMessage(dataType, data, sequenceId); + return new List { new ServerDataMessage(dataType, data, sequenceId) }; case FromType.Group: AssertNotNull(group, GroupPropertyName); - return new GroupDataMessage(group, dataType, data, sequenceId, fromUserId); + return new List { new GroupDataMessage(group, dataType, data, sequenceId, fromUserId) }; // Forward compatible default: return null; @@ -288,9 +288,9 @@ public virtual WebPubSubMessage ParseMessage(ReadOnlySequence input) switch (systemEventType) { case SystemEventType.Connected: - return new ConnectedMessage(userId, connectionId, reconnectionToken); + return new List { new ConnectedMessage(userId, connectionId, reconnectionToken) }; case SystemEventType.Disconnected: - return new DisconnectedMessage(message); + return new List { new DisconnectedMessage(message) }; // Forward compatible default: return null; diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonReliableProtocol.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonReliableProtocol.cs index 019d6e6a8fcc2..c9db9f8e2afb2 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonReliableProtocol.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubJsonReliableProtocol.cs @@ -46,7 +46,7 @@ public override ReadOnlyMemory GetMessageBytes(WebPubSubMessage message) /// /// The serialized representation of the message. /// A - public override WebPubSubMessage ParseMessage(ReadOnlySequence input) + public override IReadOnlyList ParseMessage(ReadOnlySequence input) { return _processor.ParseMessage(input); } diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubProtocol.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubProtocol.cs index ee27741d6701b..b4ffd0d9fd519 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubProtocol.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/Protocols/WebPubSubProtocol.cs @@ -29,7 +29,7 @@ public abstract class WebPubSubProtocol /// /// The serialized representation of the message. /// A - public abstract WebPubSubMessage ParseMessage(ReadOnlySequence input); + public abstract IReadOnlyList ParseMessage(ReadOnlySequence input); /// /// Writes the specified to a writer. diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/WebPubSubClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/WebPubSubClient.cs index 11342ccbc60b4..7efb2e7cdc7e9 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/WebPubSubClient.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/src/WebPubSubClient.cs @@ -518,8 +518,10 @@ private async Task ListenLoop(IWebSocketClient client, CancellationToken token) { try { - var message = _protocol.ParseMessage(result.Payload); - await HandleMessageAsync(message, token).ConfigureAwait(false); + foreach (var message in _protocol.ParseMessage(result.Payload)) + { + await HandleMessageAsync(message, token).ConfigureAwait(false); + } } catch (Exception ex) { diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/tests/Protocols/JsonProtocolTests.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/tests/Protocols/JsonProtocolTests.cs index c2ca7e1214170..1d6dc80882683 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/tests/Protocols/JsonProtocolTests.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub.Client/tests/Protocols/JsonProtocolTests.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; @@ -152,7 +153,7 @@ public void ParseMessageTest(byte[] payload, Action messageAss { var protocol = new WebPubSubJsonProtocol(); var resolvedMessage = protocol.ParseMessage(new ReadOnlySequence(payload)); - messageAssert(resolvedMessage); + messageAssert(resolvedMessage[0]); } [TestCaseSource(nameof(GetSerializingTestData))]