MessagePtr Frame::write() { MessagePtr msg = std::make_shared<std::vector <char> >(); msg->reserve(10); unsigned char firstbyte = 0; firstbyte |= fin << 7; firstbyte |= rsv1 << 6; firstbyte |= rsv2 << 5; firstbyte |= rsv3 << 4; firstbyte |= opcode & 0xF; msg->push_back(firstbyte); // host never masks.. payload_length = payload_data->size(); if(payload_length < 126) { msg->push_back(uint8_t(payload_length)); } else if(payload_length <= 0xFFFF) { msg->push_back(uint8_t(126)); u16 conv; conv.integer = htons(uint16_t(payload_length)); msg->push_back(conv.data[0]); msg->push_back(conv.data[1]); } else { msg->push_back(uint8_t(127)); u64 conv; conv.integer = htonll(payload_length); for(int i = 0; i < 8; i++) msg->push_back(conv.data[i]); } return msg; }