void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
        {
            if (Enabled.HasValue)
            {
                json.WriteStartObject(s_attributesPropertyNameBytes);

                json.WriteBoolean(s_enabledPropertyNameBytes, Enabled.Value);

                json.WriteEndObject();
            }

            if (!_tags.IsNullOrEmpty())
            {
                json.WriteStartObject(s_tagsPropertyNameBytes);

                foreach (KeyValuePair <string, string> kvp in _tags)
                {
                    json.WriteString(kvp.Key, kvp.Value);
                }

                json.WriteEndObject();
            }

            if (X509Certificates != null)
            {
                json.WriteStartArray(s_x5cPropertyNameBytes);

                foreach (byte[] x509certificate in X509Certificates)
                {
                    json.WriteBase64StringValue(x509certificate);
                }

                json.WriteEndArray();
            }
        }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (StartDate != null)
     {
         writer.WritePropertyName("startDate");
         writer.WriteStringValue(StartDate.Value, "O");
     }
     if (EndDate != null)
     {
         writer.WritePropertyName("endDate");
         writer.WriteStringValue(EndDate.Value, "O");
     }
     if (KeyId != null)
     {
         writer.WritePropertyName("keyId");
         writer.WriteStringValue(KeyId);
     }
     if (Value != null)
     {
         writer.WritePropertyName("value");
         writer.WriteStringValue(Value);
     }
     if (CustomKeyIdentifier != null)
     {
         writer.WritePropertyName("customKeyIdentifier");
         writer.WriteBase64StringValue(CustomKeyIdentifier);
     }
     foreach (var item in AdditionalProperties)
     {
         writer.WritePropertyName(item.Key);
         writer.WriteObjectValue(item.Value);
     }
     writer.WriteEndObject();
 }
Пример #3
0
        void Write(Utf8JsonWriter writer, IKMessageContext <TNodeId> context, TNodeId nodeId)
        {
            var a = (Span <byte>) stackalloc byte[KNodeId <TNodeId> .SizeOf];

            nodeId.Write(a);
            writer.WriteBase64StringValue(a);
        }
Пример #4
0
        public void Setup()
        {
            // Results in a number of A plus padding
            var dataWithNoEscaping = new byte[NumberOfBytes];

            // Results in a lot + and /
            byte[] dataWithEscaping = Enumerable.Range(0, NumberOfBytes)
                                      .Select(i => i % 2 == 0 ? 0xFB : 0xFF)
                                      .Select(i => (byte)i)
                                      .ToArray();

            _base64NoEscaping    = Write(dataWithNoEscaping);
            _base64HeavyEscaping = Write(dataWithEscaping);

            byte[] Write(byte[] data)
            {
                var memoryStream = new MemoryStream();

                using (var json = new Utf8JsonWriter(memoryStream))
                {
                    json.WriteBase64StringValue(data);
                    json.Flush();

                    return(memoryStream.ToArray());
                }
            }
        }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("value");
     writer.WriteBase64StringValue(StorageBundleBackup, "U");
     writer.WriteEndObject();
 }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(Quote))
     {
         writer.WritePropertyName("quote");
         writer.WriteBase64StringValue(Quote, "U");
     }
     if (Optional.IsDefined(RuntimeData))
     {
         writer.WritePropertyName("runtimeData");
         writer.WriteObjectValue(RuntimeData);
     }
     if (Optional.IsDefined(InitTimeData))
     {
         writer.WritePropertyName("initTimeData");
         writer.WriteObjectValue(InitTimeData);
     }
     if (Optional.IsDefined(DraftPolicyForAttestation))
     {
         writer.WritePropertyName("draftPolicyForAttestation");
         writer.WriteStringValue(DraftPolicyForAttestation);
     }
     writer.WriteEndObject();
 }
Пример #7
0
 public override void Write(Utf8JsonWriter writer, Image img, JsonSerializerOptions options)
 {
     using (MemoryStream mStream = new MemoryStream())
     {
         img.Save(mStream, img.RawFormat);
         writer.WriteBase64StringValue(mStream.ToArray());
     }
 }
