Refine search
@Override public Object decode(ByteBuf buf, State state) { byte[] result = new byte[buf.readableBytes()]; buf.readBytes(result); return fromByteArrayReverse(result); } };
@Override public String decode(ByteBuf source) { if (source.readableBytes() >= 4) { int length = source.readInt(); if (length > 0 && source.readableBytes() > 0) { byte[] bytes = new byte[length]; source.readBytes(bytes); return new String(bytes); } } return null; } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { while (in.readableBytes() >= frameLength) { ByteBuf buf = in.readBytes(frameLength); out.add(buf); } } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int startIndex = -1; int endIndex = -1; if((startIndex = in.indexOf(in.readerIndex(), in.writerIndex(), TransferProtocolUtils.PROTOCOL_HAED)) != -1 && (endIndex = in.indexOf(startIndex + 1, in.writerIndex(), TransferProtocolUtils.PROTOCOL_TAIL)) != -1) { endIndex ++; byte[] bytes = new byte[endIndex - startIndex]; in.skipBytes(startIndex - in.readerIndex()); in.readBytes(bytes, 0, bytes.length); out.add(bytes); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return; } in.markReaderIndex(); int length = in.order(ByteOrder.LITTLE_ENDIAN).readInt(); if (in.readableBytes() < length) { in.resetReaderIndex(); return; } ByteBuf buf = ctx.alloc().buffer(length); in.readBytes(buf, length); out.add(buf.retain()); } }
params.add(source.readInt()); return true; case ClusterConstants.PARAM_TYPE_STRING: int length = source.readInt(); byte[] bytes = new byte[length]; source.readBytes(bytes); params.add(new String(bytes)); return true; case ClusterConstants.PARAM_TYPE_BOOLEAN: params.add(source.readBoolean()); return true; case ClusterConstants.PARAM_TYPE_DOUBLE:
if (in.readableBytes() < 4) { return NOT_ENOUGH_INPUT; for (; copies > 0; copies--) { out.readerIndex(initialIndex - offset); out.readBytes(out, offset); out.readBytes(out, length % offset); out.readBytes(out, length);
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int readableBytes = in.readableBytes(); if (readableBytes > maxFrameSize) { // discard the bytes in.clear(); throw new TooLongFrameException(); } ByteBuf buf = in.readBytes(readableBytes); out.add(buf); } }
@Override protected void decode( ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (done) { int readable = actualReadableBytes(); if (readable == 0) { // if non is readable just return null // https://github.com/netty/netty/issues/1159 return; } out.add(buffer.readBytes(readable)); } else { int oldSize = out.size(); super.decode(ctx, buffer, out); if (failOnMissingResponse) { int size = out.size(); for (int i = oldSize; i < size; i++) { decrement(out.get(i)); } } } }
@Override public final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return; } in.markReaderIndex(); int dataLength = in.readInt(); /*if (dataLength <= 0) { ctx.close(); }*/ if (in.readableBytes() < dataLength) { in.resetReaderIndex(); return; } byte[] data = new byte[dataLength]; in.readBytes(data); Object obj = SerializationUtil.deserialize(data, genericClass); //Object obj = JsonUtil.deserialize(data,genericClass); // Not use this, have some bugs out.add(obj); }
@Override public Object decode(ByteBuf buf, State state) { byte[] result = new byte[buf.readableBytes()]; buf.readBytes(result); return result; } };
@Override public boolean decode(ByteBuf in) { int i = in.readableBytes(); if (i < 4) { return false; } i -= 4; int length = in.readInt(); if (i < length) { return false; } byte[] buffer = new byte[length]; in.readBytes(buffer); ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); decode(byteBuffer); return true; }
@Override public void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out) throws Exception { ByteBuf buf = packet.content(); byte[] encoded = new byte[buf.readableBytes()]; buf.readBytes(encoded); try { Message msg = Message.decode(encoded); DiscoveryEvent event = new DiscoveryEvent(msg, packet.sender()); out.add(event); } catch (Exception e) { throw new RuntimeException("Exception processing inbound message from " + ctx.channel().remoteAddress() + ": " + toHexString(encoded), e); } } }
@Override protected void decode( ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (done) { final int readable = actualReadableBytes(); if (readable == 0) { // if non is readable just return null // https://github.com/netty/netty/issues/1159 return; } out.add(buffer.readBytes(readable)); } else { final int oldSize = out.size(); super.decode(ctx, buffer, out); if (failOnMissingResponse) { final int size = out.size(); for (int i = oldSize; i < size; i++) { decrement(out.get(i)); } } } }
@Override public Object decode(ByteBuf buf, State state) { byte[] result = new byte[buf.readableBytes()]; buf.readBytes(result); return fromByteArrayReverse(result); } };
@Override public boolean decode(ByteBuf in) { int i = in.readableBytes(); if (i < 4) { return false; } i -= 4; int length = in.readInt(); if (i < length) { return false; } byte[] buffer = new byte[length]; in.readBytes(buffer); ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); doDecode(byteBuffer); return true; }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { // check for length field readability in.markReaderIndex(); if (!readableVarInt(in)) { return; } // check for contents readability int length = ByteBufUtils.readVarInt(in); if (in.readableBytes() < length) { in.resetReaderIndex(); return; } // read contents into buf ByteBuf buf = ctx.alloc().buffer(length); in.readBytes(buf, length); out.add(buf); } }