/* connect2 (C->S): userid + auth_info */ EdpPacket* PacketConnect2(const int8_t* userid, const int8_t* auth_info) { EdpPacket* pkg = NULL; uint32_t remainlen; pkg = NewBuffer(); /* msg type */ WriteByte(pkg, CONNREQ); /* remain len */ remainlen = (2 + 3) + 1 + 1 + 2 + 2 + (2 + strlen((const char *)userid)) + (2 + strlen((const char *)auth_info)); WriteRemainlen(pkg, remainlen); /* protocol desc */ WriteStr(pkg, PROTOCOL_NAME); /* protocol version */ WriteByte(pkg, PROTOCOL_VERSION); /* connect flag */ WriteByte(pkg, 0xC0); /* keep time */ WriteUint16(pkg, 0x0080); /* devid */ WriteByte(pkg, 0x00); WriteByte(pkg, 0x00); /* USERID */ WriteStr(pkg, userid); /* auth info */ WriteStr(pkg, auth_info); return pkg; }
/* connect1 (C->S): devid + apikey */ EdpPacket* PacketConnect1(const int8_t* devid, const int8_t* auth_key) { uint32_t remainlen; EdpPacket* pkg = NewBuffer(); if(pkg == NULL) { return NULL; } /* msg type */ WriteByte(pkg, CONNREQ); /* remain len */ remainlen = (2 + 3) + 1 + 1 + 2 + (2 + strlen((const char *)devid)) + (2 + strlen((const char *)auth_key)); WriteRemainlen(pkg, remainlen); /* protocol desc */ WriteStr(pkg, PROTOCOL_NAME); /* protocol version */ WriteByte(pkg, PROTOCOL_VERSION); /* connect flag */ WriteByte(pkg, 0x40); /* keep time */ WriteUint16(pkg, 0x0080); /* DEVID */ WriteStr(pkg, devid); /* auth key */ WriteStr(pkg, auth_key); return pkg; }
int32_t WriteStr(Buffer* buf, const int8_t *str) { uint16_t length = 0; my_assert(buf->_read_pos == 0); length = strlen((const char *)str); return WriteUint16(buf, length) || WriteBytes(buf, str, length); }
int32 WriteStr(Buffer* buf, const char *str) { uint16 length = mystrlen(str); //assert(buf->_read_pos == 0); return WriteUint16(buf, length) || WriteBytes(buf, str, length); }
EdpPacket* PacketCmdResp(const int8_t* cmdid, uint16_t cmdid_len, const int8_t* resp, uint32_t resp_len) { EdpPacket* send_pkg = NULL; unsigned remainlen = 0; send_pkg = NewBuffer(); /* 6 = 2 + 4 = len(cmdid_len) + len(resp_len) */ remainlen = cmdid_len + resp_len + (resp_len ? 6 : 2); WriteByte(send_pkg, CMDRESP); WriteRemainlen(send_pkg, remainlen); WriteUint16(send_pkg, cmdid_len); WriteBytes(send_pkg, cmdid, cmdid_len); if (resp_len) { WriteUint32(send_pkg, resp_len); WriteBytes(send_pkg, resp, resp_len); } return send_pkg; }
void UTPex::encode(BEncoder & enc,const std::map<Uint32,net::Address> & ps) { if (ps.size() == 0) { enc.write(""); return; } Uint8* buf = new Uint8[ps.size() * 6]; Uint32 size = 0; std::map<Uint32,net::Address>::const_iterator i = ps.begin(); while (i != ps.end()) { const net::Address & addr = i->second; WriteUint32(buf,size,addr.ip()); WriteUint16(buf,size + 4,addr.port()); size += 6; i++; } enc.write(buf,size); delete [] buf; }
/** * This method encodes and writes an `int16_t` value to current input frame. * * Before using this method `BeginFrame()` must be called to start and prepare a new input frame. Otherwise, this * method does nothing and returns error status `OT_ERROR_INVALID_STATE`. * * If no buffer space is available, this method will discard and clear the current input frame and return the * error status `OT_ERROR_NO_BUFS`. * * @param[in] aInt16 The value to add to input frame. * * @retval OT_ERROR_NONE Successfully added given value to the frame. * @retval OT_ERROR_NO_BUFS Insufficient buffer space available to add the value. * @retval OT_ERROR_INVALID_STATE `BeginFrame()` has not been called earlier to start the frame. * */ otError WriteInt16(int16_t aInt16) { return WriteUint16(static_cast<uint16_t>(aInt16)); }
void nsSOCKSSocketInfo::WriteNetPort(const PRNetAddr *addr) { WriteUint16(PR_NetAddrInetPort(addr)); }