public void WriteString(ref CborWriter writer, T value) { if (values2Names.TryGetValue(value, out ReadOnlyMemory <byte> name)) { writer.WriteString(name.Span); } else { WriteInt32(ref writer, value); } }
public override void Write(ref CborWriter writer, DateTime value) { switch (_options.DateTimeFormat) { case DateTimeFormat.ISO8601: writer.WriteString(value.ToString("yyyy-MM-dd'T'HH:mm:ss.FFFK")); break; case DateTimeFormat.Unix: writer.WriteInt64(new DateTimeOffset(value).ToUnixTimeSeconds()); break; } }
public override void Write(ref CborWriter writer, CborValue value, LengthMode lengthMode) { switch (value.Type) { case CborValueType.Object: ((ICborConverter <CborObject>) this).Write(ref writer, (CborObject)value, lengthMode); break; case CborValueType.Array: ((ICborConverter <CborArray>) this).Write(ref writer, (CborArray)value, lengthMode); break; case CborValueType.Positive: writer.WriteUInt64(value.Value <ulong>()); break; case CborValueType.Negative: writer.WriteInt64(value.Value <long>()); break; case CborValueType.Single: writer.WriteSingle(value.Value <float>()); break; case CborValueType.Double: writer.WriteDouble(value.Value <double>()); break; case CborValueType.Decimal: writer.WriteDecimal(value.Value <decimal>()); break; case CborValueType.String: writer.WriteString(value.Value <string>()); break; case CborValueType.Boolean: writer.WriteBoolean(value.Value <bool>()); break; case CborValueType.Null: writer.WriteNull(); break; case CborValueType.ByteString: writer.WriteByteString(value.Value <ReadOnlyMemory <byte> >().Span); break; } }
public void WriteDiscriminator(ref CborWriter writer, Type actualType) { string discriminator = _discriminatorsByType.GetOrAdd(actualType, TypeToName); writer.WriteString(discriminator); }
public override void Write(ref CborWriter writer, string?value) { writer.WriteString(value); }