From 54d658a858e993aa20a0c0918b3d54b5659d721c Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sat, 19 Aug 2023 23:55:45 +0530 Subject: [PATCH 1/9] Added custom serialization example snippet to rest publish --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 7050b8a4c..215dfd429 100644 --- a/README.md +++ b/README.md @@ -331,6 +331,21 @@ catch(AblyException ablyError) } ``` +- If sending message as a dotnet object instance, internal newtonsoft will apply default serialization settings. +- To avoid this, apply custom serialization settings externally, send it as a serialized string instead. +```csharp +var serializedData = JsonConvert.SerializeObject(message, + new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }); + +var ablyMessage = new Message("name", serializedData) {Encoding = "json"}; + +channel.Publish(ablyMessage); +``` + + ### Querying channel history ```csharp From a63d5817619aa81a958c9fe6de4fdac971705d9b Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sat, 19 Aug 2023 23:57:25 +0530 Subject: [PATCH 2/9] Added custom serialization example snippet to realtime publish --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 215dfd429..aec2fa96e 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,20 @@ if (result.IsFailure) } ``` +- If sending message as a dotnet object instance, internal newtonsoft will apply default serialization settings. +- To avoid this, apply custom serialization settings externally, send it as a serialized string instead. +```csharp +var serializedData = JsonConvert.SerializeObject(message, + new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }); + +var ablyMessage = new Message("name", serializedData) {Encoding = "json"}; + +channel.Publish(ablyMessage); +``` + ### Getting channel history Calling history returns a paginated list of message. The object is of type `PaginatedResult` and can be iterated through as a normal list. From 920a92a40fa3cd464245d3b8838286a415e4126f Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sun, 20 Aug 2023 00:14:22 +0530 Subject: [PATCH 3/9] Updated readme message for publishing the message --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aec2fa96e..2350bef4e 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ if (result.IsFailure) } ``` -- If sending message as a dotnet object instance, internal newtonsoft will apply default serialization settings. +- If publishing message as a dotnet object instance, internal newtonsoft will apply default serialization settings. - To avoid this, apply custom serialization settings externally, send it as a serialized string instead. ```csharp var serializedData = JsonConvert.SerializeObject(message, @@ -345,7 +345,7 @@ catch(AblyException ablyError) } ``` -- If sending message as a dotnet object instance, internal newtonsoft will apply default serialization settings. +- If publishing message as a dotnet object instance, internal newtonsoft will apply default serialization settings. - To avoid this, apply custom serialization settings externally, send it as a serialized string instead. ```csharp var serializedData = JsonConvert.SerializeObject(message, From 65dd1ae1f818fd672029a5a19294c5cd68ed4a92 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sun, 20 Aug 2023 18:51:01 +0530 Subject: [PATCH 4/9] Updated README for serialization settings --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2350bef4e..ade512939 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ if (result.IsFailure) ``` - If publishing message as a dotnet object instance, internal newtonsoft will apply default serialization settings. -- To avoid this, apply custom serialization settings externally, send it as a serialized string instead. +- If received data has unwanted serialization, apply custom serialization settings externally, send it as a serialized string instead. ```csharp var serializedData = JsonConvert.SerializeObject(message, new JsonSerializerSettings @@ -346,7 +346,7 @@ catch(AblyException ablyError) ``` - If publishing message as a dotnet object instance, internal newtonsoft will apply default serialization settings. -- To avoid this, apply custom serialization settings externally, send it as a serialized string instead. +- If received data has unwanted serialization, apply custom serialization settings externally, send it as a serialized string instead. ```csharp var serializedData = JsonConvert.SerializeObject(message, new JsonSerializerSettings From 63fca081c5bf82d5e8d3a75f6f7e84f2366a1b8f Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sun, 27 Aug 2023 22:30:58 +0530 Subject: [PATCH 5/9] Added spec annotation for presence methods --- src/IO.Ably.Shared/Extensions/PresenceExtensions.cs | 2 ++ src/IO.Ably.Shared/Realtime/Presence.cs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs b/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs index f151e30c0..034d4103d 100644 --- a/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs +++ b/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs @@ -9,11 +9,13 @@ public static bool IsSynthesized(this PresenceMessage msg) public static bool IsNewerThan(this PresenceMessage thisMessage, PresenceMessage thatMessage) { + // RTP2b1 if (thisMessage.IsSynthesized() || thatMessage.IsSynthesized()) { return thisMessage.Timestamp > thatMessage.Timestamp; } + // RTP2b2 var thisValues = thisMessage.Id.Split(':'); var thatValues = thatMessage.Id.Split(':'); diff --git a/src/IO.Ably.Shared/Realtime/Presence.cs b/src/IO.Ably.Shared/Realtime/Presence.cs index 7a45266f9..ee625bdac 100644 --- a/src/IO.Ably.Shared/Realtime/Presence.cs +++ b/src/IO.Ably.Shared/Realtime/Presence.cs @@ -493,6 +493,7 @@ internal void UpdatePresence(PresenceMessage msg, Action callba return; } + // RTP16 switch (_channel.State) { case ChannelState.Initialized: @@ -521,6 +522,7 @@ internal void UpdatePresence(PresenceMessage msg, Action callba } } + // RTP16b private bool PendingPresenceEnqueue(QueuedPresenceMessage msg) { if (!_connection.Options.QueueMessages) @@ -743,6 +745,7 @@ private void NotifySubscribers(PresenceMessage message) } } + // RTP5a internal void ChannelDetachedOrFailed(ErrorInfo error) { FailQueuedMessages(error); @@ -750,6 +753,7 @@ internal void ChannelDetachedOrFailed(ErrorInfo error) InternalMap.Clear(); } + // RTP5f internal void ChannelSuspended(ErrorInfo error) { /* From 698976ff2db28e714195432a5c1fc83a783d1670 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 30 Aug 2023 19:42:51 +0530 Subject: [PATCH 6/9] Revert "Added spec annotation for presence methods" This reverts commit 63fca081c5bf82d5e8d3a75f6f7e84f2366a1b8f. --- src/IO.Ably.Shared/Extensions/PresenceExtensions.cs | 2 -- src/IO.Ably.Shared/Realtime/Presence.cs | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs b/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs index 034d4103d..f151e30c0 100644 --- a/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs +++ b/src/IO.Ably.Shared/Extensions/PresenceExtensions.cs @@ -9,13 +9,11 @@ public static bool IsSynthesized(this PresenceMessage msg) public static bool IsNewerThan(this PresenceMessage thisMessage, PresenceMessage thatMessage) { - // RTP2b1 if (thisMessage.IsSynthesized() || thatMessage.IsSynthesized()) { return thisMessage.Timestamp > thatMessage.Timestamp; } - // RTP2b2 var thisValues = thisMessage.Id.Split(':'); var thatValues = thatMessage.Id.Split(':'); diff --git a/src/IO.Ably.Shared/Realtime/Presence.cs b/src/IO.Ably.Shared/Realtime/Presence.cs index ee625bdac..7a45266f9 100644 --- a/src/IO.Ably.Shared/Realtime/Presence.cs +++ b/src/IO.Ably.Shared/Realtime/Presence.cs @@ -493,7 +493,6 @@ internal void UpdatePresence(PresenceMessage msg, Action callba return; } - // RTP16 switch (_channel.State) { case ChannelState.Initialized: @@ -522,7 +521,6 @@ internal void UpdatePresence(PresenceMessage msg, Action callba } } - // RTP16b private bool PendingPresenceEnqueue(QueuedPresenceMessage msg) { if (!_connection.Options.QueueMessages) @@ -745,7 +743,6 @@ private void NotifySubscribers(PresenceMessage message) } } - // RTP5a internal void ChannelDetachedOrFailed(ErrorInfo error) { FailQueuedMessages(error); @@ -753,7 +750,6 @@ internal void ChannelDetachedOrFailed(ErrorInfo error) InternalMap.Clear(); } - // RTP5f internal void ChannelSuspended(ErrorInfo error) { /* From e57237cac11ca4a107fb3d67b0c8eeb896305952 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 30 Aug 2023 19:48:03 +0530 Subject: [PATCH 7/9] Updated readme with proper serialization doc --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ade512939..e65923749 100644 --- a/README.md +++ b/README.md @@ -235,8 +235,9 @@ if (result.IsFailure) } ``` -- If publishing message as a dotnet object instance, internal newtonsoft will apply default serialization settings. -- If received data has unwanted serialization, apply custom serialization settings externally, send it as a serialized string instead. +- When published message is a dotnet object instance, internal newtonsoft will apply default serialization settings. +- If received message has unwanted serialization, publish it as a serialized string instead by applying custom serialization settings externally. + ```csharp var serializedData = JsonConvert.SerializeObject(message, new JsonSerializerSettings @@ -345,8 +346,9 @@ catch(AblyException ablyError) } ``` -- If publishing message as a dotnet object instance, internal newtonsoft will apply default serialization settings. -- If received data has unwanted serialization, apply custom serialization settings externally, send it as a serialized string instead. +- When published message is a dotnet object instance, internal newtonsoft will apply default serialization settings. +- If received message has unwanted serialization, publish it as a serialized string instead by applying custom serialization settings externally. + ```csharp var serializedData = JsonConvert.SerializeObject(message, new JsonSerializerSettings From 078011dd672f7979018853a50ee4981ecdd6bf90 Mon Sep 17 00:00:00 2001 From: sachin shinde Date: Wed, 30 Aug 2023 23:15:20 +0530 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Owen Pearson <48608556+owenpearson@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e65923749..9c489e184 100644 --- a/README.md +++ b/README.md @@ -235,8 +235,8 @@ if (result.IsFailure) } ``` -- When published message is a dotnet object instance, internal newtonsoft will apply default serialization settings. -- If received message has unwanted serialization, publish it as a serialized string instead by applying custom serialization settings externally. +- When calling `channel.Publish` with a dotnet object instance as the message data, the library will use the Newtonsoft Json.NET library to serialize the message with default serialization settings. +- If you need to use custom seralization settings, you can apply the serialization yourself and send the resulting string as the message data: ```csharp var serializedData = JsonConvert.SerializeObject(message, From d7b66ea6a13cfee14d4dedbec5a9e7336bf6cf21 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 30 Aug 2023 23:19:55 +0530 Subject: [PATCH 9/9] Refactored readme with channel publishAsync doc properly --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c489e184..082412b6e 100644 --- a/README.md +++ b/README.md @@ -346,8 +346,8 @@ catch(AblyException ablyError) } ``` -- When published message is a dotnet object instance, internal newtonsoft will apply default serialization settings. -- If received message has unwanted serialization, publish it as a serialized string instead by applying custom serialization settings externally. +- When calling `channel.PublishAsync` with a dotnet object instance as the message data, the library will use the Newtonsoft Json.NET library to serialize the message with default serialization settings. +- If you need to use custom seralization settings, you can apply the serialization yourself and send the resulting string as the message data: ```csharp var serializedData = JsonConvert.SerializeObject(message,