Пример #8
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(Kind))
     {
         writer.WritePropertyName("kind");
         writer.WriteStringValue(Kind);
     }
     writer.WritePropertyName("properties");
     writer.WriteStartObject();
     if (Optional.IsDefined(Password))
     {
         writer.WritePropertyName("password");
         writer.WriteStringValue(Password);
     }
     if (Optional.IsCollectionDefined(HostNames))
     {
         writer.WritePropertyName("hostNames");
         writer.WriteStartArray();
         foreach (var item in HostNames)
         {
             writer.WriteStringValue(item);
         }
         writer.WriteEndArray();
     }
     if (Optional.IsDefined(PfxBlob))
     {
         writer.WritePropertyName("pfxBlob");
         writer.WriteBase64StringValue(PfxBlob, "D");
     }
     if (Optional.IsDefined(KeyVaultId))
     {
         writer.WritePropertyName("keyVaultId");
         writer.WriteStringValue(KeyVaultId);
     }
     if (Optional.IsDefined(KeyVaultSecretName))
     {
         writer.WritePropertyName("keyVaultSecretName");
         writer.WriteStringValue(KeyVaultSecretName);
     }
     if (Optional.IsDefined(ServerFarmId))
     {
         writer.WritePropertyName("serverFarmId");
         writer.WriteStringValue(ServerFarmId);
     }
     if (Optional.IsDefined(CanonicalName))
     {
         writer.WritePropertyName("canonicalName");
         writer.WriteStringValue(CanonicalName);
     }
     if (Optional.IsDefined(DomainValidationMethod))
     {
         writer.WritePropertyName("domainValidationMethod");
         writer.WriteStringValue(DomainValidationMethod);
     }
     writer.WriteEndObject();
     writer.WriteEndObject();
 }
Пример #9
0
 public static void WriteArray(this Utf8JsonWriter writer, Memory <byte>[] value)
 {
     writer.WriteStartArray();
     for (int i = 0; i < value.Length; i++)
     {
         writer.WriteBase64StringValue(value[i].Span);
     }
     writer.WriteEndArray();
 }
Пример #10
0
 private void WriteByteArrayAsBase64Core(byte[] data)
 {
     _arrayBufferWriter.Clear();
     using (var json = new Utf8JsonWriter(_arrayBufferWriter))
     {
         json.WriteBase64StringValue(data);
         json.Flush();
     }
 }
Пример #11
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Field != null)
     {
         writer.WritePropertyName("field");
         writer.WriteBase64StringValue(Field);
     }
     writer.WriteEndObject();
 }
Пример #12
0
 public override void Write(Utf8JsonWriter writer, byte[]?value, JsonSerializerOptions options)
 {
     if (value == null)
     {
         writer.WriteNullValue();
     }
     else
     {
         writer.WriteBase64StringValue(value);
     }
 }
Пример #13
0
 public override void Write(Utf8JsonWriter writer, TextOrBinaryData value, JsonSerializerOptions options)
 {
     if (value._str != null)
     {
         writer.WriteStringValue(value._str);
     }
     else
     {
         writer.WriteBase64StringValue(value._bytes.Span);
         writer.WriteString("encoding", "base64");
     }
 }
Пример #14
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(AppId))
     {
         writer.WritePropertyName("appId");
         writer.WriteStringValue(AppId);
     }
     if (Optional.IsDefined(Description))
     {
         writer.WritePropertyName("description");
         writer.WriteStringValue(Description);
     }
     if (Optional.IsDefined(AppUserModelId))
     {
         writer.WritePropertyName("appUserModelID");
         writer.WriteStringValue(AppUserModelId);
     }
     if (Optional.IsDefined(FriendlyName))
     {
         writer.WritePropertyName("friendlyName");
         writer.WriteStringValue(FriendlyName);
     }
     if (Optional.IsDefined(IconImageName))
     {
         writer.WritePropertyName("iconImageName");
         writer.WriteStringValue(IconImageName);
     }
     if (Optional.IsDefined(RawIcon))
     {
         writer.WritePropertyName("rawIcon");
         writer.WriteBase64StringValue(RawIcon, "D");
     }
     if (Optional.IsDefined(RawPng))
     {
         writer.WritePropertyName("rawPng");
         writer.WriteBase64StringValue(RawPng, "D");
     }
     writer.WriteEndObject();
 }
