Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter property...... #1686

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Microsoft.Azure.SignalR.Protocols/IHasSubscriberFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Azure.SignalR.Protocol
{
public interface IHasSubscriberFilter
{
string Filter { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Azure.SignalR.Protocol
/// <summary>
/// Base class for multicast data messages between Azure SignalR Service and SDK.
/// </summary>
public abstract class MulticastDataMessage : ExtensibleServiceMessage, IMessageWithTracingId
public abstract class MulticastDataMessage : ExtensibleServiceMessage, IMessageWithTracingId, IHasSubscriberFilter
{
protected MulticastDataMessage(IDictionary<string, ReadOnlyMemory<byte>> payloads, ulong? tracingId = null)
{
Expand All @@ -26,6 +26,8 @@ protected MulticastDataMessage(IDictionary<string, ReadOnlyMemory<byte>> payload
/// Gets or sets the tracing Id
/// </summary>
public ulong? TracingId { get; set; }

public string Filter { get; set; }
}

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions src/Microsoft.Azure.SignalR.Protocols/ServiceMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class ExtensibleServiceMessage : ServiceMessage
private const int TracingId = 1;
private const int Ttl = 2;
private const int Protocol = 3;
private const int Filter = 4;

internal void WriteExtensionMembers(ref MessagePackWriter writer)
{
Expand All @@ -46,6 +47,13 @@ internal void WriteExtensionMembers(ref MessagePackWriter writer)
{
count++;
}

var filter = (this as IHasSubscriberFilter)?.Filter;
if (filter != null)
{
count++;
}

// todo : count more optional fields.
writer.WriteMapHeader(count);
if (tracingId != null)
Expand All @@ -63,6 +71,11 @@ internal void WriteExtensionMembers(ref MessagePackWriter writer)
writer.Write(Protocol);
writer.Write(protocol);
}
if (filter != null)
{
writer.Write(Filter);
writer.Write(filter);
}
// todo : write more optional fields.
}

Expand Down Expand Up @@ -91,6 +104,12 @@ internal void ReadExtensionMembers(ref MessagePackReader reader)
hasProtocol.Protocol = reader.ReadString();
}
break;
case Filter:
if (this is IHasSubscriberFilter hasFilter)
{
hasFilter.Filter = reader.ReadString();
}
break;
// todo : more optional fields
default:
break;
Expand Down