public static void ExecOperation(CborWriter writer, string op)
            {
                switch (op)
                {
                case nameof(writer.WriteInt64): writer.WriteInt64(42); break;

                case nameof(writer.WriteByteString): writer.WriteByteString(Array.Empty <byte>()); break;

                case nameof(writer.WriteTextString): writer.WriteTextString(""); break;

                case nameof(writer.WriteStartTextString): writer.WriteStartTextString(); break;

                case nameof(writer.WriteStartByteString): writer.WriteStartByteString(); break;

                case nameof(writer.WriteStartArray): writer.WriteStartArray(); break;

                case nameof(writer.WriteStartMap): writer.WriteStartMap(); break;

                case nameof(writer.WriteEndByteString): writer.WriteEndByteString(); break;

                case nameof(writer.WriteEndTextString): writer.WriteEndTextString(); break;

                case nameof(writer.WriteEndArray): writer.WriteEndArray(); break;

                case nameof(writer.WriteEndMap): writer.WriteEndMap(); break;

                default: throw new Exception($"Unrecognized CborWriter operation name {op}");
                }
            }
        public static void WriteByteString_IndefiniteLength_ImbalancedWrites_ShouldThrowInvalidOperationException(string opName)
        {
            var writer = new CborWriter();

            writer.WriteStartByteString();
            Assert.Throws <InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
        }
 public static void WriteChunkedByteString(CborWriter writer, byte[][] chunks)
 {
     writer.WriteStartByteString();
     foreach (byte[] chunk in chunks)
     {
         writer.WriteByteString(chunk);
     }
     writer.WriteEndByteString();
 }
Exemple #4
0
        public static void WriteEncodedValue_IndefiniteLengthByteString_HappyPath()
        {
            using var writer = new CborWriter(encodeIndefiniteLengths: true);

            writer.WriteStartByteString();
            writer.WriteByteString(new byte[] { 1, 1, 1 });
            writer.WriteEncodedValue("43020202".HexToByteArray());
            writer.WriteEndByteString();

            byte[] encoding = writer.GetEncoding();
            Assert.Equal("5f4301010143020202ff", encoding.ByteArrayToHex().ToLower());
        }
        public static void WriteStartByteString_NoPatching_UnsupportedConformance_ShouldThrowInvalidOperationException(CborConformanceLevel conformanceLevel)
        {
            var writer = new CborWriter(conformanceLevel, convertIndefiniteLengthEncodings: false);

            Assert.Throws <InvalidOperationException>(() => writer.WriteStartByteString());
        }