Пример #15
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(Password))
     {
         writer.WritePropertyName("password");
         writer.WriteStringValue(Password);
     }
     if (Optional.IsDefined(Value))
     {
         writer.WritePropertyName("value");
         writer.WriteBase64StringValue(Value, "D");
     }
     writer.WriteEndObject();
 }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(UrlSource))
     {
         writer.WritePropertyName("urlSource");
         writer.WriteStringValue(UrlSource);
     }
     if (Optional.IsDefined(Base64Source))
     {
         writer.WritePropertyName("base64Source");
         writer.WriteBase64StringValue(Base64Source, "D");
     }
     writer.WriteEndObject();
 }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(Data))
     {
         writer.WritePropertyName("data");
         writer.WriteBase64StringValue(Data, "U");
     }
     if (Optional.IsDefined(DataType))
     {
         writer.WritePropertyName("dataType");
         writer.WriteStringValue(DataType.Value.ToString());
     }
     writer.WriteEndObject();
 }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("id");
     writer.WriteStringValue(Id);
     writer.WritePropertyName("source");
     writer.WriteStringValue(Source);
     if (Optional.IsDefined(Data))
     {
         writer.WritePropertyName("data");
         Data.WriteTo(writer);
     }
     if (Optional.IsDefined(DataBase64))
     {
         writer.WritePropertyName("data_base64");
         writer.WriteBase64StringValue(DataBase64, "D");
     }
     writer.WritePropertyName("type");
     writer.WriteStringValue(Type);
     if (Optional.IsDefined(Time))
     {
         writer.WritePropertyName("time");
         writer.WriteStringValue(Time.Value, "O");
     }
     writer.WritePropertyName("specversion");
     writer.WriteStringValue(Specversion);
     if (Optional.IsDefined(Dataschema))
     {
         writer.WritePropertyName("dataschema");
         writer.WriteStringValue(Dataschema);
     }
     if (Optional.IsDefined(Datacontenttype))
     {
         writer.WritePropertyName("datacontenttype");
         writer.WriteStringValue(Datacontenttype);
     }
     if (Optional.IsDefined(Subject))
     {
         writer.WritePropertyName("subject");
         writer.WriteStringValue(Subject);
     }
     foreach (var item in AdditionalProperties)
     {
         writer.WritePropertyName(item.Key);
         writer.WriteObjectValue(item.Value);
     }
     writer.WriteEndObject();
 }
Пример #19
0
        public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format)
        {
            switch (format)
            {
            case "U":
                writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value));
                break;

            case "D":
                writer.WriteBase64StringValue(value);
                break;

            default:
                throw new ArgumentException($"Format is not supported: '{format}'", nameof(format));
            }
        }
Пример #20
0
        public void Write(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(DdbTypeNames.BinarySet);

            writer.WriteStartArray();

            foreach (var value in _items)
            {
                writer.WriteBase64StringValue(value);
            }

            writer.WriteEndArray();

            writer.WriteEndObject();
        }
Пример #21
0
        public override void Write(Utf8JsonWriter writer, ResolvedEvent value, JsonSerializerOptions options)
        {
            var @event = value.OriginalEvent;

            if (@event == null)
            {
                writer.WriteStartObject();
                writer.WriteEndObject();
                return;
            }

            writer.WriteStartObject();

            writer.WritePropertyName("messageId");
            options.GetConverter <Uuid>().Write(writer, @event.EventId, options);

            writer.WriteString("createdUtc", @event.Created);

            writer.WritePropertyName("position");
            options.GetConverter <Position>().Write(writer, @event.Position, options);

            writer.WriteString("streamId", @event.EventStreamId);

            writer.WritePropertyName("streamVersion");
            options.GetConverter <StreamRevision>()
            .Write(writer, StreamRevision.FromStreamPosition(@event.EventNumber), options);

            writer.WriteString("type", @event.EventType);

            writer.WritePropertyName("payload");
            if (MediaTypeHeaderValue.TryParse(@event.ContentType, out var contentType) &&
                contentType.SubType.EndsWith("json", StringComparison.Ordinal))
            {
                var reader = new Utf8JsonReader(@event.Data.Span);
                if (JsonDocument.TryParseValue(ref reader, out var payload))
                {
                    payload.WriteTo(writer);
                }
                else
                {
                    writer.WriteBase64StringValue(@event.Data.Span);
                }
            }
Пример #22
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(Kind))
     {
         writer.WritePropertyName("kind");
         writer.WriteStringValue(Kind);
     }
     writer.WritePropertyName("properties");
     writer.WriteStartObject();
     if (Optional.IsDefined(Blob))
     {
         writer.WritePropertyName("blob");
         writer.WriteBase64StringValue(Blob, "D");
     }
     if (Optional.IsDefined(PublicCertificateLocation))
     {
         writer.WritePropertyName("publicCertificateLocation");
         writer.WriteStringValue(PublicCertificateLocation.Value.ToSerialString());
     }
     writer.WriteEndObject();
     writer.WriteEndObject();
 }
