diff --git a/src/NATS.Client.Core/NATS.Client.Core.csproj b/src/NATS.Client.Core/NATS.Client.Core.csproj
index f0a3da09c..52a723dc7 100644
--- a/src/NATS.Client.Core/NATS.Client.Core.csproj
+++ b/src/NATS.Client.Core/NATS.Client.Core.csproj
@@ -1,69 +1,81 @@
-
- netstandard2.0;netstandard2.1;net6.0;net8.0
- enable
- enable
- true
+
+ netstandard2.0;netstandard2.1;net6.0;net8.0
+ enable
+ enable
+ true
-
- pubsub;messaging
- NATS client for .NET.
- true
-
+
+ pubsub;messaging
+ NATS client for .NET.
+ true
+
-
- true
-
+
+ false
+ $(NoWarn);CS8774
+
-
- $(NoWarn);CS8774
-
-
- $(NoWarn);CS8604
-
+
+ $(NoWarn);CS8604
+
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
-
-
-
-
-
-
-
-
-
+
+ true
+
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/NATS.Client.JetStream/Models/StoredMessage.cs b/src/NATS.Client.JetStream/Models/StoredMessage.cs
index e7bd07d29..f1403d75d 100644
--- a/src/NATS.Client.JetStream/Models/StoredMessage.cs
+++ b/src/NATS.Client.JetStream/Models/StoredMessage.cs
@@ -29,8 +29,7 @@ public record StoredMessage
///
[System.Text.Json.Serialization.JsonPropertyName("data")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
- [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue)]
- public string? Data { get; set; }
+ public ReadOnlyMemory Data { get; set; }
///
/// The time the message was received
diff --git a/src/NATS.Client.KeyValueStore/NatsKVStore.cs b/src/NATS.Client.KeyValueStore/NatsKVStore.cs
index cbc8acafa..9ac784c30 100644
--- a/src/NATS.Client.KeyValueStore/NatsKVStore.cs
+++ b/src/NATS.Client.KeyValueStore/NatsKVStore.cs
@@ -261,20 +261,10 @@ public async ValueTask> GetEntryAsync(string key, ulong revisi
T? data;
NatsDeserializeException? deserializeException = null;
- if (response.Message.Data != null)
+ if (response.Message.Data.Length > 0)
{
-#if NETSTANDARD2_0
- byte[] bytes;
- try
- {
- bytes = Convert.FromBase64String(response.Message.Data);
- }
- catch (FormatException e)
- {
- throw new NatsKVException("Can't decode data message value", e);
- }
+ var buffer = new ReadOnlySequence(response.Message.Data);
- var buffer = new ReadOnlySequence(bytes);
try
{
data = serializer.Deserialize(buffer);
@@ -284,34 +274,6 @@ public async ValueTask> GetEntryAsync(string key, ulong revisi
deserializeException = new NatsDeserializeException(buffer.ToArray(), e);
data = default;
}
-#else
- var bytes = ArrayPool.Shared.Rent(response.Message.Data.Length);
- try
- {
- if (Convert.TryFromBase64String(response.Message.Data, bytes, out var written))
- {
- var buffer = new ReadOnlySequence(bytes.AsMemory(0, written));
-
- try
- {
- data = serializer.Deserialize(buffer);
- }
- catch (Exception e)
- {
- deserializeException = new NatsDeserializeException(buffer.ToArray(), e);
- data = default;
- }
- }
- else
- {
- throw new NatsKVException("Can't decode data message value");
- }
- }
- finally
- {
- ArrayPool.Shared.Return(bytes);
- }
-#endif
}
else
{
diff --git a/src/NATS.Client.ObjectStore/Internal/Encoder.cs b/src/NATS.Client.ObjectStore/Internal/Encoder.cs
index 3dd04658a..07aaadc1f 100644
--- a/src/NATS.Client.ObjectStore/Internal/Encoder.cs
+++ b/src/NATS.Client.ObjectStore/Internal/Encoder.cs
@@ -1,3 +1,4 @@
+using System.Buffers;
using System.Security.Cryptography;
namespace NATS.Client.ObjectStore.Internal;
diff --git a/src/NATS.Client.ObjectStore/NatsObjStore.cs b/src/NATS.Client.ObjectStore/NatsObjStore.cs
index 45ae0220f..0e5163c6d 100644
--- a/src/NATS.Client.ObjectStore/NatsObjStore.cs
+++ b/src/NATS.Client.ObjectStore/NatsObjStore.cs
@@ -530,17 +530,17 @@ public async ValueTask GetInfoAsync(string key, bool showDeleted
{
LastBySubj = GetMetaSubject(key),
};
+
try
{
var response = await _stream.GetAsync(request, cancellationToken);
-
- if (response.Message.Data == null)
+ if (response.Message.Data.Length == 0)
{
throw new NatsObjException("Can't decode data message value");
}
- var base64String = Convert.FromBase64String(response.Message.Data);
- var data = NatsObjJsonSerializer.Default.Deserialize(new ReadOnlySequence(base64String)) ?? throw new NatsObjException("Can't deserialize object metadata");
+ var buffer = new ReadOnlySequence(response.Message.Data);
+ var data = NatsObjJsonSerializer.Default.Deserialize(buffer) ?? throw new NatsObjException("Can't deserialize object metadata");
if (!showDeleted && data.Deleted)
{