Exemple #1
0
        // Implements major type 6 encoding per https://tools.ietf.org/html/rfc7049#section-2.1

        /// <summary>
        ///   Assign a semantic tag (major type 6) to the next data item.
        /// </summary>
        /// <param name="tag">The value to write.</param>
        /// <exception cref="InvalidOperationException">
        ///   Writing a new value exceeds the definite length of the parent data item. -or-
        ///   The major type of the encoded value is not permitted in the parent data item. -or-
        ///   The written data is not accepted under the current conformance level.
        /// </exception>
        public void WriteTag(CborTag tag)
        {
            if (!CborConformanceLevelHelpers.AllowsTags(ConformanceLevel))
            {
                throw new InvalidOperationException(SR.Format(SR.Cbor_ConformanceLevel_TagsNotSupported, ConformanceLevel));
            }

            WriteUnsignedInteger(CborMajorType.Tag, (ulong)tag);
            _isTagContext = true;
        }
Exemple #2
0
        public void WriteTag(CborTag tag)
        {
            if (!CborConformanceLevelHelpers.AllowsTags(ConformanceLevel))
            {
                throw new InvalidOperationException("Tagged items are not permitted under the current conformance level.");
            }

            WriteUnsignedInteger(CborMajorType.Tag, (ulong)tag);
            _isTagContext = true;
        }
Exemple #3
0
        public CborTag ReadTag()
        {
            CborTag tag = PeekTagCore(out int additionalBytes);

            if (_isConformanceLevelCheckEnabled && !CborConformanceLevelHelpers.AllowsTags(ConformanceLevel))
            {
                throw new FormatException("Tagged items are not permitted under the current conformance level.");
            }

            AdvanceBuffer(1 + additionalBytes);
            _isTagContext = true;
            return(tag);
        }
Exemple #4
0
        public void ReadTag(CborTag expectedTag)
        {
            CborTag tag = PeekTagCore(out int additionalBytes);

            if (_isConformanceLevelCheckEnabled && !CborConformanceLevelHelpers.AllowsTags(ConformanceLevel))
            {
                throw new FormatException("Tagged items are not permitted under the current conformance level.");
            }

            if (expectedTag != tag)
            {
                throw new InvalidOperationException("CBOR tag mismatch.");
            }

            AdvanceBuffer(1 + additionalBytes);
            _isTagContext = true;
        }