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); }
// 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; }