Example usage for io.netty.buffer ByteBuf getLong

List of usage examples for io.netty.buffer ByteBuf getLong

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf getLong.

Prototype

public abstract long getLong(int index);

Source Link

Document

Gets a 64-bit long integer at the specified absolute index in this buffer.

Usage

From source file:com.neoba.MessageInterpreter.java

MessageInterpreter(ChannelHandlerContext ctx, ByteBuf buff) {

    VERSION = buff.getByte(0);// w w  w.  j  ava  2s  .  co  m
    type = buff.getByte(1);
    size = buff.getInt(2);
    if (type != Constants.PINGPONG && type != Constants.USER_CREATE && type != Constants.USER_LOGIN
            && type != Constants.FACEBOOK_USER_CREATE && type != Constants.FACEBOOK_USER_LOGIN) {
        sessid = new UUID(buff.getLong(14), buff.getLong(6));
        if (isloggedin()) {
            logger.info("Authenticated message from user " + Dsyncserver.usersessions.get(sessid)
                    + " with session " + sessid);
        }
    } else {
        sessid = null;
    }
    this.buff = buff;
    this.ctx = ctx;
}

From source file:com.netty.test.LengthFieldBasedExFrameDecoder.java

License:Apache License

private long getFrameLength(ByteBuf in, int actualLengthFieldOffset) {
    in = in.order(byteOrder);//from www  .j a  v a2  s  .  c o m
    long frameLength;
    switch (lengthFieldLength) {
    case 1:
        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.streamsets.pipeline.lib.parser.collectd.CollectdParser.java

License:Apache License

private long parseNumeric(int offset, ByteBuf buf) {
    // 8 bytes
    return buf.getLong(offset);
}

From source file:com.streamsets.pipeline.lib.parser.collectd.CollectdParser.java

License:Apache License

/**
 * Parses the value part of the packet where metrics are located
 *
 * @param startOffset beginning offset for this part
 * @param buf         buffered packet//  w  w  w.  jav a  2 s  .c  o m
 * @return offset after consuming part
 */
private int parseValues(int startOffset, ByteBuf buf) throws OnRecordErrorException {
    int offset = startOffset;
    // N Values
    // For each Value:
    // 1 byte data type code
    int numValues = buf.getUnsignedShort(offset); // 4-5
    offset += 2;

    List<Byte> types = new ArrayList<>(numValues);

    while (numValues-- > 0) {
        types.add(buf.getByte(offset));
        offset += 1;
    }

    for (int i = 0; i < types.size(); i++) {
        Byte type = types.get(i);
        String label = getValueLabel(i, type);
        switch (type) {
        case COUNTER:
            fields.put(label, Field.create(buf.getUnsignedInt(offset)));
            offset += 8;
            break;
        case GAUGE:
            fields.put(label, Field.create(buf.order(ByteOrder.LITTLE_ENDIAN).getDouble(offset)));
            offset += 8;
            break;
        case DERIVE:
            fields.put(label, Field.create(buf.getLong(offset)));
            offset += 8;
            break;
        case ABSOLUTE:
            fields.put(label, Field.create(buf.getUnsignedInt(offset)));
            offset += 8;
            break;
        default:
            // error
            throw new OnRecordErrorException(Errors.COLLECTD_01, type);
        }
    }
    return offset;
}

From source file:herddb.proto.PduCodec.java

License:Apache License

public static Pdu decodePdu(ByteBuf in) throws IOException {
    byte version = in.getByte(0);
    if (version == VERSION_3) {
        byte flags = in.getByte(1);
        byte type = in.getByte(2);
        long messageId = in.getLong(3);
        return Pdu.newPdu(in, type, flags, messageId);
    }//from   w  ww.ja va 2s.c o  m
    throw new IOException("Cannot decode version " + version);
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static Long binaryDecodeINT8(int index, int len, ByteBuf buff) {
    return buff.getLong(index);
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static LocalTime binaryDecodeTIME(int index, int len, ByteBuf buff) {
    // micros to nanos
    return LocalTime.ofNanoOfDay(buff.getLong(index) * 1000);
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static OffsetTime binaryDecodeTIMETZ(int index, int len, ByteBuf buff) {
    // micros to nanos
    return OffsetTime.of(LocalTime.ofNanoOfDay(buff.getLong(index) * 1000),
            // zone offset in seconds (should we change it to UTC ?)
            ZoneOffset.ofTotalSeconds(-buff.getInt(index + 8)));
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static LocalDateTime binaryDecodeTIMESTAMP(int index, int len, ByteBuf buff) {
    return LOCAL_DATE_TIME_EPOCH.plus(buff.getLong(index), ChronoUnit.MICROS);
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

private static OffsetDateTime binaryDecodeTIMESTAMPTZ(int index, int len, ByteBuf buff) {
    return OFFSET_DATE_TIME_EPOCH.plus(buff.getLong(index), ChronoUnit.MICROS);
}