/// <summary> /// added length data /// </summary> public byte[] ToArray() { ByteQue que = new ByteQue(); que.PushSize(buff.Len); que.AddAll(buff.ToArray(), 0, -1); return(que.ToArray()); }
/// <summary> /// add some data to the buffer until it reaches the specified length /// </summary> /// <param name="other">part of the data</param> /// <param name="length">actual data length</param> public void Append(byte[] other, int length) { if (length < 0) { length = other.Length; } if (size.HasValue) { if (size.Value > buff.Len) { int l = size.Value - buff.Len; if (l < length) { buff.AddAll(other, 0, l); } else { buff.AddAll(other, 0, length); } } } else { if (buff.Len == 0) { for (int x = 0; x < length; ++x) { if (x == 4 || other[x] <= 0x7f) { int s = 0; for (int i = 0; i <= x; ++i) { s |= (other[i] & 0x7f) << 7 * i; } size = s; s += x + 1; if (s < length) { buff.AddAll(other, x + 1, s); } else { buff.AddAll(other, x + 1, length); } return; } } buff.AddAll(other, 0, length); } else { buff.AddAll(other, 0, length); byte[] arr = buff.ToArray(); for (int x = 0; x < arr.Length; ++x) { if (x == 4 || arr[x] <= 0x7f) { int s = 0; for (int i = 0; i <= x; ++i) { s |= (buff.Pop <byte>() & 0x7f) << 7 * i; } size = s; s += x + 1; if (arr.Length > s) { buff = new ByteQue(); buff.AddAll(arr, x + 1, s); } break; } } } } }