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)); }
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; }
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)); }
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)); }