}
else
{
- writer.WriteStartArrayIndefiniteLength();
+ writer.WriteStartArray();
}
foreach (object value in values)
}
else
{
- writer.WriteStartMapIndefiniteLength();
+ writer.WriteStartMap();
}
foreach (object value in keyValuePairs.Skip(1))
public static void WriteChunkedByteString(CborWriter writer, byte[][] chunks)
{
- writer.WriteStartByteStringIndefiniteLength();
+ writer.WriteStartByteString();
foreach (byte[] chunk in chunks)
{
writer.WriteByteString(chunk);
}
- writer.WriteEndByteStringIndefiniteLength();
+ writer.WriteEndByteString();
}
public static void WriteChunkedTextString(CborWriter writer, string[] chunks)
{
- writer.WriteStartTextStringIndefiniteLength();
+ writer.WriteStartTextString();
foreach (string chunk in chunks)
{
writer.WriteTextString(chunk);
}
- writer.WriteEndTextStringIndefiniteLength();
+ writer.WriteEndTextString();
}
public static void ExecOperation(CborWriter writer, string 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.WriteStartTextStringIndefiniteLength): writer.WriteStartTextStringIndefiniteLength(); break;
- case nameof(writer.WriteStartByteStringIndefiniteLength): writer.WriteStartByteStringIndefiniteLength(); break;
- case nameof(writer.WriteStartArray): writer.WriteStartArrayIndefiniteLength(); break;
- case nameof(writer.WriteStartMap): writer.WriteStartMapIndefiniteLength(); break;
- case nameof(writer.WriteEndByteStringIndefiniteLength): writer.WriteEndByteStringIndefiniteLength(); break;
- case nameof(writer.WriteEndTextStringIndefiniteLength): writer.WriteEndTextStringIndefiniteLength(); 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 EndWriteMap_IndefiniteLength_OddItems_ShouldThrowInvalidOperationException(int length)
{
using var writer = new CborWriter();
- writer.WriteStartMapIndefiniteLength();
+ writer.WriteStartMap();
for (int i = 1; i < length; i++)
{
[Theory]
[InlineData(nameof(CborWriter.WriteInt64))]
[InlineData(nameof(CborWriter.WriteByteString))]
- [InlineData(nameof(CborWriter.WriteStartTextStringIndefiniteLength))]
- [InlineData(nameof(CborWriter.WriteStartByteStringIndefiniteLength))]
+ [InlineData(nameof(CborWriter.WriteStartTextString))]
+ [InlineData(nameof(CborWriter.WriteStartByteString))]
[InlineData(nameof(CborWriter.WriteStartArray))]
[InlineData(nameof(CborWriter.WriteStartMap))]
public static void WriteTextString_IndefiniteLength_NestedWrites_ShouldThrowInvalidOperationException(string opName)
{
using var writer = new CborWriter();
- writer.WriteStartTextStringIndefiniteLength();
+ writer.WriteStartTextString();
Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
}
[Theory]
- [InlineData(nameof(CborWriter.WriteEndByteStringIndefiniteLength))]
+ [InlineData(nameof(CborWriter.WriteEndByteString))]
[InlineData(nameof(CborWriter.WriteEndArray))]
[InlineData(nameof(CborWriter.WriteEndMap))]
public static void WriteTextString_IndefiniteLength_ImbalancedWrites_ShouldThrowInvalidOperationException(string opName)
{
using var writer = new CborWriter();
- writer.WriteStartTextStringIndefiniteLength();
+ writer.WriteStartTextString();
Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
}
[Theory]
[InlineData(nameof(CborWriter.WriteInt64))]
[InlineData(nameof(CborWriter.WriteTextString))]
- [InlineData(nameof(CborWriter.WriteStartTextStringIndefiniteLength))]
- [InlineData(nameof(CborWriter.WriteStartByteStringIndefiniteLength))]
+ [InlineData(nameof(CborWriter.WriteStartTextString))]
+ [InlineData(nameof(CborWriter.WriteStartByteString))]
[InlineData(nameof(CborWriter.WriteStartArray))]
[InlineData(nameof(CborWriter.WriteStartMap))]
- [InlineData(nameof(CborWriter.WriteEndTextStringIndefiniteLength))]
+ [InlineData(nameof(CborWriter.WriteEndTextString))]
[InlineData(nameof(CborWriter.WriteEndArray))]
[InlineData(nameof(CborWriter.WriteEndMap))]
public static void WriteByteString_IndefiniteLength_NestedWrites_ShouldThrowInvalidOperationException(string opName)
{
using var writer = new CborWriter();
- writer.WriteStartByteStringIndefiniteLength();
+ writer.WriteStartByteString();
Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
}
[Theory]
- [InlineData(nameof(CborWriter.WriteEndTextStringIndefiniteLength))]
+ [InlineData(nameof(CborWriter.WriteEndTextString))]
[InlineData(nameof(CborWriter.WriteEndArray))]
[InlineData(nameof(CborWriter.WriteEndMap))]
public static void WriteByteString_IndefiniteLength_ImbalancedWrites_ShouldThrowInvalidOperationException(string opName)
{
using var writer = new CborWriter();
- writer.WriteStartByteStringIndefiniteLength();
+ writer.WriteStartByteString();
Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
}
}
{
using var writer = new CborWriter();
- writer.WriteStartArrayIndefiniteLength();
+ writer.WriteStartArray();
writer.WriteTag(CborTag.Uri);
Assert.Throws<InvalidOperationException>(() => writer.WriteEndArray());
}
{
using var writer = new CborWriter(encodeIndefiniteLengths: true);
- writer.WriteStartTextStringIndefiniteLength();
+ writer.WriteStartTextString();
writer.WriteTextString("foo");
writer.WriteEncodedValue("63626172".HexToByteArray());
- writer.WriteEndTextStringIndefiniteLength();
+ writer.WriteEndTextString();
byte[] encoding = writer.GetEncoding();
Assert.Equal("7f63666f6f63626172ff", encoding.ByteArrayToHex().ToLower());
{
using var writer = new CborWriter(encodeIndefiniteLengths: true);
- writer.WriteStartByteStringIndefiniteLength();
+ writer.WriteStartByteString();
writer.WriteByteString(new byte[] { 1, 1, 1 });
writer.WriteEncodedValue("43020202".HexToByteArray());
- writer.WriteEndByteStringIndefiniteLength();
+ writer.WriteEndByteString();
byte[] encoding = writer.GetEncoding();
Assert.Equal("5f4301010143020202ff", encoding.ByteArrayToHex().ToLower());
public static void WriteEncodedValue_BadIndefiniteLengthStringValue_ShouldThrowInvalidOperationException()
{
using var writer = new CborWriter();
- writer.WriteStartTextStringIndefiniteLength();
+ writer.WriteStartTextString();
Assert.Throws<InvalidOperationException>(() => writer.WriteEncodedValue(new byte[] { 0x01 }));
}
PushDataItem(CborMajorType.Array, definiteLength);
}
- public void WriteEndArray()
- {
- PopDataItem(CborMajorType.Array);
- AdvanceDataItemCounters();
- }
-
- public void WriteStartArrayIndefiniteLength()
+ public void WriteStartArray()
{
EnsureWriteCapacity(1);
WriteInitialByte(new CborInitialByte(CborMajorType.Array, CborAdditionalInfo.IndefiniteLength));
PushDataItem(CborMajorType.Array, definiteLength: null);
}
+ public void WriteEndArray()
+ {
+ PopDataItem(CborMajorType.Array);
+ AdvanceDataItemCounters();
+ }
+
private void PatchIndefiniteLengthCollection(CborMajorType majorType, int count)
{
Debug.Assert(majorType == CborMajorType.Array || majorType == CborMajorType.Map);
PushDataItem(CborMajorType.Map, definiteLength: checked(2 * definiteLength));
}
+ public void WriteStartMap()
+ {
+ EnsureWriteCapacity(1);
+ WriteInitialByte(new CborInitialByte(CborMajorType.Map, CborAdditionalInfo.IndefiniteLength));
+ PushDataItem(CborMajorType.Map, definiteLength: null);
+ _currentKeyOffset = _offset;
+ _currentValueOffset = null;
+ }
+
public void WriteEndMap()
{
if (_itemsWritten % 2 == 1)
AdvanceDataItemCounters();
}
- public void WriteStartMapIndefiniteLength()
- {
- EnsureWriteCapacity(1);
- WriteInitialByte(new CborInitialByte(CborMajorType.Map, CborAdditionalInfo.IndefiniteLength));
- PushDataItem(CborMajorType.Map, definiteLength: null);
- _currentKeyOffset = _offset;
- _currentValueOffset = null;
- }
-
//
// Map encoding conformance
//
AdvanceDataItemCounters();
}
- public void WriteStartByteStringIndefiniteLength()
+ public void WriteStartByteString()
{
if (!EncodeIndefiniteLengths)
{
PushDataItem(CborMajorType.ByteString, definiteLength: null);
}
- public void WriteEndByteStringIndefiniteLength()
+ public void WriteEndByteString()
{
PopDataItem(CborMajorType.ByteString);
AdvanceDataItemCounters();
}
- public void WriteStartTextStringIndefiniteLength()
+ public void WriteStartTextString()
{
if (!EncodeIndefiniteLengths)
{
PushDataItem(CborMajorType.TextString, definiteLength: null);
}
- public void WriteEndTextStringIndefiniteLength()
+ public void WriteEndTextString()
{
PopDataItem(CborMajorType.TextString);
AdvanceDataItemCounters();