private async ValueTask <byte[]?> SerializeAsync <TValue>(
            object?message,
            MessageComponentType componentType,
            MessageSerializationContext context)
        {
            if (message == null)
            {
                return(null);
            }

            if (message is Stream inputStream)
            {
                return(await inputStream.ReadAllAsync().ConfigureAwait(false));
            }

            if (message is byte[] inputBytes)
            {
                return(inputBytes);
            }

            return(await new AvroSerializer <TValue>(
                       SchemaRegistryClientFactory.GetClient(SchemaRegistryConfig),
                       AvroSerializerConfig)
                   .SerializeAsync(
                       (TValue)message,
                       GetConfluentSerializationContext(componentType, context))
                   .ConfigureAwait(false));
        }
        private async Task <TValue?> DeserializeAsync <TValue>(
            byte[]?message,
            MessageComponentType componentType,
            MessageSerializationContext context)
            where TValue : class
        {
            if (message == null)
            {
                return(null);
            }

            var avroDeserializer = new AvroDeserializer <TValue>(
                SchemaRegistryClientFactory.GetClient(SchemaRegistryConfig),
                AvroSerializerConfig);

            var confluentSerializationContext = GetConfluentSerializationContext(componentType, context);

            return(await avroDeserializer.DeserializeAsync(
                       new ReadOnlyMemory <byte>(message),
                       false,
                       confluentSerializationContext)
                   .ConfigureAwait(false));
        }