{ @Override public String decode(ByteBuf buffer) { int lineEndIndex = CodecUtils.X.findLineEndIndex(buffer); if (-1 == lineEndIndex) { return null; } Long length = (Long) DefaultRespCodec.DECODERS.get(ReplyType.INTEGER).decode(buffer); if (null == length) { return null; } // Bulk Null String if (RespConstants.NEGATIVE_ONE.equals(length)) { return null; } // Bulk Empty String if (RespConstants.ZERO.equals(length)) { return RespConstants.EMPTY_STRING; } // 真实字节内容的长度 int readLength = (int) length.longValue(); if (buffer.readableBytes() > readLength) { byte[] bytes = new byte[readLength]; buffer.readBytes(bytes); // 重置读游标为rn之后的第一个字节 buffer.readerIndex(buffer.readerIndex() + 2); return new String(bytes, RespConstants.UTF_8); } return null; }}public class RespArrayDecoder implements RespDecoder { @Override public Object decode(ByteBuf buffer) { int lineEndIndex = CodecUtils.X.findLineEndIndex(buffer); if (-1 == lineEndIndex) { return null; } // 解析元素个数 Long length = (Long) DefaultRespCodec.DECODERS.get(ReplyType.INTEGER).decode(buffer); if (null == length) { return null; } // Null Array if (RespConstants.NEGATIVE_ONE.equals(length)) { return null; } // Array Empty List if (RespConstants.ZERO.equals(length)) { return Lists.newArrayList(); } List
推荐阅读
-
张柏芝早就被绿了?谢霆锋10年后终于公开女儿,原来王菲早已知晓
-
-
月球|开始行动了!NASA登月联盟在月球上发现水,却将中国排除在外
-
华为荣耀|突然宣布!荣耀营销经理退休,引发网友猜疑
-
-
Logo设计也可以二次元化,说不准某些图标的灵感正是来自于二次元
-
世界上最古老的四种文字分别是什么 世界上最古老的六大文字
-
-
招聘|用招聘网站的后台告诉你,为什么你投了几百份简历,很少有人回复
-
无敌改装车▲RR:Type-RR,最强思域FD2!Mugen
-
张爱玲|张爱玲在晚年崇尚“极简主义生活”,并非穷困潦倒,稿费拿到手软
-
AutoR智驾 逆行外卖小哥、深夜拥堵轻松应对,元戎启行自动驾驶汽车挑战“宇宙最强街道”
-
-
-
三十年体坛故事|7连杀+赛季双杀!上港仍是国安梦魇 御林军争冠梦碎?
-
-
教育部|教育部重要通知,2条升学途径被堵死!家长无语:之前努力白费了
-
妻子伺候二婚丈夫五年,继子来医院探望一趟,妻子含泪提出离婚
-
-