Esempio n. 1
0
        /// <summary>
        /// Set start value for packet counter.
        /// </summary>
        public static void SetCounter
        (
            int startValue
        )
        {
            Sure.NonNegative(startValue, nameof(startValue));

            _counter = startValue;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public RepeatSpecification
        (
            RepeatKind kind,
            int index
        )
            : this()
        {
            Sure.Defined(kind, nameof(kind));
            Sure.NonNegative(index, nameof(index));

            Kind  = kind;
            Index = index;
        }
Esempio n. 3
0
        public GblSettings SetRange
        (
            int firstRecord,
            int numberOfRecords
        )
        {
            Sure.NonNegative(firstRecord, nameof(firstRecord));
            Sure.NonNegative(numberOfRecords, nameof(numberOfRecords));

            FirstRecord     = firstRecord;
            NumberOfRecords = numberOfRecords;

            return(this);
        }
Esempio n. 4
0
        public char LookAhead
        (
            int distance
        )
        {
            Sure.NonNegative(distance, nameof(distance));

            int newPosition = _position + distance;

            if (newPosition >= _length)
            {
                return(EOF);
            }

            return(_text[newPosition]);
        }
Esempio n. 5
0
        public byte[] GetAnswerCopy
        (
            int offset,
            int length
        )
        {
            Sure.NonNegative(offset, "offset");
            Sure.NonNegative(length, "length");

            if (ReferenceEquals(RawAnswer, null))
            {
                throw new IrbisException("packet is null");
            }

            byte[] result = RawAnswer.GetSpan(offset, length);

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public ByteNavigator
        (
            [NotNull] byte[] data,
            int length
        )
        {
            Sure.NotNull(data, nameof(data));
            Sure.NonNegative(length, nameof(length));

            if (length > data.Length)
            {
                length = data.Length;
            }

            _data    = data;
            Length   = length;
            Encoding = Encoding.Default;
        }
Esempio n. 7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public ByteNavigator
        (
            [NotNull] byte[] data,
            int length,
            [NotNull] Encoding encoding
        )
        {
            Sure.NotNull(data, nameof(data));
            Sure.NonNegative(length, nameof(length));
            Sure.NotNull(encoding, nameof(encoding));

            if (length > data.Length)
            {
                length = data.Length;
            }

            _data    = data;
            Length   = length;
            Encoding = encoding;
        }
Esempio n. 8
0
        public static byte[] ReceiveExact
        (
            [NotNull] this Socket socket,
            int dataLength
        )
        {
            Sure.NotNull(socket, nameof(socket));
            Sure.NonNegative(dataLength, nameof(dataLength));

            using (MemoryStream result = new MemoryStream(dataLength))
            {
                byte[] buffer = new byte[32 * 1024];

                while (dataLength > 0)
                {
                    int readed = socket.Receive(buffer);

                    if (readed <= 0)
                    {
                        Log.Error
                        (
                            "SocketUtility::ReceiveExact: "
                            + "error reading socket"
                        );

                        throw new ArsMagnaException
                              (
                                  "Socket reading error"
                              );
                    }

                    result.Write(buffer, 0, readed);

                    dataLength -= readed;
                }

                return(result.ToArray());
            }
        }
Esempio n. 9
0
        public Stream GetStream
        (
            int offset,
            int length
        )
        {
            Sure.NonNegative(offset, nameof(offset));
            Sure.NonNegative(length, nameof(length));

            if (ReferenceEquals(RawAnswer, null))
            {
                throw new IrbisException("packet is null");
            }

            MemoryStream result = new MemoryStream
                                  (
                RawAnswer,
                offset,
                length
                                  );

            return(result);
        }
Esempio n. 10
0
 public void Sure_NonNegative_6()
 {
     Sure.NonNegative(1L, "argument");
 }
Esempio n. 11
0
 public void Sure_NonNegative_4()
 {
     Sure.NonNegative(1.0, "argument");
 }
Esempio n. 12
0
 public void Sure_NonNegative_1()
 {
     Sure.NonNegative(-1, "argument");
 }