Ejemplo n.º 1
0
 public static void WriteArray_NestedValues_HappyPath(object[] values, string expectedHexEncoding)
 {
     byte[] expectedEncoding = expectedHexEncoding.HexToByteArray();
     using var writer = new CborWriter();
     ArrayWriterHelper.WriteArray(writer, values);
     byte[] actualEncoding = writer.ToArray();
     AssertHelper.HexEqual(expectedEncoding, actualEncoding);
 }
Ejemplo n.º 2
0
        public static void WriteArray(CborWriter writer, params object[] values)
        {
            writer.WriteStartArray(values.Length);
            foreach (object value in values)
            {
                switch (value)
                {
                case int i: writer.WriteInt64(i); break;

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

                case byte[] b: writer.WriteByteString(b); break;

                case object[] nested: ArrayWriterHelper.WriteArray(writer, nested); break;

                default: throw new ArgumentException($"Unrecognized argument type {value.GetType()}");
                }
                ;
            }
            writer.WriteEndArray();
        }