Пример #23
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Picture != null)
     {
         writer.WritePropertyName("picture");
         writer.WriteBase64StringValue(Picture);
     }
     if (Age != null)
     {
         writer.WritePropertyName("age");
         writer.WriteNumberValue(Age.Value);
     }
     writer.WritePropertyName("birthday");
     writer.WriteStringValue(Birthday, "O");
     writer.WritePropertyName("fishtype");
     writer.WriteStringValue(Fishtype);
     if (Species != null)
     {
         writer.WritePropertyName("species");
         writer.WriteStringValue(Species);
     }
     writer.WritePropertyName("length");
     writer.WriteNumberValue(Length);
     if (Siblings != null)
     {
         writer.WritePropertyName("siblings");
         writer.WriteStartArray();
         foreach (var item in Siblings)
         {
             writer.WriteObjectValue(item);
         }
         writer.WriteEndArray();
     }
     writer.WriteEndObject();
 }
Пример #24
0
 public override void WriteTo(Utf8JsonWriter jsonWriter)
 {
     jsonWriter.WriteBase64StringValue(_content.GetBuffer().AsSpan(0, (int)_content.Length));
 }
Пример #25
0
 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
 {
     writer.WriteBase64StringValue(_certificate.Value.Encrypt(value));
 }
Пример #26
0
        public static void WriteObjectValue(this Utf8JsonWriter writer, object value)
        {
            switch (value)
            {
            case null:
                writer.WriteNullValue();
                break;

            case IUtf8JsonSerializable serializable:
                writer.WriteObjectValue(serializable);
                break;

            case byte[] bytes:
                writer.WriteBase64StringValue(bytes);
                break;

            case BinaryData bytes:
                writer.WriteBase64StringValue(bytes);
                break;

            case System.Text.Json.JsonElement json:
                json.WriteTo(writer);
                break;

            case int i:
                writer.WriteNumberValue(i);
                break;

            case decimal d:
                writer.WriteNumberValue(d);
                break;

            case double d:
                writer.WriteNumberValue(d);
                break;

            case float f:
                writer.WriteNumberValue(f);
                break;

            case long l:
                writer.WriteNumberValue(l);
                break;

            case string s:
                writer.WriteStringValue(s);
                break;

            case bool b:
                writer.WriteBooleanValue(b);
                break;

            case Guid g:
                writer.WriteStringValue(g);
                break;

            case DateTimeOffset dateTimeOffset:
                writer.WriteStringValue(dateTimeOffset, "O");
                break;

            case DateTime dateTime:
                writer.WriteStringValue(dateTime, "O");
                break;

            case IEnumerable <KeyValuePair <string, object> > enumerable:
                writer.WriteStartObject();
                foreach (KeyValuePair <string, object> pair in enumerable)
                {
                    writer.WritePropertyName(pair.Key);
                    writer.WriteObjectValue(pair.Value);
                }
                writer.WriteEndObject();
                break;

            case IEnumerable <object> objectEnumerable:
                writer.WriteStartArray();
                foreach (object item in objectEnumerable)
                {
                    writer.WriteObjectValue(item);
                }
                writer.WriteEndArray();
                break;

            default:
                throw new NotSupportedException("Not supported type " + value.GetType());
            }
        }
