public static unsafe byte[] Encode(String words, int max_length) { byte * va = stackalloc byte[128]; ByteList encoded = new ByteList(va, 128); fixed(char *pEncode = WordsDecoding.char_CH) { foreach (char word in words) { if (word <= 0xFF) { encoded.Add((byte)Array.IndexOf(WordsDecoding.char_EN, word)); continue; } char *pe = pEncode; for (byte x = 1; x < 29; x++) { byte y = 0; while (true) { if (*pe++ == word) { if (x >= 6) { x++; } if (x >= 0x1a) { x++; } encoded.Add(x); encoded.Add(y); goto Loop; } if (y == 0xFF) { break; } y++; } } Loop: continue; } } if (encoded.count > max_length - 1) { encoded.count = max_length - 1; } encoded.Add(0xFF); while (encoded.count < max_length) { encoded.Add(0); } return(encoded.ToArray()); }
public void AddRange(ref ByteList list) { if (list.count == 0) { return; } if (count + list.count > length) { throwsIndexOutOfRange(); } for (int i = 0; i < list.count; i++) { data[count++] = list.data[i]; } }