List of usage examples for io.netty.buffer ByteBuf readLong
public abstract long readLong();
From source file:fourteen.proprietaryprotocol.codec.NettyMessageDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; }// w w w. ja v a 2 s .c o m NettyMessage message = new NettyMessage(); Header header = new Header(); header.setCrcCode(frame.readInt()); header.setLength(frame.readInt()); header.setSessionId(frame.readLong()); header.setType(frame.readByte()); header.setPriority(frame.readByte()); int size = frame.readInt(); if (size > 0) { Map<String, Object> attch = new HashMap<String, Object>(size); int keySize = 0; byte[] keyArray = null; String key = null; for (int i = 0; i < size; i++) { keySize = frame.readInt(); keyArray = new byte[keySize]; frame.readBytes(keyArray); key = new String(keyArray, "UTF-8"); attch.put(key, marshallingDecoder.decode(frame)); } keyArray = null; key = null; header.setAttachment(attch); } if (frame.readableBytes() > 4) { message.setObject(marshallingDecoder.decode(frame)); } message.setHeader(header); return message; }
From source file:gedi.remote.codec.DefaultDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < Integer.BYTES) return;/* w ww .j a v a 2 s . c om*/ in.markReaderIndex(); int size = in.readInt(); if (in.readableBytes() < size) { in.resetReaderIndex(); return; } // everything has arrived, decode char[] classname = new char[in.readInt()]; for (int i = 0; i < classname.length; i++) classname[i] = (char) (in.readByte() & 255); String clsName = String.valueOf(classname); if (clsName.length() == 1) { switch (clsName) { case "A": char[] re = new char[in.readInt()]; for (int i = 0; i < re.length; i++) re[i] = (char) (in.readByte() & 255); out.add(String.valueOf(re)); break; case "B": out.add(in.readByte()); break; case "S": out.add(in.readShort()); break; case "I": out.add(in.readInt()); break; case "L": out.add(in.readLong()); break; case "F": out.add(in.readFloat()); break; case "D": out.add(in.readDouble()); break; } } else { if (!ClassPathCache.getInstance().existsClass(clsName)) { in.resetReaderIndex(); return; } Class<?> cls = Class.forName(clsName); BinarySerializable re = (BinarySerializable) cls.newInstance(); BinaryBlob buff = new BinaryBlob(size - Integer.BYTES - classname.length); in.readBytes(buff.getBuffer()); buff.getBuffer().flip(); re.deserialize(buff); out.add(re); } }
From source file:hellfirepvp.astralsorcery.common.network.packet.client.PktRequestSeed.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { this.dimId = buf.readInt(); this.session = buf.readInt(); this.seed = buf.readLong(); }
From source file:hellfirepvp.astralsorcery.common.network.packet.server.PktCraftingTableFix.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { at = BlockPos.fromLong(buf.readLong()); }
From source file:herddb.proto.PduCodec.java
License:Apache License
public static Object readObject(ByteBuf dii) { int type = ByteBufUtils.readVInt(dii); switch (type) { case TYPE_BYTEARRAY: return ByteBufUtils.readArray(dii); case TYPE_LONG: return dii.readLong(); case TYPE_INTEGER: return dii.readInt(); case TYPE_SHORT: return dii.readShort(); case TYPE_BYTE: return dii.readByte(); case TYPE_STRING: return ByteBufUtils.readUnpooledRawString(dii); case TYPE_TIMESTAMP: return new java.sql.Timestamp(dii.readLong()); case TYPE_NULL: return null; case TYPE_BOOLEAN: return dii.readBoolean(); case TYPE_DOUBLE: return dii.readDouble(); default:/* w w w . jav a2s. com*/ throw new IllegalArgumentException("bad column type " + type); } }
From source file:herddb.utils.ByteBufUtils.java
License:Apache License
public static final double readDouble(ByteBuf buffer) { return Double.longBitsToDouble(buffer.readLong()); }
From source file:hivemall.mix.MixMessageDecoder.java
License:Open Source License
private static Object decodeObject(final ByteBuf in) throws IOException { final byte type = in.readByte(); switch (type) { case INTEGER_TYPE: { int i = in.readInt(); return Integer.valueOf(i); }//from w w w . j a v a 2 s .c o m case TEXT_TYPE: { int length = in.readInt(); byte[] b = new byte[length]; in.readBytes(b, 0, length); Text t = new Text(b); return t; } case STRING_TYPE: { return readString(in); } case INT_WRITABLE_TYPE: { int i = in.readInt(); return new IntWritable(i); } case LONG_WRITABLE_TYPE: { long l = in.readLong(); return new LongWritable(l); } default: break; } throw new IllegalStateException("Illegal type: " + type); }
From source file:io.atomix.catalyst.transport.netty.NettyConnection.java
License:Apache License
/** * Handles a request.//ww w . j a v a2s.co m */ void handleRequest(ByteBuf buffer) { long requestId = buffer.readLong(); try { Object request = readRequest(buffer); HandlerHolder handler = handlers.get(request.getClass()); if (handler != null) { handler.context.executor().execute(() -> handleRequest(requestId, request, handler)); } else { handleRequestFailure(requestId, new SerializationException("unknown message type: " + request.getClass()), this.context); } } catch (SerializationException e) { handleRequestFailure(requestId, e, this.context); } finally { buffer.release(); } }
From source file:io.atomix.catalyst.transport.netty.NettyConnection.java
License:Apache License
/** * Handles response.//from w w w . j av a 2 s . c om */ void handleResponse(ByteBuf response) { long requestId = response.readLong(); byte status = response.readByte(); switch (status) { case SUCCESS: try { handleResponseSuccess(requestId, readResponse(response)); } catch (SerializationException e) { handleResponseFailure(requestId, e); } break; case FAILURE: try { handleResponseFailure(requestId, readError(response)); } catch (SerializationException e) { handleResponseFailure(requestId, e); } break; } response.release(); }
From source file:io.atomix.catalyst.transport.NettyConnection.java
License:Apache License
/** * Handles a request./*from w w w .j a v a 2s.com*/ */ void handleRequest(ByteBuf buffer) { long requestId = buffer.readLong(); Object request = readRequest(buffer); HandlerHolder handler = handlers.get(request.getClass()); if (handler != null) { handler.context.executor().execute(() -> handleRequest(requestId, request, handler)); } else { handleRequestFailure(requestId, new IllegalStateException("unknown message type: " + request.getClass())); } buffer.release(); }