public static void WriteUInt64_SingleValue_HappyPath(ulong input, string hexExpectedEncoding) { byte[] expectedEncoding = hexExpectedEncoding.HexToByteArray(); using var writer = new CborWriter(); writer.WriteUInt64(input); AssertHelper.HexEqual(expectedEncoding, writer.ToArray()); }
public static void WriteValue(CborWriter writer, object value, bool useDefiniteLengthCollections = true) { switch (value) { case null: writer.WriteNull(); break; case bool b: writer.WriteBoolean(b); break; case int i: writer.WriteInt64(i); break; case long i: writer.WriteInt64(i); break; case ulong i: writer.WriteUInt64(i); break; case float f: writer.WriteSingle(f); break; case double d: writer.WriteDouble(d); break; case string s: writer.WriteTextString(s); break; case byte[] b: writer.WriteByteString(b); break; case byte[][] chunks: WriteChunkedByteString(writer, chunks); break; case string[] chunks: WriteChunkedTextString(writer, chunks); break; case object[] nested when IsCborMapRepresentation(nested): WriteMap(writer, nested, useDefiniteLengthCollections); break; case object[] nested: WriteArray(writer, nested, useDefiniteLengthCollections); break; default: throw new ArgumentException($"Unrecognized argument type {value.GetType()}"); } ; }
public static void WriteValue(CborWriter writer, object value, bool useDefiniteLengthCollections = true) { switch (value) { case null: writer.WriteNull(); break; case bool b: writer.WriteBoolean(b); break; case int i: writer.WriteInt32(i); break; case long i: writer.WriteInt64(i); break; case ulong i: writer.WriteUInt64(i); break; case float f: writer.WriteSingle(f); break; case double d: writer.WriteDouble(d); break; case decimal d: writer.WriteDecimal(d); break; case string s: writer.WriteTextString(s); break; case BigInteger i: writer.WriteBigInteger(i); break; case DateTimeOffset d: writer.WriteDateTimeOffset(d); break; case byte[] b: writer.WriteByteString(b); break; case byte[][] chunks: WriteChunkedByteString(writer, chunks); break; case string[] chunks when IsIndefiniteLengthByteString(chunks): byte[][] byteChunks = chunks.Skip(1).Select(ch => ch.HexToByteArray()).ToArray(); WriteChunkedByteString(writer, byteChunks); break; case string[] chunks: WriteChunkedTextString(writer, chunks); break; case object[] nested when IsCborMapRepresentation(nested): WriteMap(writer, nested, useDefiniteLengthCollections); break; case object[] nested when IsEncodedValueRepresentation(nested): byte[] encodedValue = ((string)nested[1]).HexToByteArray(); writer.WriteEncodedValue(encodedValue); break; case object[] nested when IsTaggedValueRepresentation(nested): writer.WriteTag((CborTag)nested[0]); WriteValue(writer, nested[1]); break; case object[] nested: WriteArray(writer, nested, useDefiniteLengthCollections); break; default: throw new ArgumentException($"Unrecognized argument type {value.GetType()}"); } ; }
public static void Roundtrip_UInt64(ulong input) { using var writer = new CborWriter(); writer.WriteUInt64(input); byte[] encoding = writer.GetEncoding(); var reader = new CborReader(encoding); ulong result = reader.ReadUInt64(); Assert.Equal(input, result); }
public static void WriteValue(CborWriter writer, object value) { switch (value) { case int i: writer.WriteInt64(i); break; case long i: writer.WriteInt64(i); break; case ulong i: writer.WriteUInt64(i); break; case string s: writer.WriteTextString(s); break; case byte[] b: writer.WriteByteString(b); break; case object[] nested when IsCborMapRepresentation(nested): WriteMap(writer, nested); break; case object[] nested: WriteArray(writer, nested); break; default: throw new ArgumentException($"Unrecognized argument type {value.GetType()}"); } ; }