Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WriteCore to serialization #4945

Merged
merged 30 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
657fa8d
Add WriteCore to serialization
Jul 29, 2024
bee6105
update
Jul 30, 2024
c8bf776
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 1, 2024
abed3c3
update
Aug 2, 2024
fc9cca4
update
Aug 2, 2024
021fad7
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 2, 2024
7cc94fc
update
Aug 5, 2024
b40d544
update
Aug 5, 2024
beeb1c9
update
Aug 5, 2024
788cb70
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 14, 2024
94dee95
Merge branch 'feature/v3' into writeCore4884
ArthurMa1978 Aug 15, 2024
1f68e1f
update
Aug 16, 2024
0d16eda
update
Aug 16, 2024
2c7e3ff
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 16, 2024
0077faa
update
Aug 16, 2024
7c77106
update
Aug 16, 2024
10d02cc
update
Aug 16, 2024
183bbe0
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 16, 2024
dc8b64c
update
Aug 19, 2024
843035f
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 19, 2024
70d50e1
update
Aug 21, 2024
398d3e8
update
Aug 21, 2024
61e5651
update
Aug 21, 2024
1f51878
update
Aug 21, 2024
3652559
update
Aug 22, 2024
af16826
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 22, 2024
d5acc12
update
Aug 26, 2024
3a380bb
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 26, 2024
8f05316
update
Aug 28, 2024
880ccbc
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp…
Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
<ItemGroup>
<PackageReference Update="NUnit" Version="3.13.2" />
<PackageReference Update="System.ClientModel" Version="1.1.0-beta.3" />
<PackageReference Update="Azure.Core" Version="1.39.0" />
<PackageReference Update="Azure.Core" Version="1.41.0" />
<PackageReference Update="Azure.Core.Experimental" Version="0.1.0-preview.18" />
<PackageReference Update="Azure.ResourceManager" Version="1.11.0" />
<PackageReference Update="Azure.ResourceManager" Version="1.13.0-alpha.20240805.2" />
<PackageReference Update="Azure.Core.Expressions.DataFactory" Version="1.0.0" />
<PackageReference Update="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Update="System.Diagnostics.DiagnosticSource" Version="6.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class AlignPolicy : IUtf8JsonSerializable, IJsonModel<AlignPolicy
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<AlignPolicy>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<AlignPolicy>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<AlignPolicy>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(AlignPolicy)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (Optional.IsDefined(AlignMode))
{
writer.WritePropertyName("alignMode"u8);
Expand Down Expand Up @@ -57,7 +65,6 @@ void IJsonModel<AlignPolicy>.Write(Utf8JsonWriter writer, ModelReaderWriterOptio
#endif
}
}
writer.WriteEndObject();
}

AlignPolicy IJsonModel<AlignPolicy>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class AnomalyDetectionModel : IUtf8JsonSerializable, IJsonModel<A
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<AnomalyDetectionModel>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<AnomalyDetectionModel>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<AnomalyDetectionModel>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(AnomalyDetectionModel)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (options.Format != "W")
{
writer.WritePropertyName("modelId"u8);
Expand Down Expand Up @@ -56,7 +64,6 @@ void IJsonModel<AnomalyDetectionModel>.Write(Utf8JsonWriter writer, ModelReaderW
#endif
}
}
writer.WriteEndObject();
}

AnomalyDetectionModel IJsonModel<AnomalyDetectionModel>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class AnomalyInterpretation : IUtf8JsonSerializable, IJsonModel<A
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<AnomalyInterpretation>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<AnomalyInterpretation>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<AnomalyInterpretation>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(AnomalyInterpretation)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (Optional.IsDefined(Variable))
{
writer.WritePropertyName("variable"u8);
Expand Down Expand Up @@ -57,7 +65,6 @@ void IJsonModel<AnomalyInterpretation>.Write(Utf8JsonWriter writer, ModelReaderW
#endif
}
}
writer.WriteEndObject();
}

AnomalyInterpretation IJsonModel<AnomalyInterpretation>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class AnomalyState : IUtf8JsonSerializable, IJsonModel<AnomalySta
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<AnomalyState>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<AnomalyState>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<AnomalyState>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(AnomalyState)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("timestamp"u8);
writer.WriteStringValue(Timestamp, "O");
if (Optional.IsDefined(Value))
Expand Down Expand Up @@ -59,7 +67,6 @@ void IJsonModel<AnomalyState>.Write(Utf8JsonWriter writer, ModelReaderWriterOpti
#endif
}
}
writer.WriteEndObject();
}

