示例#1
0
int FileReader::extract_record(RecordBlock &block, const RecordDelima &rec_delima, const RecordDelima &col_delima, int64_t max_rec_extracted) 
{
  int64_t pos = 0;
  int64_t rec_nr = 0;
  int64_t last_pos = 0;
  int ret = 0;
  bool has_partial_rec = false;

  std::string &buffer = block.buffer();

  while (pos < buffer_size_) {
    char *p = reader_buffer_ + pos;
    last_pos = pos;

    if (rec_nr >= max_rec_extracted) {
      TBSYS_LOG(DEBUG, "extract rec count[%ld] reaches max_rec_extracted[%ld]", rec_nr, max_rec_extracted);
      break;
    }

    if ((has_partial_rec = is_partial_record(pos, rec_delima, col_delima)) == true) {
      TBSYS_LOG(DEBUG, "partial record meet, will be proceed next time");
      break;
    }

    rec_nr++;
    col_delima.append_delima(reader_buffer_, pos, buffer_size_); /* replace rec_delima with col_delima */
    rec_delima.skip_delima(pos);                                      /* skip rec_delima */

    /* include rec_delima in buffer */
    int32_t psize = static_cast<int32_t>(pos - last_pos);
    append_int32(buffer, psize);

    last_pos = pos;
    buffer.append(p, psize);                   /* append length of record here */
  }

  TBSYS_LOG(DEBUG, "record block actual used size[%ld], rec_nr[%ld]", pos, rec_nr);

  if ((has_partial_rec && last_pos < buffer_size_)    /* partial record reside in buffer */
    || (rec_nr >= max_rec_extracted && last_pos < buffer_size_)) {                     
    shrink(last_pos);
  } else {
    buffer_size_ = 0;
  }

  if (rec_nr == 0 && buffer_size_ == kReadBufferSize) {
    TBSYS_LOG(ERROR, "record size too big, max size=%d", kReadBufferSize);
    ret = -1;
  }

  if (ret == 0) {
    block.set_rec_num(rec_nr);
  }

  return ret;
}
示例#2
0
文件: butil.c 项目: pstray/bareos
char *rec_state_bits_to_str(DEV_RECORD *rec)
{
   static char buf[200];
   buf[0] = 0;
   if (rec->state_bits & REC_NO_HEADER) {
      strcat(buf, _("Nohdr,"));
   }
   if (is_partial_record(rec)) {
      strcat(buf, _("partial,"));
   }
   if (rec->state_bits & REC_BLOCK_EMPTY) {
      strcat(buf, _("empty,"));
   }
   if (rec->state_bits & REC_NO_MATCH) {
      strcat(buf, _("Nomatch,"));
   }
   if (rec->state_bits & REC_CONTINUATION) {
      strcat(buf, _("cont,"));
   }
   if (buf[0]) {
      buf[strlen(buf)-1] = 0;
   }
   return buf;
}