lianghaoming7 2016-09-08 16:07 采纳率: 0%
浏览 1053

websocket协议 C++的问题

已经有编码代码
char * PackData(CString message)
{
unsigned char * contentBytes = NULL;
CString temp;
ConvertGBKToUtf8(temp,(char *)message.GetString());

        if (temp.GetLength() < 126){
            contentBytes =(unsigned char *)malloc(temp.GetLength()+2);
            contentBytes[0] = 0x81;
            contentBytes[1] = (unsigned char)temp.GetLength();
            strcpy((char *)contentBytes+2,temp.GetString());
        }else if (temp.GetLength() < 0xFFFF){
            contentBytes = (unsigned char *)malloc(temp.GetLength()+4);
            contentBytes[0] = (unsigned char)0x81;
            contentBytes[1] =(unsigned char) 126;
            contentBytes[2] = (unsigned char)((unsigned char)temp.GetLength() & 0xFF);
            contentBytes[3] = (unsigned char)((unsigned char)temp.GetLength() >> 8 & 0xFF);
            strcpy((char *)contentBytes+4,temp.GetString());
        }else{
            // 暂不处理超长内容  
        }

        return (char *)contentBytes;
    }  

            跪求解码代码
  • 写回答

1条回答

  • devmiao 2016-09-08 16:13
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题