| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Text.Json.Nodes; |
| | | 5 | | using System.Text.Json.Schema; |
| | | 6 | | |
| | | 7 | | namespace System.Text.Json.Serialization.Converters |
| | | 8 | | { |
| | | 9 | | internal sealed class ReadOnlyMemoryByteConverter : JsonConverter<ReadOnlyMemory<byte>> |
| | | 10 | | { |
| | 0 | 11 | | public override bool HandleNull => true; |
| | | 12 | | |
| | | 13 | | public override ReadOnlyMemory<byte> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions o |
| | 0 | 14 | | { |
| | 0 | 15 | | return reader.TokenType is JsonTokenType.Null ? default : reader.GetBytesFromBase64(); |
| | 0 | 16 | | } |
| | | 17 | | |
| | | 18 | | public override void Write(Utf8JsonWriter writer, ReadOnlyMemory<byte> value, JsonSerializerOptions options) |
| | 0 | 19 | | { |
| | 0 | 20 | | writer.WriteBase64StringValue(value.Span); |
| | 0 | 21 | | } |
| | | 22 | | |
| | 0 | 23 | | internal override JsonSchema? GetSchema(JsonNumberHandling _) => new() { Type = JsonSchemaType.String, ContentEn |
| | | 24 | | |
| | 0 | 25 | | internal override JsonValueType GetSupportedJsonValueTypes(JsonNumberHandling _) => JsonValueType.String; |
| | | 26 | | } |
| | | 27 | | } |
| | | 28 | | |