Dahomey.Cbor icon indicating copy to clipboard operation
Dahomey.Cbor copied to clipboard

Consider letting CborReader.SkipDataItem skip semantic tags

Open rmja opened this issue 3 years ago • 1 comments

Currently a call to CborReader.SkipDataItem() does not skip semantic tags like any other call to the reader (e.g. ReadInt32). This may lead to subtle errors where if a tag is later included in a cbor file to provide some metadata information, then the reader code fails because the call to SkipDataItem() now skips the tag and not the data as intended.

I know that this is a breaking change, however if one really wanted to skip the semantic tag, then they should call reader.TryReadSemanticTag(out _) instead of SkipDataItem().

rmja avatar Aug 15 '22 07:08 rmja

This is a bug. Consider CborReader.SkipArray():

private void SkipArray()
        {
            int size = ReadSize();

            while (size > 0 || size < 0 && GetCurrentDataItemType() != CborDataItemType.Break)
            {
                SkipDataItem();
                size--;
            }

            _state = CborReaderState.Start;
        }

This code fails if any item in the array has a tag.

rmja avatar Aug 15 '22 10:08 rmja