コード例 #1
0
        private static TypedData ParseInt32(byte[] buffer, ref int offset)
        {
            VariableInt value = VariableInt.DecodeVariableInt(buffer);

            offset += value.Length;
            return(new TypedData(DataType.Int32, (int)value.Value));
        }
コード例 #2
0
        private static TypedData ParseUint64(byte[] buffer, ref int offset)
        {
            VariableInt value = VariableInt.DecodeVariableUnsignedInt(buffer);

            offset += value.Length;
            return(new TypedData(DataType.Uint64, value.UnsignedValue));
        }
コード例 #3
0
        private byte[] GetBytesForUint64Value()
        {
            var         bytes = new List <byte>();
            VariableInt value = VariableInt.EncodeVariableUint((ulong)this.Value);

            bytes.AddRange(value.Bytes);
            return(bytes.ToArray());
        }
コード例 #4
0
        private byte[] GetBytesForStringValue()
        {
            var         bytes         = new List <byte>();
            VariableInt lengthOfValue = VariableInt.EncodeVariableInt(((string)this.Value).Length);

            bytes.AddRange(lengthOfValue.Bytes);
            bytes.AddRange(System.Text.Encoding.ASCII.GetBytes((string)this.Value));
            return(bytes.ToArray());
        }
コード例 #5
0
        private byte[] GetBytesForBinaryValue()
        {
            var         bytes         = new List <byte>();
            VariableInt lengthOfValue = VariableInt.EncodeVariableInt(((byte[])this.Value).Length);

            bytes.AddRange(lengthOfValue.Bytes);
            bytes.AddRange((byte[])this.Value);
            return(bytes.ToArray());
        }
コード例 #6
0
        internal void Parse(byte[] buffer, ref int bufferOffset)
        {
            // Flags always use 4 bytes
            this.Flags    = ParseMetadataFlags(buffer.Skip(bufferOffset).Take(4).ToArray());
            bufferOffset += 4;

            // Stream ID
            this.StreamId = VariableInt.DecodeVariableInt(buffer.Skip(bufferOffset).ToArray());
            bufferOffset += this.StreamId.Length;

            // Frame ID
            this.FrameId  = VariableInt.DecodeVariableInt(buffer.Skip(bufferOffset).ToArray());
            bufferOffset += this.FrameId.Length;
        }
コード例 #7
0
        private static TypedData ParseBinary(byte[] buffer, ref int offset)
        {
            VariableInt lengthOfBinary = VariableInt.DecodeVariableInt(buffer);
            int         length         = (int)lengthOfBinary.Value;
            int         lengthOfLength = lengthOfBinary.Length;

            // if the data is larger than the max-frame-size, and fragmentation
            // is supported, then the data may be fragmented into chunks.
            // Check if the size of the data exceeds the space left in the buffer.
            int remainingBufferSize = buffer.Skip(lengthOfLength).Count();

            if (remainingBufferSize < length)
            {
                length = remainingBufferSize;
            }

            byte[] value = buffer.Skip(lengthOfBinary.Length).Take((int)lengthOfBinary.Value).ToArray();
            offset = offset + lengthOfLength + length;
            return(new TypedData(DataType.Binary, value));
        }
コード例 #8
0
        private static TypedData ParseString(byte[] buffer, ref int offset)
        {
            VariableInt lengthOfString = VariableInt.DecodeVariableInt(buffer);
            int         length         = (int)lengthOfString.Value;
            int         lengthOfLength = lengthOfString.Length;

            // if the data is larger than the max-frame-size, and fragmentation
            // is supported, then the data may be fragmented into chunks.
            // Check if the size of the data exceeds the space left in the buffer.
            int remainingBufferSize = buffer.Skip(lengthOfLength).Count();

            if (remainingBufferSize < length)
            {
                length = remainingBufferSize;
            }

            string value = System.Text.Encoding.ASCII.GetString(buffer, lengthOfLength, length);

            offset = offset + lengthOfLength + length;
            return(new TypedData(DataType.String, value));
        }