byte[] ReadRawUTF8Char( PrimitiveReader reader ) { int byteCount = 0; byte header = reader.ReadByte(); for( int bit = 7; bit >= 0; bit-- ) { if( ( header & ( 1 << bit ) ) != 0 ) { byteCount++; header &= (byte)~( 1 << bit ); } else { break; } } if( byteCount == 0 ) return new byte[] { header }; byte[] data = new byte[byteCount]; data[0] = header; reader.FillBuffer( data, 1, byteCount - 1 ); for( int i = 1; i < data.Length; i++ ) { data[i] &= 0x3F; // Clear highest two bits. } return data; }