openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
joseharriaga/powershell-dotnet-test

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Generated/Models/Files/InternalAddUploadPartRequest.Serialization.cs

127lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel.Primitives;
7using System.Collections.Generic;
8using System.Text.Json;
9using OpenAI;
10
11namespace OpenAI.Files
12{
13 internal partial class InternalAddUploadPartRequest : IJsonModel<InternalAddUploadPartRequest>
14 {
15 internal InternalAddUploadPartRequest()
16 {
17 }
18
19 protected virtual InternalAddUploadPartRequest PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
20 {
21 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
22 switch (format)
23 {
24 case "J":
25 using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions))
26 {
27 return DeserializeInternalAddUploadPartRequest(document.RootElement, options);
28 }
29 default:
30 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support reading '{options.Format}' format.");
31 }
32 }
33
34 protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
35 {
36 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
37 switch (format)
38 {
39 case "J":
40 return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
41 default:
42 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support writing '{options.Format}' format.");
43 }
44 }
45
46 BinaryData IPersistableModel<InternalAddUploadPartRequest>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
47
48 InternalAddUploadPartRequest IPersistableModel<InternalAddUploadPartRequest>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
49
50 string IPersistableModel<InternalAddUploadPartRequest>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
51
52 void IJsonModel<InternalAddUploadPartRequest>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
53 {
54 writer.WriteStartObject();
55 JsonModelWriteCore(writer, options);
56 writer.WriteEndObject();
57 }
58
59 protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
60 {
61 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
62 if (format != "J")
63 {
64 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support writing '{format}' format.");
65 }
66 if (_additionalBinaryDataProperties?.ContainsKey("data") != true)
67 {
68 writer.WritePropertyName("data"u8);
69 writer.WriteBase64StringValue(Data.ToArray(), "D");
70 }
71 // Plugin customization: remove options.Format != "W" check
72 if (_additionalBinaryDataProperties != null)
73 {
74 foreach (var item in _additionalBinaryDataProperties)
75 {
76 if (ModelSerializationExtensions.IsSentinelValue(item.Value))
77 {
78 continue;
79 }
80 writer.WritePropertyName(item.Key);
81#if NET6_0_OR_GREATER
82 writer.WriteRawValue(item.Value);
83#else
84 using (JsonDocument document = JsonDocument.Parse(item.Value))
85 {
86 JsonSerializer.Serialize(writer, document.RootElement);
87 }
88#endif
89 }
90 }
91 }
92
93 InternalAddUploadPartRequest IJsonModel<InternalAddUploadPartRequest>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
94
95 protected virtual InternalAddUploadPartRequest JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
96 {
97 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
98 if (format != "J")
99 {
100 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support reading '{format}' format.");
101 }
102 using JsonDocument document = JsonDocument.ParseValue(ref reader);
103 return DeserializeInternalAddUploadPartRequest(document.RootElement, options);
104 }
105
106 internal static InternalAddUploadPartRequest DeserializeInternalAddUploadPartRequest(JsonElement element, ModelReaderWriterOptions options)
107 {
108 if (element.ValueKind == JsonValueKind.Null)
109 {
110 return null;
111 }
112 BinaryData data = default;
113 IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
114 foreach (var prop in element.EnumerateObject())
115 {
116 if (prop.NameEquals("data"u8))
117 {
118 data = BinaryData.FromBytes(prop.Value.GetBytesFromBase64("D"));
119 continue;
120 }
121 // Plugin customization: remove options.Format != "W" check
122 additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
123 }
124 return new InternalAddUploadPartRequest(data, additionalBinaryDataProperties);
125 }
126 }
127}
128