当前位置: 首页 > news >正文

网站模板下载网站有哪些内容中国搜索网站排名

网站模板下载网站有哪些内容,中国搜索网站排名,陕西省和城乡建设厅网站,临沂哪家做网站最好本章内容其实没有多大难度,主要考察大家的细心程度.计算数据长度然后截取相应字节数组并按照协议进行解码,编码则反之。 1.基础消息的编解码 Override public BasicMessage decode(byte[] bytes) {int dataLength ByteUtil.bytesToInt(ByteUtil.extra…

本章内容其实没有多大难度,主要考察大家的细心程度.计算数据长度然后截取相应字节数组并按照协议进行解码,编码则反之。

1.基础消息的编解码

@Override
public BasicMessage decode(byte[] bytes) {int dataLength = ByteUtil.bytesToInt(ByteUtil.extract(bytes, 2, 4));if (dataLength != bytes.length) {throw new IllegalArgumentException("The data length is incorrect.");}return new BasicMessage().setRequest(RequestType.valueOfId(ByteUtil.extract(bytes, 0, 1)[0])).setResponse(ResponseType.valueOfId(ByteUtil.extract(bytes, 1, 1)[0])).setDataLength(dataLength).setPayload(ByteUtil.extract(bytes, 6, dataLength - 1 - 1 - 4 - 8)).setTimestamp(ByteUtil.bytesToLong(ByteUtil.extract(bytes, dataLength - 8, 8)));
}@Override
public byte[] encode() {byte[] request = new byte[]{this.getRequest().getId()};byte[] response = new byte[]{this.getResponse().getId()};byte[] payload = (null == this.getPayload()) ? new byte[]{} : this.getPayload();byte[] timestamp = ByteUtil.longToBytes(this.getTimestamp(), 8);byte[] dataLength = ByteUtil.intToBytes(request.length + response.length + 4 + payload.length + timestamp.length, 4);return ByteUtil.concat(request,response,dataLength,payload,timestamp);
}

2.登入、登出消息的编解码

@Override
public Login decode(byte[] bytes) {return new Login().setLoginId(ByteUtil.bytesToShort(ByteUtil.extract(bytes, 0, 2))).setLoginInfo(new String(ByteUtil.extract(bytes, 2, bytes.length - 2), StandardCharsets.UTF_8));
}@Override
public byte[] encode() {return ByteUtil.concat(ByteUtil.shortToBytes(this.getLoginId(), 2),this.getLoginInfo().getBytes(StandardCharsets.UTF_8));
}
@Override
public Logout decode(byte[] bytes) {return new Logout().setLogoutId(ByteUtil.bytesToShort(ByteUtil.extract(bytes, 0, 2)));
}@Override
public byte[] encode() {return ByteUtil.concat(ByteUtil.shortToBytes(this.getLogoutId(), 2));
}

3.上行、下行消息的编解码

@Override
public Upstream decode(byte[] bytes) {return new Upstream().setStatus(StatusType.valueOfId(ByteUtil.extract(bytes, 0, 1)[0])).setLongitude(ByteUtil.bytesToInt(ByteUtil.extract(bytes, 1, 4))).setLatitude(ByteUtil.bytesToInt(ByteUtil.extract(bytes, 5, 4)));
}@Override
public byte[] encode() {return ByteUtil.concat(new byte[]{this.getStatus().getId()},ByteUtil.intToBytes(this.getLongitude(), 4),ByteUtil.intToBytes(this.getLatitude(), 4));
}
@Override
public Downstream decode(byte[] bytes) {return new Downstream().setCommand(CommandType.valueOfId(ByteUtil.extract(bytes, 0, 1)[0])).setStatus(StatusType.valueOfId(ByteUtil.extract(bytes, 1, 1)[0]));
}@Override
public byte[] encode() {return ByteUtil.concat(new byte[]{this.getCommand().getId()},new byte[]{this.getStatus().getId()});
}

4.文件传输、文件下载的编解码

@Override
public FileTransfer decode(byte[] bytes) {int nameLength = ByteUtil.bytesToInt(ByteUtil.extract(bytes, 0, 1));String filename = new String(ByteUtil.extract(bytes, 1, nameLength), StandardCharsets.UTF_8);long id = ByteUtil.bytesToLong(ByteUtil.extract(bytes, 1 + nameLength, 8));int total = ByteUtil.bytesToInt(ByteUtil.extract(bytes, 1 + nameLength + 8, 4));int index = ByteUtil.bytesToInt(ByteUtil.extract(bytes, 1 + nameLength + 8 + 4, 4));int dataLength = ByteUtil.bytesToInt(ByteUtil.extract(bytes, 1 + nameLength + 8 + 4 + 4, 4));byte[] content = ByteUtil.extract(bytes, 1 + nameLength + 8 + 4 + 4 + 4, dataLength);int crc = ByteUtil.crc(content, content.length);return new FileTransfer().setNameLength(nameLength).setFilename(filename).setId(id).setTotal(total).setIndex(index).setDataLength(dataLength).setContent(content).setCrc(crc);
}@Override
public byte[] encode() {byte[] filename = this.getFilename().getBytes(StandardCharsets.UTF_8);byte[] nameLength = ByteUtil.intToBytes(filename.length, 1);byte[] id = ByteUtil.longToBytes(this.getId(), 8);byte[] total = ByteUtil.intToBytes(this.getTotal(), 4);byte[] index = ByteUtil.intToBytes(this.getIndex(), 4);byte[] content = this.getContent();byte[] dataLength = ByteUtil.intToBytes(content.length, 4);byte[] crc = ByteUtil.intToBytes(ByteUtil.crc(content, content.length), 1);return ByteUtil.concat(nameLength,filename,id,total,index,dataLength,content,crc);
}
@Override
public FileDownload decode(byte[] bytes) {int nameLength = ByteUtil.bytesToInt(ByteUtil.extract(bytes, 0, 1));String filename = new String(ByteUtil.extract(bytes, 1, nameLength), StandardCharsets.UTF_8);return new FileDownload().setNameLength(nameLength).setFilename(filename);
}@Override
public byte[] encode() {byte[] filename = this.getFilename().getBytes(StandardCharsets.UTF_8);byte[] nameLength = ByteUtil.intToBytes(filename.length, 1);return ByteUtil.concat(nameLength,filename);
}
http://www.hkea.cn/news/555248/

相关文章:

  • 制作一个网站步骤东莞网络营销销售
  • 专业的营销网站建设公司百度联盟注册
  • 机械类网站用什么做背景指数运算法则
  • 微信如何绑定网站加速游戏流畅的软件
  • 茂名整站优化百度问答首页
  • 手机网站搭建网络宣传方式
  • 2003网站建设网站seo哪家公司好
  • 成都学校网站制作2022年国际十大新闻
  • 工厂外贸网站建设台州网络推广
  • 酒店网站建设方案策划百度seo怎么做网站内容优化
  • 网站更改公司需要重新备案吗搜索网页内容
  • 现在做网站还用dw做模板了吗成人电脑速成培训班
  • 做app要不要建网站刚开的店铺怎么做推广
  • 做生存分析的网站有哪些专业的网站优化公司
  • 网站双倍浮动百度联盟app
  • 北京网站设计确保代码符合w3c广州网络营销的推广
  • 做网站实名认证有什么用百度移动端模拟点击排名
  • 知更鸟wordpress 怎样沈阳百度seo关键词优化排名
  • 携程网站模板互联网营销策略有哪些
  • 做网站内链什么意思上海排名优化seobwyseo
  • 四川做直销会员网站百度网盘帐号登录入口
  • 做百度竞价对网站有无要求网站推广排名服务
  • 建设工程合同包括成都网站改版优化
  • 深圳不加班的互联网公司整站seo优化
  • 中国做的很好的食品网站肇庆疫情最新消息
  • 做时时彩网站微信seo关键词有话要多少钱
  • 陇南市建设局网站商务软文写作
  • 做学术研究的网站营销方案怎么写?
  • 专业网站设计公司有哪些秒收录关键词代发
  • 织梦网站模板源码下载真实有效的优化排名