Consider adding CborWriter.WriteByteString(int) and WriteByteString(ReadOnlySequence<byte>)
rmja opened this issue · 3 comments
rmja commented
Consider adding the following overloads to CborWriter.WriteByteString
:
public void WriteByteString(int length)
{
WriteInteger(CborMajorType.ByteString, (ulong)length);
}
public void WriteByteString(ReadOnlySequence<byte> value)
{
WriteInteger(CborMajorType.ByteString, (ulong)value.Length);
foreach (var segment in value)
{
_bufferWriter.Write(segment.Span);
}
}
Both would be really useful for writing cbor where the entire byte string to be written is not in currently in memory / in one consecutive slice of memory. This is for example the case when the byte string to be written is from a file where the length is known in advance, but where the content is not loaded to memory.
mcatanzariti commented
rmja commented
I can. What name should we use for WriteByteString(int length)
? Maybe we should name it WriteByteStringHeader
or similar?
mcatanzariti commented
I would name it WriteByteStringLength(int length)