Пример #27
0
 public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options)
 {
     writer.WriteBase64StringValue(value);
 }
Пример #28
0
 public override void Write(
     Utf8JsonWriter writer,
     ReadOnlyMemory <byte> value,
     JsonSerializerOptions options) =>
 writer.WriteBase64StringValue(value.Span);
Пример #29
0
 public sealed override void Write(Utf8JsonWriter writer, BinaryData value, JsonSerializerOptions options)
 {
     writer.WriteBase64StringValue(value.ToMemory().Span);
 }
Пример #30
0
        void IJsonSerializable.WriteToJson(Utf8JsonWriter writer, WritedObjects objrefs)
        {
            var model = Model;
            EntityMemberModel mm;

            for (int i = 0; i < model.Members.Count; i++)
            {
                mm = model.Members[i];
                ref EntityMember m = ref GetMember(mm.Name);
                switch (mm.Type)
                {
                case EntityMemberType.EntityRef:
                    if (m.HasValue)     //注意:无加载值不写入给前端
                    {
                        writer.WritePropertyName(mm.Name);
                        writer.Serialize(m.ObjectValue, objrefs);
                    }
                    break;

                case EntityMemberType.EntitySet:
                    if (m.HasValue)     //注意:无加载值不写入给前端
                    {
                        writer.WritePropertyName(mm.Name);
                        writer.WriteList((IList)m.ObjectValue, objrefs);
                    }
                    break;

                case EntityMemberType.EntityRefDisplayText:
                    if (m.HasValue)     //注意:无加载值不写入给前端
                    {
                        writer.WritePropertyName(mm.Name);
                        writer.WriteStringValue((string)m.ObjectValue);
                    }
                    break;

                case EntityMemberType.DataField:
                    writer.WritePropertyName(mm.Name);
                    if (m.HasValue)
                    {
                        switch (m.ValueType)
                        {
                        case EntityFieldType.Binary:
                            writer.WriteBase64StringValue((byte[])m.ObjectValue); break;

                        case EntityFieldType.Boolean:
                            writer.WriteBooleanValue(m.BooleanValue); break;

                        case EntityFieldType.Byte:
                            writer.WriteNumberValue(m.ByteValue); break;

                        case EntityFieldType.DateTime:
                            writer.WriteStringValue(m.DateTimeValue); break;

                        case EntityFieldType.Decimal:
                            writer.WriteNumberValue(m.DecimalValue); break;

                        case EntityFieldType.Double:
                            writer.WriteNumberValue(m.DoubleValue); break;

                        case EntityFieldType.Enum:
                            writer.WriteNumberValue(m.Int32Value); break;

                        case EntityFieldType.Float:
                            writer.WriteNumberValue(m.FloatValue); break;

                        case EntityFieldType.Guid:
                            writer.WriteStringValue(m.GuidValue); break;

                        case EntityFieldType.EntityId:
                            writer.WriteStringValue((Guid)((EntityId)m.ObjectValue)); break;

                        case EntityFieldType.Int16:
                            writer.WriteNumberValue(m.Int16Value); break;

                        case EntityFieldType.UInt16:
                            writer.WriteNumberValue(m.UInt16Value); break;

                        case EntityFieldType.Int32:
                            writer.WriteNumberValue(m.Int32Value); break;

                        case EntityFieldType.UInt32:
                            writer.WriteNumberValue(m.UInt32Value); break;

                        case EntityFieldType.Int64:
                            writer.WriteNumberValue(m.Int64Value); break;

                        case EntityFieldType.UInt64:
                            writer.WriteStringValue(m.UInt64Value.ToString()); break;         //暂序列化为字符串

                        case EntityFieldType.String:
                            writer.WriteStringValue((string)m.ObjectValue); break;

                        default: throw new NotSupportedException();
                        }
                    }
                    else
                    {
                        writer.WriteNullValue();
                    }
                    break;

                default:
                    throw ExceptionHelper.NotImplemented();
                    //writer.WritePropertyName(m.Name);
                    //writer.Serialize(m.BoxedValue);
                    //break;
                }
            }