openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Generated/Internal/Utf8JsonBinaryContent.cs

52lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System.ClientModel;
6using System.IO;
7using System.Text.Json;
8using System.Threading;
9using System.Threading.Tasks;
10
11namespace OpenAI
12{
13 internal class Utf8JsonBinaryContent : BinaryContent
14 {
15 private readonly MemoryStream _stream;
16 private readonly BinaryContent _content;
17
18 public Utf8JsonBinaryContent()
19 {
20 _stream = new MemoryStream();
21 _content = Create(_stream);
22 JsonWriter = new Utf8JsonWriter(_stream);
23 }
24
25 public Utf8JsonWriter JsonWriter { get; }
26
27 public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default)
28 {
29 await JsonWriter.FlushAsync().ConfigureAwait(false);
30 await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false);
31 }
32
33 public override void WriteTo(Stream stream, CancellationToken cancellationToken = default)
34 {
35 JsonWriter.Flush();
36 _content.WriteTo(stream, cancellationToken);
37 }
38
39 public override bool TryComputeLength(out long length)
40 {
41 length = JsonWriter.BytesCommitted + JsonWriter.BytesPending;
42 return true;
43 }
44
45 public override void Dispose()
46 {
47 JsonWriter.Dispose();
48 _content.Dispose();
49 _stream.Dispose();
50 }
51 }
52}
53