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

做网站 网上接单查询网 域名查询

做网站 网上接单,查询网 域名查询,wordpress支付宝扫码支付,wordpress写的网站本章内容其实没有多大难度,主要考察大家的细心程度.计算数据长度然后截取相应字节数组并按照协议进行解码,编码则反之。 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/704753/

相关文章:

  • 无锡做网站哪家公司好一个公司可以做几个百度推广
  • 专题网站建设工作关键词林俊杰无损下载
  • adobe 网站开发软件软文写作兼职
  • 英文网站建设 淮安免费培训网站
  • 隔离需要多少钱湖南网站seo找行者seo
  • wordpress简单企业站seo怎么刷排名
  • 网站建设与运维泉州全网推广
  • 网站建站哪个公司好一点营销咨询服务
  • 值得玩的网页游戏北京seo营销培训
  • 中国建设银行网站分期通百度推广登录平台网址
  • 公司内部网站源码新闻软文推广案例
  • vf建设银行网站谷歌seo排名
  • 如何申请商业服务器武汉seo工厂
  • 祥云平台英文网站微博指数查询入口
  • 公司网站建设准备资料今日重大财经新闻
  • 发布网站后备案免费网站建站页面
  • 浙江建设职业技术学院迎新网站做一个网站要多少钱
  • axure做网站好不好手机百度问一问
  • 开发微信小程序的流程广州seo优化电话
  • 小企业网站建设和管理全能搜
  • 无棣县建设局网站游戏优化大师下载安装
  • 小额贷款 网站模板品牌推广软文
  • 网站建设开发成本天津百度搜索网站排名
  • 做的好的营销型网站有哪些内容外贸网站外链平台
  • 东营网站建设预算价格百度网盘网页版入口官网
  • 网站建设中标公告18款禁用看奶app入口
  • 网站运营人员岗位职责长沙正规seo优化价格
  • cnzz统计代码放在后台网站为什么没显示seo的英文全称是什么
  • 杭州企业网站建设方案广告门
  • 自己免费做网站(二)seo优化公司信