コード例 #1
0
        /// <exception cref="ImageFormatLimitationException">The remaining space on the heap is too small to fit the string.</exception>
        public UserStringHandle ReserveUserString(int length, out Blob fixup)
        {
            int offset        = GetNewUserStringHeapOffset(length);
            int encodedLength = BlobUtilities.GetUserStringByteLength(length);

            fixup = _userStringWriter.ReserveBytes(BlobWriterImpl.GetCompressedIntegerSize(encodedLength) + encodedLength);
            new BlobWriter(fixup).WriteBytes(0, fixup.Length);
            return(MetadataTokens.UserStringHandle(offset));
        }
コード例 #2
0
        /// <summary>
        /// Reserves space on the User String heap for a string of specified length.
        /// </summary>
        /// <param name="length">The number of characters to reserve.</param>
        /// <param name="reservedUserString">
        /// <see cref="Blob"/> representing the entire User String blob (including its length and terminal character).
        /// Use <see cref="BlobWriter.WriteUserString(string)"/> to fill in the content.
        /// </param>
        /// <returns>
        /// Handle to the reserved User String.
        /// May be used in <see cref="InstructionEncoder.LoadString(UserStringHandle)"/>.
        /// </returns>
        /// <exception cref="ImageFormatLimitationException">The remaining space on the heap is too small to fit the string.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="length"/> is negative.</exception>
        public UserStringHandle ReserveUserString(int length, out Blob reservedUserString)
        {
            if (length < 0)
            {
                Throw.ArgumentOutOfRange(nameof(length));
            }

            var handle        = GetNewUserStringHandle();
            int encodedLength = BlobUtilities.GetUserStringByteLength(length);

            reservedUserString = _userStringBuilder.ReserveBytes(BlobWriterImpl.GetCompressedIntegerSize(encodedLength) + encodedLength);
            return(handle);
        }
コード例 #3
0
        public BlobHandle GetBlob(ImmutableArray <byte> blob)
        {
            BlobHandle index;

            if (!_blobs.TryGetValue(blob, out index))
            {
                Debug.Assert(!_streamsAreComplete);

                index = MetadataTokens.BlobHandle(_blobHeapSize);
                _blobs.Add(blob, index);

                _blobHeapSize += BlobWriterImpl.GetCompressedIntegerSize(blob.Length) + blob.Length;
            }

            return(index);
        }
コード例 #4
0
        /// <summary>
        /// Adds specified blob to Blob heap, if it's not there already.
        /// </summary>
        /// <param name="value">Array containing the blob.</param>
        /// <returns>Handle to the added or existing blob.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
        public BlobHandle GetOrAddBlob(ImmutableArray <byte> value)
        {
            if (value.IsDefault)
            {
                Throw.ArgumentNull(nameof(value));
            }

            BlobHandle handle;

            if (!_blobs.TryGetValue(value, out handle))
            {
                handle = BlobHandle.FromOffset(_blobHeapStartOffset + _blobHeapSize);
                _blobs.Add(value, handle);

                _blobHeapSize += BlobWriterImpl.GetCompressedIntegerSize(value.Length) + value.Length;
            }

            return(handle);
        }