bool WandReadVector(std::string::iterator &buffer,
                    std::string::iterator &buffer_end, binary_string &target,
                    uint32_t len) {
  target.resize(len);

  binary_string::iterator target_pos = target.begin();

  for (; len > 0 && buffer < buffer_end; len--, buffer++, target_pos++) {
    *target_pos = (unsigned char)*buffer;
  }

  return (len == 0);
}
示例#2
0
 // TODO: to factor away
 binary_string_ptr prepare_frame(frame::opcode::value opcode,
                                 bool mask,
                                 const binary_string& payload)  {
     if (opcode != frame::opcode::TEXT) {
         // TODO: hybi_legacy doesn't allow non-text frames.
         throw;
     }
     
     // TODO: mask = ignore?
     
     // TODO: utf8 validation on payload.
     
     binary_string_ptr response(new binary_string(payload.size()+2));
     
     (*response)[0] = 0x00;
     std::copy(payload.begin(),payload.end(),response->begin()+1);
     (*response)[response->size()-1] = 0xFF;
     
     return response;
 }
bool WandReadTagLenDataVector(std::string::iterator &buffer,
                              std::string::iterator &buffer_end,
                              uint32_t tag_len, uint32_t len_len, uint32_t &tag,
                              binary_string &target) {
  target.resize(0);
  tag = 0;

  if (tag_len && !WandReadUintX(buffer, buffer_end, tag_len, tag, true))
    return false;

  if ((tag & TAG_MSB) != 0)
    return true;

  uint32_t len = 0;
  if (len_len && !WandReadUintX(buffer, buffer_end, len_len, len))
    return false;

  if (len == 0)
    return true;

  return WandReadVector(buffer, buffer_end, target, len);
}