コード例 #1
0
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="byteCount"/> is negative.</exception>
        public void WriteBytes(byte value, int byteCount)
        {
            if (byteCount < 0)
            {
                Throw.ArgumentOutOfRange(nameof(byteCount));
            }

            int start = Advance(byteCount);

            fixed(byte *buffer = _buffer)
            {
                byte *ptr = buffer + start;

                for (int i = 0; i < byteCount; i++)
                {
                    ptr[i] = value;
                }
            }
        }
コード例 #2
0
ファイル: BlobBuilder.cs プロジェクト: layomia/dotnet_runtime
        /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="byteCount"/> is negative.</exception>
        /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception>
        public unsafe void WriteBytes(byte *buffer, int byteCount)
        {
            if (buffer == null)
            {
                Throw.ArgumentNull(nameof(buffer));
            }

            if (byteCount < 0)
            {
                Throw.ArgumentOutOfRange(nameof(byteCount));
            }

            if (!IsHead)
            {
                Throw.InvalidOperationBuilderAlreadyLinked();
            }

            WriteBytesUnchecked(buffer, byteCount);
        }
コード例 #3
0
        public void f32(f32 value, f32 min, f32 max, u8 numberOfBits)
        {
#if !NO_EXCEPTIONS
            if (min >= max)
            {
                Throw.Argument("min should be lower than max");
            }
            if (value < min || value > max)
            {
                Throw.ArgumentOutOfRange(nameof(value), $"Value should be withing provided {min} and {max} range");
            }
#endif
            var   maxvalue     = (1 << numberOfBits) - 1;
            float range        = max - min;
            var   precision    = range / maxvalue;
            var   invPrecision = 1.0f / precision;
            f32   adjusted     = (value - min) * invPrecision;
            u32((u32)(adjusted + 0.5f), numberOfBits);
        }
コード例 #4
0
        public void f32(f32 value, f32 min, f32 max, f32 precision)
        {
#if !NO_EXCEPTIONS
            if (min >= max)
            {
                Throw.Argument("min should be lower than max");
            }
            if (value < min || value > max)
            {
                Throw.ArgumentOutOfRange(nameof(value), $"Value should be withing provided {min} and {max} range");
            }
#endif
            float range        = max - min;
            float invPrecision = 1.0f / precision;
            float maxVal       = range * invPrecision;
            var   numberOfBits = (u8)(BitOperations.Log2((u32)(maxVal + 0.5f)) + 1);
            float adjusted     = (value - min) * invPrecision;
            u32((u32)(adjusted + 0.5f), numberOfBits);
        }
コード例 #5
0
ファイル: FeatureServer.cs プロジェクト: wmlrose/mvcpluggedin
        /// <summary>
        /// This operation adds, updates, and deletes features to the specified feature layer.
        /// </summary>
        /// <param name="layerId">The ID of the layer to query.</param>
        /// <param name="adds">The array of features to be added.</param>
        /// <param name="updates">The array of features to be updated. The attributes property of
        /// each feature should include the object ID of the feature.</param>
        /// <param name="deletes">The array of object IDs to be deleted.</param>
        /// <returns></returns>
        public ApplyEditsResult ApplyEdits(int layerId, Feature[] adds = null, Feature[] updates = null, long[] deletes = null)
        {
            LayerTableBase layer = this.LayerInfos.Single(x => x.ID == layerId);

            if (layer == null)
            {
                Throw.ArgumentOutOfRange("layerId");
            }
            IDictionary <string, object> inputs = new Dictionary <string, object>()
            {
            };
            Uri endpoint = GetUrl("applyEdits", inputs, layer);
            var nvc      = new NameValueCollection();

            nvc.Add("adds", JsonConvert.SerializeObject(adds) ?? "[]");
            nvc.Add("updates", JsonConvert.SerializeObject(updates) ?? "[]");
            nvc.Add("deletes", JsonConvert.SerializeObject(deletes) ?? "[]");
            return(Geocrest.Model.RestHelper.HydrateObject <ApplyEditsResult>(endpoint.ToString(), nvc));
        }
