From 7fd5df590dcd8e020b7d0821eb781c25cf0a6ff9 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 15 Feb 2022 00:20:15 -0800 Subject: [PATCH 1/4] SR API updates based on architect feedback --- .../Azure.Core.Experimental.netstandard2.0.cs | 4 +- ...essageWithMetadata.cs => BinaryContent.cs} | 10 +- .../src/Azure.Messaging.EventHubs.csproj | 5 +- .../src/EventData.cs | 8 +- .../README.md | 20 ++-- ...chemaRegistry.ApacheAvro.netstandard2.0.cs | 24 ++-- ...zure.Data.SchemaRegistry.ApacheAvro.csproj | 5 +- ...der.cs => SchemaRegistryAvroSerializer.cs} | 104 +++++++++--------- ...=> SchemaRegistryAvroSerializerOptions.cs} | 4 +- ...maRegistryAvroObjectSerializerLiveTests.cs | 76 ++++++------- 10 files changed, 133 insertions(+), 127 deletions(-) rename sdk/core/Azure.Core.Experimental/src/{MessageWithMetadata.cs => BinaryContent.cs} (83%) rename sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/{SchemaRegistryAvroEncoder.cs => SchemaRegistryAvroSerializer.cs} (80%) rename sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/{SchemaRegistryAvroEncoderOptions.cs => SchemaRegistryAvroSerializerOptions.cs} (83%) diff --git a/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs b/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs index 99b9fd6aaa3f0..d4994724ec765 100644 --- a/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs +++ b/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs @@ -1,8 +1,8 @@ namespace Azure { - public partial class MessageWithMetadata + public partial class BinaryContent { - public MessageWithMetadata() { } + public BinaryContent() { } public virtual Azure.Core.ContentType? ContentType { get { throw null; } set { } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] protected virtual Azure.Core.ContentType? ContentTypeCore { get { throw null; } set { } } diff --git a/sdk/core/Azure.Core.Experimental/src/MessageWithMetadata.cs b/sdk/core/Azure.Core.Experimental/src/BinaryContent.cs similarity index 83% rename from sdk/core/Azure.Core.Experimental/src/MessageWithMetadata.cs rename to sdk/core/Azure.Core.Experimental/src/BinaryContent.cs index 077eb3fe9a609..2e943f3da407e 100644 --- a/sdk/core/Azure.Core.Experimental/src/MessageWithMetadata.cs +++ b/sdk/core/Azure.Core.Experimental/src/BinaryContent.cs @@ -8,17 +8,17 @@ namespace Azure { /// - /// A message containing a content type along with its data. + /// Content containing a content type along with its data. /// - public class MessageWithMetadata + public class BinaryContent { /// - /// Gets or sets the message data. + /// Gets or sets the data. /// public virtual BinaryData? Data { get; set; } /// - /// Gets or sets the message content type. + /// Gets or sets the content type. /// public virtual ContentType? ContentType { @@ -35,7 +35,7 @@ public virtual ContentType? ContentType protected virtual ContentType? ContentTypeCore { get; set; } /// - /// Gets whether the message is read only or not. This + /// Gets whether the content is read only or not. This /// can be overriden by inheriting classes to specify whether or /// not the message can be modified. /// diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj b/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj index f79445a2ed6f4..93b54dc229eaa 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj +++ b/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj @@ -19,7 +19,7 @@ --> - + @@ -66,4 +66,7 @@ Azure.Messaging.EventHubs + + + diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/src/EventData.cs b/sdk/eventhub/Azure.Messaging.EventHubs/src/EventData.cs index a9415aed1455e..9efe3a2ea2b69 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/src/EventData.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/src/EventData.cs @@ -19,7 +19,7 @@ namespace Azure.Messaging.EventHubs /// An Event Hubs event, encapsulating a set of data and its associated metadata. /// /// - public class EventData : MessageWithMetadata + public class EventData : BinaryContent { /// The AMQP representation of the event, allowing access to additional protocol data elements not used directly by the Event Hubs client library. private readonly AmqpAnnotatedMessage _amqpMessage; @@ -98,7 +98,7 @@ public BinaryData EventBody /// /// This member is intended to allow the string-based in this class to be - /// translated to/from the type used by the + /// translated to/from the type used by the /// base class. /// /// @@ -111,7 +111,7 @@ protected override ContentType? ContentTypeCore /// /// Hidden property that shadows the property. This is added - /// in order to inherit from . + /// in order to inherit from . /// /// [EditorBrowsable(EditorBrowsableState.Never)] @@ -123,7 +123,7 @@ public override BinaryData Data /// /// Hidden property that indicates that the is not read-only. This is part of - /// the abstraction. + /// the abstraction. /// /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md index 10d50ed556c1c..fcf0b99e8c42d 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -80,10 +80,10 @@ Details on generating a class using the Apache Avro library can be found in the In order to encode an `EventData` instance with Avro information, you can do the following: ```C# Snippet:SchemaRegistryAvroEncodeEventData -var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); +var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); var employee = new Employee { Age = 42, Name = "Caketown" }; -EventData eventData = (EventData) await encoder.EncodeMessageDataAsync(employee, messageType: typeof(EventData)); +EventData eventData = (EventData) await serializer.SerializeAsync(employee, messageType: typeof(EventData)); // the schema Id will be included as a parameter of the content type Console.WriteLine(eventData.ContentType); @@ -94,17 +94,17 @@ Console.WriteLine(eventData.EventBody); To decode an `EventData` event that you are consuming: ```C# Snippet:SchemaRegistryAvroDecodeEventData -Employee deserialized = (Employee) await encoder.DecodeMessageDataAsync(eventData, typeof(Employee)); +Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData, typeof(Employee)); Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); ``` You can also use generic methods to encode and decode the data. This may be more convenient if you are not building a library on top of the Avro encoder, as you won't have to worry about the virality of generics: ```C# Snippet:SchemaRegistryAvroEncodeEventDataGenerics -var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); +var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); var employee = new Employee { Age = 42, Name = "Caketown" }; -EventData eventData = await encoder.EncodeMessageDataAsync(employee); +EventData eventData = await serializer.SerializeAsync(employee); // the schema Id will be included as a parameter of the content type Console.WriteLine(eventData.ContentType); @@ -115,7 +115,7 @@ Console.WriteLine(eventData.EventBody); Similarly, to decode: ```C# Snippet:SchemaRegistryAvroDecodeEventDataGenerics -Employee deserialized = (Employee) await encoder.DecodeMessageDataAsync(eventData); +Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData); Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); ``` @@ -123,11 +123,11 @@ Console.WriteLine(deserialized.Name); ### Encode and decode data using `MessageWithMetadata` directly It is also possible to encode and decode using `MessageWithMetadata`. Use this option if you are not integrating with any of the messaging libraries that work with `MessageWithMetadata`. -```C# Snippet:SchemaRegistryAvroEncodeDecodeMessageWithMetadata -var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); -MessageWithMetadata messageData = await encoder.EncodeMessageDataAsync(employee); +```C# Snippet:SchemaRegistryAvroEncodeDecodeBinaryContent +var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); +BinaryContent content = await serializer.SerializeAsync(employee); -Employee decodedEmployee = await encoder.DecodeMessageDataAsync(messageData); +Employee deserializedEmployee = await serializer.DeserializeAsync(content); ``` ## Troubleshooting diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs index 0a6b0fea9fd3a..7f41a1a6d0dd3 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs @@ -1,20 +1,20 @@ namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro { - public partial class SchemaRegistryAvroEncoder + public partial class SchemaRegistryAvroSerializer { - public SchemaRegistryAvroEncoder(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.SchemaRegistryAvroEncoderOptions options = null) { } - public object DecodeMessageData(Azure.MessageWithMetadata message, System.Type dataType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public System.Threading.Tasks.ValueTask DecodeMessageDataAsync(Azure.MessageWithMetadata message, System.Type dataType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public System.Threading.Tasks.ValueTask DecodeMessageDataAsync(Azure.MessageWithMetadata message, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public TData DecodeMessageData(Azure.MessageWithMetadata message, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public Azure.MessageWithMetadata EncodeMessageData(object data, System.Type dataType = null, System.Type messageType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public System.Threading.Tasks.ValueTask EncodeMessageDataAsync(object data, System.Type dataType = null, System.Type messageType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public System.Threading.Tasks.ValueTask EncodeMessageDataAsync(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TMessage : Azure.MessageWithMetadata, new() { throw null; } - public TMessage EncodeMessageData(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TMessage : Azure.MessageWithMetadata, new() { throw null; } + public SchemaRegistryAvroSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClient client, string groupName, Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.SchemaRegistryAvroSerializerOptions options = null) { } + public object Deserialize(Azure.BinaryContent content, System.Type dataType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public System.Threading.Tasks.ValueTask DeserializeAsync(Azure.BinaryContent content, System.Type dataType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public System.Threading.Tasks.ValueTask DeserializeAsync(Azure.BinaryContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public TData Deserialize(Azure.BinaryContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public Azure.BinaryContent Serialize(object data, System.Type dataType = null, System.Type messageType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public System.Threading.Tasks.ValueTask SerializeAsync(object data, System.Type dataType = null, System.Type messageType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public System.Threading.Tasks.ValueTask SerializeAsync(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TBinaryContent : Azure.BinaryContent, new() { throw null; } + public TBinaryContent Serialize(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TBinaryContent : Azure.BinaryContent, new() { throw null; } } - public partial class SchemaRegistryAvroEncoderOptions + public partial class SchemaRegistryAvroSerializerOptions { - public SchemaRegistryAvroEncoderOptions() { } + public SchemaRegistryAvroSerializerOptions() { } public bool AutoRegisterSchemas { get { throw null; } set { } } } } diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj index 8a2fdf528bd1b..7aa39faee6fdc 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.csproj @@ -10,7 +10,7 @@ - + @@ -22,4 +22,7 @@ + + + diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoder.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs similarity index 80% rename from sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoder.cs rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs index e80c31868a127..bdece13c9903f 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoder.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs @@ -19,22 +19,22 @@ namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro { /// - /// A uses the to + /// A uses the to /// encode and decode Avro payloads. /// - public class SchemaRegistryAvroEncoder + public class SchemaRegistryAvroSerializer { private readonly SchemaRegistryClient _client; private readonly string _groupName; - private readonly SchemaRegistryAvroEncoderOptions _options; + private readonly SchemaRegistryAvroSerializerOptions _options; private const string AvroMimeType = "avro/binary"; private const int CacheCapacity = 128; private static readonly Encoding Utf8Encoding = new UTF8Encoding(false); /// - /// Initializes new instance of . + /// Initializes new instance of . /// - public SchemaRegistryAvroEncoder(SchemaRegistryClient client, string groupName, SchemaRegistryAvroEncoderOptions options = null) + public SchemaRegistryAvroSerializer(SchemaRegistryClient client, string groupName, SchemaRegistryAvroSerializerOptions options = null) { _client = client ?? throw new ArgumentNullException(nameof(client)); _groupName = groupName ?? throw new ArgumentNullException(nameof(groupName)); @@ -54,71 +54,71 @@ private enum SupportedType GenericRecord } - #region Encode + #region Serialize /// - /// Encodes the message data as Avro and stores it in . The + /// Encodes the message data as Avro and stores it in . The /// will be set to "avro/binary+schemaId" where schemaId is the ID of the schema used to encode the data. /// /// The data to serialize to Avro and encode into the message. /// An optional instance to signal the request to cancel the operation. - /// The type to encode the data into. + /// The type to encode the data into. /// The type of the data to encode. - public TMessage EncodeMessageData( + public TBinaryContent Serialize( TData data, - CancellationToken cancellationToken = default) where TMessage : MessageWithMetadata, new() - => (TMessage) EncodeMessageDataInternalAsync(data, typeof(TData), typeof(TMessage), false, cancellationToken).EnsureCompleted(); + CancellationToken cancellationToken = default) where TBinaryContent : BinaryContent, new() + => (TBinaryContent) SerializeInternalAsync(data, typeof(TData), typeof(TBinaryContent), false, cancellationToken).EnsureCompleted(); /// - /// Encodes the message data as Avro and stores it in . The + /// Encodes the message data as Avro and stores it in . The /// will be set to "avro/binary+schemaId" where schemaId is the ID of the schema used to encode the data. /// /// The data to serialize to Avro and encode into the message. /// An optional instance to signal the request to cancel the operation. - /// The type to encode the data into. + /// The type to encode the data into. /// The type of the data to encode. - public async ValueTask EncodeMessageDataAsync( + public async ValueTask SerializeAsync( TData data, - CancellationToken cancellationToken = default) where TMessage : MessageWithMetadata, new() - => (TMessage) await EncodeMessageDataInternalAsync(data, typeof(TData), typeof(TMessage), true, cancellationToken).ConfigureAwait(false); + CancellationToken cancellationToken = default) where TBinaryContent : BinaryContent, new() + => (TBinaryContent) await SerializeInternalAsync(data, typeof(TData), typeof(TBinaryContent), true, cancellationToken).ConfigureAwait(false); /// - /// Encodes the message data as Avro and stores it in . The + /// Encodes the message data as Avro and stores it in . The /// will be set to "avro/binary+schemaId" where schemaId is the ID of the schema used to encode the data. /// /// The data to serialize to Avro and encode into the message. /// The type of the data to encode. If left blank, the type will be determined at runtime by /// calling . - /// The type of message to encode the data into. Must extend from , and + /// The type of message to encode the data into. Must extend from , and /// have a parameterless constructor. - /// If left blank, the data will be encoded into a instance. + /// If left blank, the data will be encoded into a instance. /// An optional instance to signal the request to cancel the operation. - public MessageWithMetadata EncodeMessageData( + public BinaryContent Serialize( object data, Type dataType = default, Type messageType = default, CancellationToken cancellationToken = default) - => EncodeMessageDataInternalAsync(data, dataType, messageType, false, cancellationToken).EnsureCompleted(); + => SerializeInternalAsync(data, dataType, messageType, false, cancellationToken).EnsureCompleted(); /// - /// Encodes the message data as Avro and stores it in . The + /// Encodes the message data as Avro and stores it in . The /// will be set to "avro/binary+schemaId" where schemaId is the ID of the schema used to encode the data. /// /// The data to serialize to Avro and encode into the message. /// The type of the data to encode. If left blank, the type will be determined at runtime by /// calling . - /// The type of message to encode the data into. Must extend from , and + /// The type of message to encode the data into. Must extend from , and /// have a parameterless constructor. - /// If left blank, the data will be encoded into a instance. + /// If left blank, the data will be encoded into a instance. /// An optional instance to signal the request to cancel the operation. - public async ValueTask EncodeMessageDataAsync( + public async ValueTask SerializeAsync( object data, Type dataType = default, Type messageType = default, CancellationToken cancellationToken = default) - => await EncodeMessageDataInternalAsync(data, dataType, messageType, true, cancellationToken).ConfigureAwait(false); + => await SerializeInternalAsync(data, dataType, messageType, true, cancellationToken).ConfigureAwait(false); - internal async ValueTask EncodeMessageDataInternalAsync( + internal async ValueTask SerializeInternalAsync( object data, Type dataType, Type messageType, @@ -126,17 +126,17 @@ internal async ValueTask EncodeMessageDataInternalAsync( CancellationToken cancellationToken) { (string schemaId, BinaryData bd) = async - ? await EncodeInternalAsync(data, dataType, true, cancellationToken).ConfigureAwait(false) - : EncodeInternalAsync(data, dataType, false, cancellationToken).EnsureCompleted(); + ? await SerializeInternalAsync(data, dataType, true, cancellationToken).ConfigureAwait(false) + : SerializeInternalAsync(data, dataType, false, cancellationToken).EnsureCompleted(); - messageType ??= typeof(MessageWithMetadata); - var message = (MessageWithMetadata)Activator.CreateInstance(messageType); + messageType ??= typeof(BinaryContent); + var message = (BinaryContent)Activator.CreateInstance(messageType); message.Data = bd; message.ContentType = $"{AvroMimeType}+{schemaId}"; return message; } - private async ValueTask<(string SchemaId, BinaryData Data)> EncodeInternalAsync( + private async ValueTask<(string SchemaId, BinaryData Data)> SerializeInternalAsync( object value, Type dataType, bool async, @@ -231,62 +231,62 @@ private static SupportedType GetSupportedTypeOrThrow(Type type) #region Decode /// - /// Decodes the message data into the specified type using the schema information populated in . + /// Decodes the message data into the specified type using the schema information populated in . /// - /// The message containing the data to decode. + /// The message containing the data to decode. /// An optional instance to signal the request to cancel the operation. /// The type to decode the message data into. /// The deserialized data. /// Thrown if the content type is not in the expected format. /// Thrown if an attempt is made to decode non-Avro data. - public TData DecodeMessageData( - MessageWithMetadata message, + public TData Deserialize( + BinaryContent content, CancellationToken cancellationToken = default) - => (TData) DecodeMessageDataInternalAsync(message.Data, typeof(TData), message.ContentType, false, cancellationToken).EnsureCompleted(); + => (TData) DecodeMessageDataInternalAsync(content.Data, typeof(TData), content.ContentType, false, cancellationToken).EnsureCompleted(); /// - /// Decodes the message data into the specified type using the schema information populated in . + /// Decodes the message data into the specified type using the schema information populated in . /// - /// The message containing the data to decode. + /// The content to deserialize. /// An optional instance to signal the request to cancel the operation. /// The type to decode the message data into. /// The deserialized data. /// Thrown if the content type is not in the expected format. /// Thrown if an attempt is made to decode non-Avro data. - public async ValueTask DecodeMessageDataAsync( - MessageWithMetadata message, + public async ValueTask DeserializeAsync( + BinaryContent content, CancellationToken cancellationToken = default) - => (TData) await DecodeMessageDataInternalAsync(message.Data, typeof(TData), message.ContentType, true, cancellationToken).ConfigureAwait(false); + => (TData) await DecodeMessageDataInternalAsync(content.Data, typeof(TData), content.ContentType, true, cancellationToken).ConfigureAwait(false); /// - /// Decodes the message data into the specified type using the schema information populated in . + /// Decodes the message data into the specified type using the schema information populated in . /// - /// The message containing the data to decode. + /// The message containing the data to decode. /// The type to decode the message data into. /// An optional instance to signal the request to cancel the operation. /// The deserialized data. /// Thrown if the content type is not in the expected format. /// Thrown if an attempt is made to decode non-Avro data. - public object DecodeMessageData( - MessageWithMetadata message, + public object Deserialize( + BinaryContent content, Type dataType, CancellationToken cancellationToken = default) - => DecodeMessageDataInternalAsync(message.Data, dataType, message.ContentType, false, cancellationToken).EnsureCompleted(); + => DecodeMessageDataInternalAsync(content.Data, dataType, content.ContentType, false, cancellationToken).EnsureCompleted(); /// - /// Decodes the message data into the specified type using the schema information populated in . + /// Decodes the message data into the specified type using the schema information populated in . /// - /// The message containing the data to decode. + /// The message containing the data to decode. /// The type to decode the message data into. /// An optional instance to signal the request to cancel the operation. /// The deserialized data. /// Thrown if the content type is not in the expected format. /// Thrown if an attempt is made to decode non-Avro data. - public async ValueTask DecodeMessageDataAsync( - MessageWithMetadata message, + public async ValueTask DeserializeAsync( + BinaryContent content, Type dataType, CancellationToken cancellationToken = default) - => await DecodeMessageDataInternalAsync(message.Data, dataType, message.ContentType, true, cancellationToken).ConfigureAwait(false); + => await DecodeMessageDataInternalAsync(content.Data, dataType, content.ContentType, true, cancellationToken).ConfigureAwait(false); private async ValueTask DecodeMessageDataInternalAsync( BinaryData data, diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoderOptions.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializerOptions.cs similarity index 83% rename from sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoderOptions.cs rename to sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializerOptions.cs index 3af0e28bd3131..c1d8ddbd384b6 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoderOptions.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializerOptions.cs @@ -4,9 +4,9 @@ namespace Microsoft.Azure.Data.SchemaRegistry.ApacheAvro { /// - /// Options for . + /// Options for . /// - public class SchemaRegistryAvroEncoderOptions + public class SchemaRegistryAvroSerializerOptions { /// /// Gets or sets the automatic registration of schemas flag. diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs index 0cbd7c3c49023..8e4d60f07438a 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs @@ -39,16 +39,16 @@ public async Task CanSerializeAndDeserialize() var groupName = TestEnvironment.SchemaRegistryGroup; var employee = new Employee { Age = 42, Name = "Caketown" }; - #region Snippet:SchemaRegistryAvroEncodeDecodeMessageWithMetadata - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - MessageWithMetadata messageData = await encoder.EncodeMessageDataAsync(employee); + #region Snippet:SchemaRegistryAvroEncodeDecodeBinaryContent + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + BinaryContent content = await serializer.SerializeAsync(employee); - Employee decodedEmployee = await encoder.DecodeMessageDataAsync(messageData); + Employee deserializedEmployee = await serializer.DeserializeAsync(content); #endregion - Assert.IsNotNull(decodedEmployee); - Assert.AreEqual("Caketown", decodedEmployee.Name); - Assert.AreEqual(42, decodedEmployee.Age); + Assert.IsNotNull(deserializedEmployee); + Assert.AreEqual("Caketown", deserializedEmployee.Name); + Assert.AreEqual(42, deserializedEmployee.Age); } [RecordedTest] @@ -58,19 +58,19 @@ public async Task CanSerializeAndDeserializeWithCompatibleSchema() var groupName = TestEnvironment.SchemaRegistryGroup; var employee = new Employee_V2 { Age = 42, Name = "Caketown", City = "Redmond" }; - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - var messageData = await encoder.EncodeMessageDataAsync(employee); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + var content = await serializer.SerializeAsync(employee); // deserialize using the old schema, which is forward compatible with the new schema // if you swap the old schema and the new schema in your mind, then this can also be thought as a backwards compatible test - var deserializedObject = await encoder.DecodeMessageDataAsync(messageData); + var deserializedObject = await serializer.DeserializeAsync(content); var readEmployee = deserializedObject as Employee; Assert.IsNotNull(readEmployee); Assert.AreEqual("Caketown", readEmployee.Name); Assert.AreEqual(42, readEmployee.Age); // deserialize using the new schema to make sure we are respecting it - var readEmployeeV2 = await encoder.DecodeMessageDataAsync(messageData); + var readEmployeeV2 = await serializer.DeserializeAsync(content); Assert.IsNotNull(readEmployee); Assert.AreEqual("Caketown", readEmployeeV2.Name); Assert.AreEqual(42, readEmployeeV2.Age); @@ -84,12 +84,12 @@ public async Task CannotDeserializeIntoNonCompatibleType() var groupName = TestEnvironment.SchemaRegistryGroup; var employee = new Employee() { Age = 42, Name = "Caketown"}; - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - var messageData = await encoder.EncodeMessageDataAsync(employee); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + var content = await serializer.SerializeAsync(employee); // deserialize with the new schema, which is NOT backward compatible with the old schema as it adds a new field Assert.That( - async () => await encoder.DecodeMessageDataAsync(messageData), + async () => await serializer.DeserializeAsync(content), Throws.InstanceOf()); } @@ -102,10 +102,10 @@ public async Task CanSerializeAndDeserializeGenericRecord() record.Add("Name", "Caketown"); record.Add("Age", 42); - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - var messageData = await encoder.EncodeMessageDataAsync(record); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + var content = await serializer.SerializeAsync(record); - var deserializedObject = await encoder.DecodeMessageDataAsync(messageData); + var deserializedObject = await serializer.DeserializeAsync(content); var readRecord = deserializedObject as GenericRecord; Assert.IsNotNull(readRecord); Assert.AreEqual("Caketown", readRecord.GetValue(0)); @@ -119,8 +119,8 @@ public async Task CannotSerializeUnsupportedType() var groupName = TestEnvironment.SchemaRegistryGroup; var timeZoneInfo = TimeZoneInfo.Utc; - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - Assert.ThrowsAsync(async () => await encoder.EncodeMessageDataAsync(timeZoneInfo)); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + Assert.ThrowsAsync(async () => await serializer.SerializeAsync(timeZoneInfo)); await Task.CompletedTask; } @@ -130,13 +130,13 @@ public async Task CannotDeserializeUnsupportedType() var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - var messageData = new MessageWithMetadata + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + var content = new BinaryContent { Data = new BinaryData(Array.Empty()), ContentType = "avro/binary+234234" }; - Assert.ThrowsAsync(async () => await encoder.DecodeMessageDataAsync(messageData)); + Assert.ThrowsAsync(async () => await serializer.DeserializeAsync(content)); await Task.CompletedTask; } @@ -146,27 +146,27 @@ public async Task CannotDeserializeWithNullSchemaId() var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); - var messageData = new MessageWithMetadata + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); + var content = new BinaryContent { Data = new BinaryData(Array.Empty()), ContentType = null }; - Assert.ThrowsAsync(async () => await encoder.DecodeMessageDataAsync(messageData)); + Assert.ThrowsAsync(async () => await serializer.DeserializeAsync(content)); await Task.CompletedTask; } [RecordedTest] - public async Task CanUseEncoderWithEventData() + public async Task CanUseserializerWithEventData() { var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; #region Snippet:SchemaRegistryAvroEncodeEventData - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); var employee = new Employee { Age = 42, Name = "Caketown" }; - EventData eventData = (EventData) await encoder.EncodeMessageDataAsync(employee, messageType: typeof(EventData)); + EventData eventData = (EventData) await serializer.SerializeAsync(employee, messageType: typeof(EventData)); #if SNIPPET // the schema Id will be included as a parameter of the content type @@ -177,14 +177,14 @@ public async Task CanUseEncoderWithEventData() #endif #endregion - Assert.IsFalse(((MessageWithMetadata) eventData).IsReadOnly); + Assert.IsFalse(((BinaryContent) eventData).IsReadOnly); string[] contentType = eventData.ContentType.Split('+'); Assert.AreEqual(2, contentType.Length); Assert.AreEqual("avro/binary", contentType[0]); Assert.IsNotEmpty(contentType[1]); #region Snippet:SchemaRegistryAvroDecodeEventData - Employee deserialized = (Employee) await encoder.DecodeMessageDataAsync(eventData, typeof(Employee)); + Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData, typeof(Employee)); #if SNIPPET Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); @@ -204,16 +204,16 @@ public async Task CanUseEncoderWithEventData() } [RecordedTest] - public async Task CanUseEncoderWithEventDataUsingGenerics() + public async Task CanUseserializerWithEventDataUsingGenerics() { var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; #region Snippet:SchemaRegistryAvroEncodeEventDataGenerics - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); var employee = new Employee { Age = 42, Name = "Caketown" }; - EventData eventData = await encoder.EncodeMessageDataAsync(employee); + EventData eventData = await serializer.SerializeAsync(employee); #if SNIPPET // the schema Id will be included as a parameter of the content type @@ -224,14 +224,14 @@ public async Task CanUseEncoderWithEventDataUsingGenerics() #endif #endregion - Assert.IsFalse(((MessageWithMetadata) eventData).IsReadOnly); + Assert.IsFalse(((BinaryContent) eventData).IsReadOnly); string[] contentType = eventData.ContentType.Split('+'); Assert.AreEqual(2, contentType.Length); Assert.AreEqual("avro/binary", contentType[0]); Assert.IsNotEmpty(contentType[1]); #region Snippet:SchemaRegistryAvroDecodeEventDataGenerics - Employee deserialized = (Employee) await encoder.DecodeMessageDataAsync(eventData); + Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData); #if SNIPPET Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); @@ -256,10 +256,10 @@ public async Task CanDecodePreamble() var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; - var encoder = new SchemaRegistryAvroEncoder(client, groupName, new SchemaRegistryAvroEncoderOptions { AutoRegisterSchemas = true }); + var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); var employee = new Employee { Age = 42, Name = "Caketown" }; - EventData eventData = await encoder.EncodeMessageDataAsync(employee); + EventData eventData = await serializer.SerializeAsync(employee); string schemaId = eventData.ContentType.Split('+')[1]; eventData.ContentType = "avro/binary"; @@ -271,7 +271,7 @@ public async Task CanDecodePreamble() stream.Position = 0; eventData.EventBody = BinaryData.FromStream(stream); - Employee deserialized = await encoder.DecodeMessageDataAsync(eventData); + Employee deserialized = await serializer.DeserializeAsync(eventData); // decoding should not alter the message Assert.AreEqual("avro/binary", eventData.ContentType); From 40bd864ab3c0a567033bb519b98283c4ffeacad5 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 15 Feb 2022 00:25:16 -0800 Subject: [PATCH 2/4] API --- .../api/Azure.Messaging.EventHubs.netstandard2.0.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/api/Azure.Messaging.EventHubs.netstandard2.0.cs b/sdk/eventhub/Azure.Messaging.EventHubs/api/Azure.Messaging.EventHubs.netstandard2.0.cs index f2b82b301e3cb..dfecf00ed159c 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/api/Azure.Messaging.EventHubs.netstandard2.0.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/api/Azure.Messaging.EventHubs.netstandard2.0.cs @@ -1,6 +1,6 @@ namespace Azure.Messaging.EventHubs { - public partial class EventData : Azure.MessageWithMetadata + public partial class EventData : Azure.BinaryContent { public EventData() { } public EventData(System.BinaryData eventBody) { } From d14816ec917bb7a29e4bc16f5f48a5a946f3a408 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Thu, 17 Feb 2022 15:49:10 -0800 Subject: [PATCH 3/4] PR fb --- .../src/Azure.Messaging.EventHubs.csproj | 8 ++--- .../README.md | 30 +++++++++---------- ...chemaRegistry.ApacheAvro.netstandard2.0.cs | 4 +-- .../src/SchemaRegistryAvroSerializer.cs | 16 +++++----- ...maRegistryAvroObjectSerializerLiveTests.cs | 2 +- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj b/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj index 93b54dc229eaa..985e1f360f66b 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj +++ b/sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj @@ -15,10 +15,11 @@ + @@ -66,7 +67,4 @@ Azure.Messaging.EventHubs - - - diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md index fcf0b99e8c42d..f9953bddf9808 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/README.md @@ -1,6 +1,6 @@ # Azure Schema Registry Apache Avro client library for .NET -Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning, and management. This package provides an Avro encoder capable of encoding and decoding payloads containing Schema Registry schema identifiers and Avro-encoded data. +Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning, and management. This package provides an Avro serializer capable of serializing and deserializing payloads containing Schema Registry schema identifiers and Avro-serialized data. ## Getting started @@ -50,17 +50,17 @@ var schemaRegistryClient = new SchemaRegistryClient(fullyQualifiedNamespace: ful ## Key concepts -### Encoder +### Serializer -This library provides an encoder, [SchemaRegistryAvroEncoder] -[schema_registry_avro_encoder], that interacts with `EventData` events. The SchemaRegistryAvroEncoder utilizes a SchemaRegistryClient to enrich the `EventData` events with the schema ID for the schema used to encode the data. +This library provides a serializer, [SchemaRegistryAvroSerializer] +[schema_registry_avro_serializer], that interacts with `EventData` events. The SchemaRegistryAvroSerializer utilizes a SchemaRegistryClient to enrich the `EventData` events with the schema ID for the schema used to serialize the data. -This encoder requires the [Apache Avro library][apache_avro_library]. The payload types accepted by this encoder include [GenericRecord][generic_record] and [ISpecificRecord][specific_record]. +This serializer requires the [Apache Avro library][apache_avro_library]. The payload types accepted by this serializer include [GenericRecord][generic_record] and [ISpecificRecord][specific_record]. ### Examples -The following shows examples of what is available through the `SchemaRegistryAvroEncoder`. There are both sync and async methods available for these operations. These examples use a generated Apache Avro class [Employee.cs][employee] created using this schema: +The following shows examples of what is available through the `SchemaRegistryAvroSerializer`. There are both sync and async methods available for these operations. These examples use a generated Apache Avro class [Employee.cs][employee] created using this schema: ```json { @@ -76,9 +76,9 @@ The following shows examples of what is available through the `SchemaRegistryAvr Details on generating a class using the Apache Avro library can be found in the [Avro C# Documentation][avro_csharp_documentation]. -### Encode and decode data using the Event Hub EventData model +### Serialize and deserialize data using the Event Hub EventData model -In order to encode an `EventData` instance with Avro information, you can do the following: +In order to serialize an `EventData` instance with Avro information, you can do the following: ```C# Snippet:SchemaRegistryAvroEncodeEventData var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); @@ -92,14 +92,14 @@ Console.WriteLine(eventData.ContentType); Console.WriteLine(eventData.EventBody); ``` -To decode an `EventData` event that you are consuming: +To deserialize an `EventData` event that you are consuming: ```C# Snippet:SchemaRegistryAvroDecodeEventData Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData, typeof(Employee)); Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); ``` -You can also use generic methods to encode and decode the data. This may be more convenient if you are not building a library on top of the Avro encoder, as you won't have to worry about the virality of generics: +You can also use generic methods to serialize and deserialize the data. This may be more convenient if you are not building a library on top of the Avro serializer, as you won't have to worry about the virality of generics: ```C# Snippet:SchemaRegistryAvroEncodeEventDataGenerics var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); @@ -113,16 +113,16 @@ Console.WriteLine(eventData.ContentType); Console.WriteLine(eventData.EventBody); ``` -Similarly, to decode: +Similarly, to deserialize: ```C# Snippet:SchemaRegistryAvroDecodeEventDataGenerics -Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData); +Employee deserialized = await serializer.DeserializeAsync(eventData); Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); ``` -### Encode and decode data using `MessageWithMetadata` directly +### Serialize and deserialize data using `BinaryContent` directly -It is also possible to encode and decode using `MessageWithMetadata`. Use this option if you are not integrating with any of the messaging libraries that work with `MessageWithMetadata`. +It is also possible to serialize and deserialize using `BinaryContent`. Use this option if you are not integrating with any of the messaging libraries that work with `BinaryContent`. ```C# Snippet:SchemaRegistryAvroEncodeDecodeBinaryContent var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); BinaryContent content = await serializer.SerializeAsync(employee); @@ -162,7 +162,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ [code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/ [email_opencode]: mailto:opencode@microsoft.com -[schema_registry_avro_encoder]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroEncoder.cs +[schema_registry_avro_serializer]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs [employee]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/Models/Employee.cs [avro_csharp_documentation]: https://avro.apache.org/docs/current/api/csharp/html/index.html [apache_avro_library]: https://www.nuget.org/packages/Apache.Avro/ diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs index 7f41a1a6d0dd3..f98dc615f9ad6 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/api/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.netstandard2.0.cs @@ -9,8 +9,8 @@ public SchemaRegistryAvroSerializer(Azure.Data.SchemaRegistry.SchemaRegistryClie public TData Deserialize(Azure.BinaryContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public Azure.BinaryContent Serialize(object data, System.Type dataType = null, System.Type messageType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public System.Threading.Tasks.ValueTask SerializeAsync(object data, System.Type dataType = null, System.Type messageType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public System.Threading.Tasks.ValueTask SerializeAsync(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TBinaryContent : Azure.BinaryContent, new() { throw null; } - public TBinaryContent Serialize(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TBinaryContent : Azure.BinaryContent, new() { throw null; } + public System.Threading.Tasks.ValueTask SerializeAsync(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TEnvelope : Azure.BinaryContent, new() { throw null; } + public TEnvelope Serialize(TData data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where TEnvelope : Azure.BinaryContent, new() { throw null; } } public partial class SchemaRegistryAvroSerializerOptions { diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs index bdece13c9903f..82f6ce631ea55 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/src/SchemaRegistryAvroSerializer.cs @@ -62,12 +62,12 @@ private enum SupportedType /// /// The data to serialize to Avro and encode into the message. /// An optional instance to signal the request to cancel the operation. - /// The type to encode the data into. + /// The type to encode the data into. /// The type of the data to encode. - public TBinaryContent Serialize( + public TEnvelope Serialize( TData data, - CancellationToken cancellationToken = default) where TBinaryContent : BinaryContent, new() - => (TBinaryContent) SerializeInternalAsync(data, typeof(TData), typeof(TBinaryContent), false, cancellationToken).EnsureCompleted(); + CancellationToken cancellationToken = default) where TEnvelope : BinaryContent, new() + => (TEnvelope) SerializeInternalAsync(data, typeof(TData), typeof(TEnvelope), false, cancellationToken).EnsureCompleted(); /// /// Encodes the message data as Avro and stores it in . The @@ -75,12 +75,12 @@ public TBinaryContent Serialize( /// /// The data to serialize to Avro and encode into the message. /// An optional instance to signal the request to cancel the operation. - /// The type to encode the data into. + /// The type to encode the data into. /// The type of the data to encode. - public async ValueTask SerializeAsync( + public async ValueTask SerializeAsync( TData data, - CancellationToken cancellationToken = default) where TBinaryContent : BinaryContent, new() - => (TBinaryContent) await SerializeInternalAsync(data, typeof(TData), typeof(TBinaryContent), true, cancellationToken).ConfigureAwait(false); + CancellationToken cancellationToken = default) where TEnvelope : BinaryContent, new() + => (TEnvelope) await SerializeInternalAsync(data, typeof(TData), typeof(TEnvelope), true, cancellationToken).ConfigureAwait(false); /// /// Encodes the message data as Avro and stores it in . The diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs index 8e4d60f07438a..1d0bd47a3d989 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs @@ -231,7 +231,7 @@ public async Task CanUseserializerWithEventDataUsingGenerics() Assert.IsNotEmpty(contentType[1]); #region Snippet:SchemaRegistryAvroDecodeEventDataGenerics - Employee deserialized = (Employee) await serializer.DeserializeAsync(eventData); + Employee deserialized = await serializer.DeserializeAsync(eventData); #if SNIPPET Console.WriteLine(deserialized.Age); Console.WriteLine(deserialized.Name); From cfea289cb7bc12b4cb04c5a589c1b6cc40e08826 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Thu, 17 Feb 2022 16:14:48 -0800 Subject: [PATCH 4/4] fix test names --- .../tests/SchemaRegistryAvroObjectSerializerLiveTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs index 1d0bd47a3d989..856201943ef8c 100644 --- a/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs +++ b/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro/tests/SchemaRegistryAvroObjectSerializerLiveTests.cs @@ -157,7 +157,7 @@ public async Task CannotDeserializeWithNullSchemaId() } [RecordedTest] - public async Task CanUseserializerWithEventData() + public async Task CanUseEncoderWithEventData() { var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; @@ -204,7 +204,7 @@ public async Task CanUseserializerWithEventData() } [RecordedTest] - public async Task CanUseserializerWithEventDataUsingGenerics() + public async Task CanUseEncoderWithEventDataUsingGenerics() { var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup;