List of usage examples for io.netty.buffer ByteBuf order
@Deprecated public abstract ByteBuf order(ByteOrder endianness);
From source file:com.eightkdata.mongowp.mongoserver.util.ChannelLittleEndianEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, ReplyMessage msg, ByteBuf out) throws Exception { encodeLittleEndian(ctx, msg, out.order(ByteOrder.LITTLE_ENDIAN)); }
From source file:com.eightkdata.mongowp.mongoserver.util.ChannelLittleEndianHandler.java
License:Open Source License
@Override protected final void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> objects) throws Exception { decodeLittleEndian(channelHandlerContext, byteBuf.order(ByteOrder.LITTLE_ENDIAN), objects); }
From source file:com.eightkdata.mongowp.mongoserver.util.LengthFieldPrependerLittleEndian.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { super.encode(ctx, msg, out.order(ByteOrder.LITTLE_ENDIAN)); }
From source file:com.netty.test.LengthFieldBasedExFrameDecoder.java
License:Apache License
private long getFrameLength(ByteBuf in, int actualLengthFieldOffset) { in = in.order(byteOrder); long frameLength; switch (lengthFieldLength) { case 1:/* www . j av a 2 s .c o m*/ frameLength = in.getUnsignedByte(actualLengthFieldOffset); break; case 2: frameLength = in.getUnsignedShort(actualLengthFieldOffset); break; case 3: frameLength = in.getUnsignedMedium(actualLengthFieldOffset); break; case 4: frameLength = in.getUnsignedInt(actualLengthFieldOffset); break; case 8: frameLength = in.getLong(actualLengthFieldOffset); break; default: throw new Error("should not reach here"); } return frameLength; }
From source file:com.ogarproject.ogar.server.net.packet.Packet.java
License:Open Source License
public static String readUTF16(ByteBuf in) { in = in.order(ByteOrder.BIG_ENDIAN); ByteBuf buffer = in.alloc().buffer(); char chr;//ww w . j a va 2 s . co m while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) { buffer.writeChar(chr); } return buffer.toString(Charsets.UTF_16LE); }
From source file:com.ogarproject.ogar.server.net.packet.Packet.java
License:Open Source License
public static void writeUTF16(ByteBuf out, String s) { out.order(ByteOrder.BIG_ENDIAN).writeBytes(s.getBytes(Charsets.UTF_16LE)); out.writeChar(0);// www. j a v a2 s .c o m }
From source file:com.spotify.heroic.consumer.collectd.CollectdParser.java
License:Apache License
public static Iterator<CollectdSample> parse(final ByteBuf frame) { if (frame.readableBytes() < 4) { throw new RuntimeException("frame to short"); }//from w w w . j av a 2 s. c om frame.order(ByteOrder.BIG_ENDIAN); return new Iterator<CollectdSample>() { private Decoded decoded = new Decoded(); @Override public boolean hasNext() { return frame.readableBytes() > 0; } @Override public CollectdSample next() { while (true) { final int type = frame.readUnsignedShort(); final int size = frame.readUnsignedShort(); switch (type) { case HOST: decoded.host = parseString(frame, size); break; case TIME: decoded.time = frame.readLong(); break; case TIME_HR: decoded.time = (long) (((double) frame.readLong()) / FACTOR_HR); break; case PLUGIN: decoded.plugin = parseString(frame, size); break; case PLUGIN_INSTANCE: decoded.pluginInstance = parseString(frame, size); break; case TYPE: decoded.type = parseString(frame, size); break; case TYPE_INSTANCE: decoded.typeInstance = parseString(frame, size); break; case INTERVAL: decoded.interval = frame.readLong(); break; case INTERVAL_HR: decoded.interval = (long) (((double) frame.readLong()) / FACTOR_HR); break; case MESSAGE: decoded.message = parseString(frame, size); break; case SEVERITY: decoded.severity = frame.readLong(); break; case VALUES: return decoded.toSample(parseValues(frame, size)); default: log.warn("unhandled type: " + type); break; } } } }; }
From source file:com.spotify.heroic.consumer.collectd.CollectdParser.java
License:Apache License
public static List<CollectdValue> parseValues(final ByteBuf frame, final int size) { final int n = frame.readUnsignedShort(); final List<Integer> types = ImmutableList.copyOf(IntStream.range(0, n).map(i -> { return frame.readByte(); }).iterator());//from w w w. j a v a 2 s.c om final ImmutableList.Builder<CollectdValue> values = ImmutableList.builder(); for (final int type : types) { switch (type) { case CollectdSample.COUNTER: final long c = frame.readLong(); if (c < 0) { throw new IllegalArgumentException("value too large for signed type"); } values.add(new Counter(c)); break; case CollectdSample.GAUGE: frame.order(ByteOrder.LITTLE_ENDIAN); values.add(new CollectdValue.Gauge(frame.readDouble())); frame.order(ByteOrder.BIG_ENDIAN); break; case CollectdSample.DERIVE: values.add(new CollectdValue.Derive(frame.readLong())); break; case CollectdSample.ABSOLUTE: final long a = frame.readLong(); if (a < 0) { throw new IllegalArgumentException("value too large for signed type"); } values.add(new CollectdValue.Absolute(a)); break; default: throw new IllegalArgumentException("invalid sample type: " + type); } } return values.build(); }
From source file:com.spotify.netty.handler.codec.zmtp.ZMTPUtilsTests.java
License:Apache License
@Test public void testWriteLongBE() { ByteBuf cb = Unpooled.buffer(8); cb.order(ByteOrder.BIG_ENDIAN); ZMTPUtils.writeLong(cb, 1);//from ww w . j a va2s. c o m cmp(cb, 0, 0, 0, 0, 0, 0, 0, 1); }
From source file:com.spotify.netty.handler.codec.zmtp.ZMTPUtilsTests.java
License:Apache License
@Test public void testWriteLongLE() { ByteBuf cb = Unpooled.buffer(8); cb.order(ByteOrder.LITTLE_ENDIAN); ZMTPUtils.writeLong(cb, 1);//from w w w. j a v a2 s . co m cmp(cb, 0, 0, 0, 0, 0, 0, 0, 1); }