コード例 #6
0
        /// <summary>
        /// Adds Embedded Portable PDB entry.
        /// </summary>
        /// <param name="debugMetadata">Portable PDB metadata builder.</param>
        /// <param name="portablePdbVersion">Version of Portable PDB format (e.g. 0x0100 for 1.0).</param>
        /// <exception cref="ArgumentNullException"><paramref name="debugMetadata"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="portablePdbVersion"/> is smaller than 0x0100.</exception>
        public void AddEmbeddedPortablePdbEntry(BlobBuilder debugMetadata, ushort portablePdbVersion)
        {
            if (debugMetadata == null)
            {
                Throw.ArgumentNull(nameof(debugMetadata));
            }

            if (portablePdbVersion < PortablePdbVersions.MinFormatVersion)
            {
                Throw.ArgumentOutOfRange(nameof(portablePdbVersion));
            }

            int dataSize = WriteEmbeddedPortablePdbData(_dataBuilder, debugMetadata);

            AddEntry(
                type: DebugDirectoryEntryType.EmbeddedPortablePdb,
                version: PortablePdbVersions.DebugDirectoryEmbeddedVersion(portablePdbVersion),
                stamp: 0,
                dataSize);
        }
コード例 #7
0
        /// <summary>
        /// Encodes Method Signature blob.
        /// </summary>
        /// <param name="convention">Calling convention.</param>
        /// <param name="genericParameterCount">Number of generic parameters.</param>
        /// <param name="isInstanceMethod">True to encode an instance method signature, false to encode a static method signature.</param>
        /// <returns>An Encoder of the rest of the signature including return value and parameters.</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="genericParameterCount"/> is not in range [0, 0xffff].</exception>
        public MethodSignatureEncoder MethodSignature(
            SignatureCallingConvention convention = SignatureCallingConvention.Default,
            int genericParameterCount             = 0,
            bool isInstanceMethod = false)
        {
            if (unchecked ((uint)genericParameterCount) > ushort.MaxValue)
            {
                Throw.ArgumentOutOfRange(nameof(genericParameterCount));
            }

            var attributes =
                (genericParameterCount != 0 ? SignatureAttributes.Generic : 0) |
                (isInstanceMethod ? SignatureAttributes.Instance : 0);

            Builder.WriteByte(new SignatureHeader(SignatureKind.Method, convention, attributes).RawValue);

            if (genericParameterCount != 0)
            {
                Builder.WriteCompressedInteger(genericParameterCount);
            }

            return(new MethodSignatureEncoder(Builder, hasVarArgs: convention == SignatureCallingConvention.VarArgs));
        }
コード例 #8
0
        /// <summary>
        /// Create a pipe-reader over the provided file
        /// </summary>
        public static PipeReader Create(string path, int pageSize = DEFAULT_PAGE_SIZE)
        {
            if (IsAvailable)
            {
                if (pageSize <= 0)
                {
                    Throw.ArgumentOutOfRange(nameof(pageSize));
                }
                var file = new FileInfo(path);
                if (!file.Exists)
                {
                    Throw.FileNotFound("File not found", path);
                }

                var mmap = MemoryMappedFile.CreateFromFile(path, FileMode.Open, null, file.Length, MemoryMappedFileAccess.Read);
                return(new MemoryMappedPipeReader(mmap, file.Length, pageSize, path));
            }
            else
            {
                // fallback... FileStream
                var file = File.OpenRead(path);
                return(StreamConnection.GetReader(file, name: path));
            }
        }
コード例 #9
0
        private MemoryMappedPipeReader(MemoryMappedFile file, long length, int pageSize = DEFAULT_PAGE_SIZE, string name = null)
        {
            if (file == null)
            {
                Throw.ArgumentNull(nameof(file));
            }
            _file = file;
            if (pageSize <= 0)
            {
                Throw.ArgumentOutOfRange(nameof(pageSize));
            }
            if (length < 0)
            {
                Throw.ArgumentOutOfRange(nameof(length));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                name = GetType().Name;
            }
            Name       = name;
            _pageSize  = pageSize;
            _remaining = length;
        }
