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 WriteChunkedTextString(CborWriter writer, string[] chunks) { writer.WriteStartTextString(); foreach (string chunk in chunks) { writer.WriteTextString(chunk); } writer.WriteEndTextString(); }
public static void WriteEncodedValue_IndefiniteLengthTextString_HappyPath() { using var writer = new CborWriter(encodeIndefiniteLengths: true); writer.WriteStartTextString(); writer.WriteTextString("foo"); writer.WriteEncodedValue("63626172".HexToByteArray()); writer.WriteEndTextString(); byte[] encoding = writer.GetEncoding(); Assert.Equal("7f63666f6f63626172ff", encoding.ByteArrayToHex().ToLower()); }