Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 2 additions & 11 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
}
public static partial class AzureCoreExtensions
{
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelJsonSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelXmlSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -718,17 +720,6 @@ internal RetryOptions() { }
public Azure.Core.RetryMode Mode { get { throw null; } set { } }
public System.TimeSpan NetworkTimeout { get { throw null; } set { } }
}
public sealed partial class SequenceWriter : System.Buffers.IBufferWriter<byte>, System.IDisposable
{
public SequenceWriter(int segmentSize = 4096) { }
public void Advance(int bytesWritten) { }
public void CopyTo(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { }
public System.Threading.Tasks.Task CopyToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { throw null; }
public void Dispose() { }
public System.Memory<byte> GetMemory(int sizeHint = 0) { throw null; }
public System.Span<byte> GetSpan(int sizeHint = 0) { throw null; }
public bool TryComputeLength(out long length) { throw null; }
}
public partial class StatusCodeClassifier : Azure.Core.ResponseClassifier
{
public StatusCodeClassifier(System.ReadOnlySpan<ushort> successStatusCodes) { }
Expand Down
13 changes: 2 additions & 11 deletions sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
}
public static partial class AzureCoreExtensions
{
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelJsonSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelXmlSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -718,17 +720,6 @@ internal RetryOptions() { }
public Azure.Core.RetryMode Mode { get { throw null; } set { } }
public System.TimeSpan NetworkTimeout { get { throw null; } set { } }
}
public sealed partial class SequenceWriter : System.Buffers.IBufferWriter<byte>, System.IDisposable
{
public SequenceWriter(int segmentSize = 4096) { }
public void Advance(int bytesWritten) { }
public void CopyTo(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { }
public System.Threading.Tasks.Task CopyToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { throw null; }
public void Dispose() { }
public System.Memory<byte> GetMemory(int sizeHint = 0) { throw null; }
public System.Span<byte> GetSpan(int sizeHint = 0) { throw null; }
public bool TryComputeLength(out long length) { throw null; }
}
public partial class StatusCodeClassifier : Azure.Core.ResponseClassifier
{
public StatusCodeClassifier(System.ReadOnlySpan<ushort> successStatusCodes) { }
Expand Down
13 changes: 2 additions & 11 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
}
public static partial class AzureCoreExtensions
{
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelJsonSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelXmlSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -718,17 +720,6 @@ internal RetryOptions() { }
public Azure.Core.RetryMode Mode { get { throw null; } set { } }
public System.TimeSpan NetworkTimeout { get { throw null; } set { } }
}
public sealed partial class SequenceWriter : System.Buffers.IBufferWriter<byte>, System.IDisposable
{
public SequenceWriter(int segmentSize = 4096) { }
public void Advance(int bytesWritten) { }
public void CopyTo(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { }
public System.Threading.Tasks.Task CopyToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { throw null; }
public void Dispose() { }
public System.Memory<byte> GetMemory(int sizeHint = 0) { throw null; }
public System.Span<byte> GetSpan(int sizeHint = 0) { throw null; }
public bool TryComputeLength(out long length) { throw null; }
}
public partial class StatusCodeClassifier : Azure.Core.ResponseClassifier
{
public StatusCodeClassifier(System.ReadOnlySpan<ushort> successStatusCodes) { }
Expand Down
13 changes: 2 additions & 11 deletions sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
}
public static partial class AzureCoreExtensions
{
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelJsonSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelXmlSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -718,17 +720,6 @@ internal RetryOptions() { }
public Azure.Core.RetryMode Mode { get { throw null; } set { } }
public System.TimeSpan NetworkTimeout { get { throw null; } set { } }
}
public sealed partial class SequenceWriter : System.Buffers.IBufferWriter<byte>, System.IDisposable
{
public SequenceWriter(int segmentSize = 4096) { }
public void Advance(int bytesWritten) { }
public void CopyTo(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { }
public System.Threading.Tasks.Task CopyToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { throw null; }
public void Dispose() { }
public System.Memory<byte> GetMemory(int sizeHint = 0) { throw null; }
public System.Span<byte> GetSpan(int sizeHint = 0) { throw null; }
public bool TryComputeLength(out long length) { throw null; }
}
public partial class StatusCodeClassifier : Azure.Core.ResponseClassifier
{
public StatusCodeClassifier(System.ReadOnlySpan<ushort> successStatusCodes) { }
Expand Down
13 changes: 2 additions & 11 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
}
public static partial class AzureCoreExtensions
{
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelJsonSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static System.BinaryData ToBinaryData(this Azure.Core.Serialization.IModelXmlSerializable<object> model, Azure.Core.Serialization.ModelSerializerOptions? options = null) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -718,17 +720,6 @@ internal RetryOptions() { }
public Azure.Core.RetryMode Mode { get { throw null; } set { } }
public System.TimeSpan NetworkTimeout { get { throw null; } set { } }
}
public sealed partial class SequenceWriter : System.Buffers.IBufferWriter<byte>, System.IDisposable
{
public SequenceWriter(int segmentSize = 4096) { }
public void Advance(int bytesWritten) { }
public void CopyTo(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { }
public System.Threading.Tasks.Task CopyToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { throw null; }
public void Dispose() { }
public System.Memory<byte> GetMemory(int sizeHint = 0) { throw null; }
public System.Span<byte> GetSpan(int sizeHint = 0) { throw null; }
public bool TryComputeLength(out long length) { throw null; }
}
public partial class StatusCodeClassifier : Azure.Core.ResponseClassifier
{
public StatusCodeClassifier(System.ReadOnlySpan<ushort> successStatusCodes) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Azure.Core.Perf
public class BimodalRepro
{
[Benchmark]
public SequenceWriter Bimodal()
public void Bimodal() => ConstructWriter();

private SequenceWriter ConstructWriter()
{
return new SequenceWriter();
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/src/SequenceWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Azure.Core
/// <summary>
/// A buffer writer which writes large sequences of data into smaller shared buffers.
/// </summary>
public sealed class SequenceWriter : IBufferWriter<byte>, IDisposable
internal sealed class SequenceWriter : IBufferWriter<byte>, IDisposable
{
private struct Buffer
{
Expand Down
38 changes: 38 additions & 0 deletions sdk/core/Azure.Core/src/Serialization/AzureCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Core.Json;
using Azure.Core.Serialization;

Expand Down Expand Up @@ -99,6 +102,41 @@ internal static dynamic ToDynamicFromJson(this BinaryData utf8Json, DynamicDataO
return new DynamicData(mdoc.RootElement, options);
}

/// <summary>
/// Converts an <see cref="IModelJsonSerializable{T}"/> into a <see cref="BinaryData"/>.
/// </summary>
/// <param name="model">The model to convert.</param>
/// <param name="options">The <see cref="ModelSerializerOptions"/> to use.</param>
/// <returns>A binary representation of the serialized model.</returns>
public static BinaryData ToBinaryData(this IModelJsonSerializable<object> model, ModelSerializerOptions? options = default)
{
options ??= ModelSerializerOptions.DefaultServiceOptions;
using var writer = new SequenceWriter();
using var jsonWriter = new Utf8JsonWriter(writer);
model.Serialize(jsonWriter, options);
jsonWriter.Flush();
writer.TryComputeLength(out var length);
using var stream = new MemoryStream((int)length);
writer.CopyTo(stream, default);
return new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position));
}

/// <summary>
/// Converts an <see cref="IModelXmlSerializable{T}"/> into a <see cref="BinaryData"/>.
/// </summary>
/// <param name="model">The model to convert.</param>
/// <param name="options">The <see cref="ModelSerializerOptions"/> to use.</param>
/// <returns>A binary representation of the serialized model.</returns>
public static BinaryData ToBinaryData(this IModelXmlSerializable<object> model, ModelSerializerOptions? options = default)
{
options ??= ModelSerializerOptions.DefaultServiceOptions;
using MemoryStream stream = new MemoryStream();
using XmlWriter writer = XmlWriter.Create(stream);
model.Serialize(writer, options);
writer.Flush();
return new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position));
}

private static object? GetObject(in this JsonElement element)
{
switch (element.ValueKind)
Expand Down
34 changes: 0 additions & 34 deletions sdk/core/Azure.Core/src/Shared/ModelSerializerHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)Utf8JsonReaderExtensions.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)ModelSerializerHelper.cs" LinkBase="Shared/Core" />
</ItemGroup>

<!-- Test classes to share in public space-->
Expand Down
Loading