AnomalyState IJsonModel<AnomalyState>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class AnomalyValue : IUtf8JsonSerializable, IJsonModel<AnomalyVal
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<AnomalyValue>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<AnomalyValue>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<AnomalyValue>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(AnomalyValue)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("isAnomaly"u8);
writer.WriteBooleanValue(IsAnomaly);
writer.WritePropertyName("severity"u8);
Expand Down Expand Up @@ -58,7 +66,6 @@ void IJsonModel<AnomalyValue>.Write(Utf8JsonWriter writer, ModelReaderWriterOpti
#endif
}
}
writer.WriteEndObject();
}

AnomalyValue IJsonModel<AnomalyValue>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class CorrelationChanges : IUtf8JsonSerializable, IJsonModel<Corr
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<CorrelationChanges>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<CorrelationChanges>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<CorrelationChanges>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(CorrelationChanges)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (Optional.IsCollectionDefined(ChangedVariables))
{
writer.WritePropertyName("changedVariables"u8);
Expand All @@ -52,7 +60,6 @@ void IJsonModel<CorrelationChanges>.Write(Utf8JsonWriter writer, ModelReaderWrit
#endif
}
}
writer.WriteEndObject();
}

CorrelationChanges IJsonModel<CorrelationChanges>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class DiagnosticsInfo : IUtf8JsonSerializable, IJsonModel<Diagnos
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<DiagnosticsInfo>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<DiagnosticsInfo>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<DiagnosticsInfo>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(DiagnosticsInfo)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (Optional.IsDefined(ModelState))
{
writer.WritePropertyName("modelState"u8);
Expand Down Expand Up @@ -57,7 +65,6 @@ void IJsonModel<DiagnosticsInfo>.Write(Utf8JsonWriter writer, ModelReaderWriterO
#endif
}
}
writer.WriteEndObject();
}

DiagnosticsInfo IJsonModel<DiagnosticsInfo>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class ErrorResponse : IUtf8JsonSerializable, IJsonModel<ErrorResp
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<ErrorResponse>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<ErrorResponse>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<ErrorResponse>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(ErrorResponse)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("code"u8);
writer.WriteStringValue(Code);
writer.WritePropertyName("message"u8);
Expand All @@ -46,7 +54,6 @@ void IJsonModel<ErrorResponse>.Write(Utf8JsonWriter writer, ModelReaderWriterOpt
#endif
}
}
writer.WriteEndObject();
}

ErrorResponse IJsonModel<ErrorResponse>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class ModelInfo : IUtf8JsonSerializable, IJsonModel<ModelInfo>
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<ModelInfo>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<ModelInfo>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<ModelInfo>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(ModelInfo)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("dataSource"u8);
writer.WriteStringValue(DataSource);
if (Optional.IsDefined(DataSchema))
Expand Down Expand Up @@ -88,7 +96,6 @@ void IJsonModel<ModelInfo>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions
#endif
}
}
writer.WriteEndObject();
}

ModelInfo IJsonModel<ModelInfo>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class ModelState : IUtf8JsonSerializable, IJsonModel<ModelState>
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<ModelState>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<ModelState>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<ModelState>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(ModelState)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
if (Optional.IsCollectionDefined(EpochIds))
{
writer.WritePropertyName("epochIds"u8);
Expand Down Expand Up @@ -82,7 +90,6 @@ void IJsonModel<ModelState>.Write(Utf8JsonWriter writer, ModelReaderWriterOption
#endif
}
}
writer.WriteEndObject();
}

ModelState IJsonModel<ModelState>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public partial class MultivariateBatchDetectionOptions : IUtf8JsonSerializable,
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<MultivariateBatchDetectionOptions>)this).Write(writer, ModelSerializationExtensions.WireOptions);

void IJsonModel<MultivariateBatchDetectionOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
writer.WriteEndObject();
}

/// <param name="writer"> The JSON writer. </param>
/// <param name="options"> The client options for reading and writing models. </param>
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<MultivariateBatchDetectionOptions>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(MultivariateBatchDetectionOptions)} does not support writing '{format}' format.");
}

writer.WriteStartObject();
writer.WritePropertyName("dataSource"u8);
writer.WriteStringValue(DataSource.AbsoluteUri);
writer.WritePropertyName("topContributorCount"u8);
Expand All @@ -50,7 +58,6 @@ void IJsonModel<MultivariateBatchDetectionOptions>.Write(Utf8JsonWriter writer,
#endif
}
}
writer.WriteEndObject();
}

MultivariateBatchDetectionOptions IJsonModel<MultivariateBatchDetectionOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
Expand Down
Loading