コード例 #10
0
        /// <summary>
        /// Adds an exception clause.
        /// </summary>
        /// <param name="kind">Clause kind.</param>
        /// <param name="tryOffset">Try block start offset.</param>
        /// <param name="tryLength">Try block length.</param>
        /// <param name="handlerOffset">Handler start offset.</param>
        /// <param name="handlerLength">Handler length.</param>
        /// <param name="catchType">
        /// <see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/> or <see cref="TypeSpecificationHandle"/>,
        /// or nil if <paramref name="kind"/> is not <see cref="ExceptionRegionKind.Catch"/>
        /// </param>
        /// <param name="filterOffset">
        /// Offset of the filter block, or 0 if the <paramref name="kind"/> is not <see cref="ExceptionRegionKind.Filter"/>.
        /// </param>
        /// <returns>Encoder for the next clause.</returns>
        /// <exception cref="ArgumentException"><paramref name="catchType"/> is invalid.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind"/> has invalid value.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="tryOffset"/>, <paramref name="tryLength"/>, <paramref name="handlerOffset"/> or <paramref name="handlerLength"/> is out of range.
        /// </exception>
        /// <exception cref="InvalidOperationException">Method body was not declared to have exception regions.</exception>
        public ExceptionRegionEncoder Add(
            ExceptionRegionKind kind,
            int tryOffset,
            int tryLength,
            int handlerOffset,
            int handlerLength,
            EntityHandle catchType = default(EntityHandle),
            int filterOffset       = 0)
        {
            if (Builder == null)
            {
                Throw.InvalidOperation(SR.MethodHasNoExceptionRegions);
            }

            if (HasSmallFormat)
            {
                if (unchecked ((ushort)tryOffset) != tryOffset)
                {
                    Throw.ArgumentOutOfRange(nameof(tryOffset));
                }
                if (unchecked ((byte)tryLength) != tryLength)
                {
                    Throw.ArgumentOutOfRange(nameof(tryLength));
                }
                if (unchecked ((ushort)handlerOffset) != handlerOffset)
                {
                    Throw.ArgumentOutOfRange(nameof(handlerOffset));
                }
                if (unchecked ((byte)handlerLength) != handlerLength)
                {
                    Throw.ArgumentOutOfRange(nameof(handlerLength));
                }
            }
            else
            {
                if (tryOffset < 0)
                {
                    Throw.ArgumentOutOfRange(nameof(tryOffset));
                }
                if (tryLength < 0)
                {
                    Throw.ArgumentOutOfRange(nameof(tryLength));
                }
                if (handlerOffset < 0)
                {
                    Throw.ArgumentOutOfRange(nameof(handlerOffset));
                }
                if (handlerLength < 0)
                {
                    Throw.ArgumentOutOfRange(nameof(handlerLength));
                }
            }

            int catchTokenOrOffset;

            switch (kind)
            {
            case ExceptionRegionKind.Catch:
                if (!IsValidCatchTypeHandle(catchType))
                {
                    Throw.InvalidArgument_Handle(nameof(catchType));
                }

                catchTokenOrOffset = MetadataTokens.GetToken(catchType);
                break;

            case ExceptionRegionKind.Filter:
                if (filterOffset < 0)
                {
                    Throw.ArgumentOutOfRange(nameof(filterOffset));
                }

                catchTokenOrOffset = filterOffset;
                break;

            case ExceptionRegionKind.Finally:
            case ExceptionRegionKind.Fault:
                catchTokenOrOffset = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(kind));
            }

            AddUnchecked(kind, tryOffset, tryLength, handlerOffset, handlerLength, catchTokenOrOffset);
            return(this);
        }
コード例 #11
0
        public void c(ReadOnlySpan <char> value)
        {
            if (value.Length > config.CharSpanLengthMax)
            {
                Throw.ArgumentOutOfRange($"String too long, raise the {nameof(config.CharSpanBitsLength)} value or split the string.");
            }

            var length = value.Length;

            if (length * 17 + 10 > (totalNumberBits - BitsWritten)) // possible overflow
            {
                if (BitBuffer.BitsRequired(value, length) > (totalNumberBits - BitsWritten))
                {
                    Throw.ArgumentOutOfRange("String would not fit in bitstream.");
                }
            }

            var codePage = CodePage.Ascii;

            for (var i = 0; i < length; i++)
            {
                var val = value[i];
                if (val > 127)
                {
                    codePage = CodePage.Latin1;
                    if (val > 255)
                    {
                        codePage = CodePage.LatinExtended;
                        if (val > 511)
                        {
                            codePage = CodePage.UTF16;
                            break;
                        }
                    }
                }
            }

            u32((u32)codePage, BitBuffer.codePageBitsRequired);
            u32((u32)length, config.CharSpanBitsLength);

            switch (codePage)
            {
            case CodePage.Ascii:
                for (var i = 0; i < length; i++)
                {
                    u32(value[i], BitBuffer.bitsASCII);
                }
                break;

            case CodePage.Latin1:
                for (var i = 0; i < length; i++)
                {
                    u32(value[i], BitBuffer.bitsLATIN1);
                }
                break;

            case CodePage.LatinExtended:
                for (var i = 0; i < length; i++)
                {
                    u32(value[i], BitBuffer.bitsLATINEXT);
                }
                break;

            default:
                for (var i = 0; i < length; i++)
                {
                    if (value[i] > 127)
                    {
                        u32(1, 1);
                        u32(value[i], BitBuffer.bitsUTF16);
                    }
                    else
                    {
                        u32(0, 1);
                        u32(value[i], BitBuffer.bitsASCII);
                    }
                }
                break;
            }
        }