message: core: enhance the stream testing Data struct
diff: @@ -83,6 +83,7 @@ impl Data {
  );
  }
  + /// Returns `true` if the stream is finished reading/writing
  pub fn is_finished(&self) -> bool {
  self.len <= self.offset
  }
  @@ -97,23 +98,48 @@ impl Data {
  let mut count = 0;
  for chunk in chunks.iter_mut() {
  + if let Some(data) = self.send_one(amount).filter(|data| !data.is_empty()) {
  + amount -= data.len();
  + count += 1;
  + *chunk = data;
  + } else {
  + break;
  + }
  + }
  +
  + Some(count)
  + }
  +
  + /// Sends a single chunk of data, up to the provided `amount`
  + pub fn send_one(&mut self, amount: usize) -> Option<Bytes> {
  + if self.is_finished() {
  + return None;
  + }
  +
  let offset = (self.offset % DATA_MOD as u64) as usize;
  let to_send = ((self.len - self.offset) as usize)
  .min(amount)
  .min(DATA.len() - offset);
  if to_send == 0 {
  - break;
  + return Some(Bytes::new());
  }
  - *chunk = DATA.slice(offset..offset + to_send);
  + let chunk = DATA.slice(offset..offset + to_send);
  - self.offset += to_send as u64;
  - amount -= to_send;
  - count += 1;
  + self.seek_forward(to_send);
  +
  + Some(chunk)
  }
  - Some(count)
  + /// Returns the current offset being received or sent
  + pub fn offset(&self) -> u64 {
  + self.offset
  + }
  +
  + /// Moves the current offset forward by the provided `len`
  + pub fn seek_forward(&mut self, len: usize) {
  + self.offset += len as u64;
  }
  }
  