Example usage for io.netty.buffer ByteBuf readLong

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

Introduction

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

Prototype

public abstract long readLong();

Source Link

Document

Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.

Usage

From source file:org.virtue.network.protocol.social.SocialNetworkDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
    int size = buf.readShort() & 0xFFFF;

    if (buf.readableBytes() < size)
        throw new IllegalStateException("Not enough readable bytes from buffer!");

    int version = buf.readInt();
    int subVersion = buf.readInt();

    if (version != Constants.FRAME_MAJOR && subVersion != Constants.FRAME_MINOR)
        throw new IllegalStateException("Invalid client version/sub-version!");

    //if (type.equals(LoginTypeMessage.LOGIN_WORLD))
    //buf.readByte();//TODO if its world login, client does send this byte. however social doesnt send the login type

    int secureBufferSize = buf.readShort() & 0xFFFF;
    if (buf.readableBytes() < secureBufferSize)
        throw new IllegalStateException("Not enough readable bytes from buffer.");

    byte[] secureBytes = new byte[secureBufferSize];
    buf.readBytes(secureBytes);/* ww w .ja  v a  2 s  .c o m*/
    ByteBuf secureBuffer = Unpooled.wrappedBuffer(new BigInteger(secureBytes)
            .modPow(Constants.getLoginKey(), Constants.getLoginModulus()).toByteArray());

    secureBuffer.readByte();
    secureBuffer.skipBytes(4);
    secureBuffer.readByte();
    secureBuffer.readByte();//int langID = 
    secureBuffer.readInt();
    int[] random = new int[5];
    for (int index = 0; index < random.length; index++) {
        random[index] = secureBuffer.readInt();
    }
    secureBuffer.readLong();
    secureBuffer.readByte();
    secureBuffer.readByte();
    ctx.channel().writeAndFlush(Unpooled.buffer().writeByte(0).writeByte(1).writeByte(2));
}

From source file:org.wso2.carbon.tcp.transport.util.SiddhiEventConverter.java

License:Open Source License

public Object[] toObjectArray(ByteBuf byteBuffer, Attribute.Type[] attributeTypeOrder) {
    if (attributeTypeOrder != null) {
        if (byteBuffer == null) {
            throw new MalformedEventException("Received byte stream in null. Hence cannot convert to event");
        }/*from  w w w . ja  va 2 s .com*/
        Object[] objects = new Object[attributeTypeOrder.length];
        for (int i = 0; i < attributeTypeOrder.length; i++) {
            switch (attributeTypeOrder[i]) {
            case INT:
                objects[i] = byteBuffer.readInt();
                break;
            case LONG:
                objects[i] = byteBuffer.readLong();
                break;
            case STRING:
                int stringSize = byteBuffer.readInt();
                if (stringSize == 0) {
                    objects[i] = null;
                } else {
                    objects[i] = BinaryMessageConverterUtil.getString(byteBuffer, stringSize);
                }
                break;
            case DOUBLE:
                objects[i] = byteBuffer.readDouble();
                break;
            case FLOAT:
                objects[i] = byteBuffer.readFloat();
                break;
            case BOOL:
                objects[i] = byteBuffer.readByte() == 1;
                break;
            }
        }
        return objects;
    } else {
        return null;
    }
}

From source file:qunar.tc.qmq.delay.receiver.ReceivedDelayMessageProcessor.java

License:Apache License

private RawMessageExtend doDeserializeRawMessagesExtend(ByteBuf body) {
    body.markReaderIndex();// w ww  . j a va 2  s.  c om
    int headerStart = body.readerIndex();
    long bodyCrc = body.readLong();
    MessageHeader header = deserializeMessageHeader(body);
    header.setBodyCrc(bodyCrc);
    int bodyLen = body.readInt();
    int headerLen = body.readerIndex() - headerStart;
    int totalLen = headerLen + bodyLen;

    body.resetReaderIndex();
    ByteBuf messageBuf = body.readSlice(totalLen);
    // client config error,prefer to send after ten second
    long scheduleTime = System.currentTimeMillis() + 10000;
    if (Flags.isDelay(header.getFlag())) {
        scheduleTime = header.getExpireTime();
    }

    return new RawMessageExtend(header, messageBuf, messageBuf.readableBytes(), scheduleTime);
}

From source file:qunar.tc.qmq.delay.sync.master.DelaySyncRequestProcessor.java

License:Apache License

private DelaySyncRequest deserializeSyncRequest(RemotingCommand request) {
    ByteBuf body = request.getBody();
    int logType = body.readByte();
    long messageLogOffset = body.readLong();
    int dispatchLogSegmentBaseOffset = body.readInt();
    long dispatchLogOffset = body.readLong();
    int lastDispatchLogBaseOffset = body.readInt();
    long lastDispatchLogOffset = body.readLong();
    return new DelaySyncRequest(messageLogOffset, dispatchLogSegmentBaseOffset, dispatchLogOffset,
            lastDispatchLogBaseOffset, lastDispatchLogOffset, logType);
}

From source file:qunar.tc.qmq.delay.sync.slave.DispatchLogSyncProcessor.java

License:Apache License

@Override
public void process(Datagram syncData) {
    ByteBuf body = syncData.getBody();
    int size = body.readInt();
    if (size == 0) {
        LOGGER.debug("sync dispatch log data empty");
        return;/*  w  w  w  .  j  ava 2 s .co  m*/
    }

    long startOffset = body.readLong();
    long baseOffset = body.readLong();
    appendLogs(startOffset, baseOffset, body);
}

From source file:qunar.tc.qmq.delay.sync.slave.MessageLogSyncProcessor.java

License:Apache License

@Override
public void process(Datagram syncData) {
    final ByteBuf body = syncData.getBody();
    final int size = body.readInt();
    if (size == 0) {
        LOGGER.debug("sync message log data empty");
        return;/*ww  w  .  j  a  v a2s.co m*/
    }
    final long startOffset = body.readLong();
    appendLogs(startOffset, body);
}

From source file:qunar.tc.qmq.metainfoclient.MetaInfoClientHandler.java

License:Apache License

private static MetaInfoResponse deserializeMetaInfoResponse(ByteBuf buf) {
    try {/*  w w w  .  ja  va 2  s.  c o m*/
        final MetaInfoResponse metaInfoResponse = new MetaInfoResponse();
        metaInfoResponse.setTimestamp(buf.readLong());
        metaInfoResponse.setSubject(PayloadHolderUtils.readString(buf));
        metaInfoResponse.setConsumerGroup(PayloadHolderUtils.readString(buf));
        metaInfoResponse.setOnOfflineState(OnOfflineState.fromCode(buf.readByte()));
        metaInfoResponse.setClientTypeCode(buf.readByte());
        metaInfoResponse.setBrokerCluster(deserializeBrokerCluster(buf));
        return metaInfoResponse;
    } catch (Exception e) {
        LOG.error("deserializeMetaInfoResponse exception", e);
    }
    return null;
}

From source file:qunar.tc.qmq.metainfoclient.MetaInfoClientHandler.java

License:Apache License

private static BrokerCluster deserializeBrokerCluster(ByteBuf buf) {
    final int brokerGroupSize = buf.readShort();
    final List<BrokerGroup> brokerGroups = new ArrayList<>(brokerGroupSize);
    for (int i = 0; i < brokerGroupSize; i++) {
        final BrokerGroup brokerGroup = new BrokerGroup();
        brokerGroup.setGroupName(PayloadHolderUtils.readString(buf));
        brokerGroup.setMaster(PayloadHolderUtils.readString(buf));
        brokerGroup.setUpdateTime(buf.readLong());
        final int brokerStateCode = buf.readByte();
        final BrokerState brokerState = BrokerState.codeOf(brokerStateCode);
        brokerGroup.setBrokerState(brokerState);
        brokerGroups.add(brokerGroup);//w  w  w.j av  a 2  s.  c  o  m
    }
    return new BrokerCluster(brokerGroups);
}

From source file:qunar.tc.qmq.processor.AckMessageProcessor.java

License:Apache License

private AckRequest deserializeAckRequest(RemotingCommand command) {
    ByteBuf input = command.getBody();
    AckRequest request = new AckRequest();
    request.setSubject(PayloadHolderUtils.readString(input));
    request.setGroup(PayloadHolderUtils.readString(input));
    request.setConsumerId(PayloadHolderUtils.readString(input));
    request.setPullOffsetBegin(input.readLong());
    request.setPullOffsetLast(input.readLong());
    if (command.getHeader().getVersion() >= RemotingHeader.VERSION_8) {
        request.setBroadcast(input.readByte());
    }/*from ww  w. j a va 2  s.c om*/
    return request;
}

From source file:qunar.tc.qmq.processor.SendMessageProcessor.java

License:Apache License

private RawMessage deserializeRawMessageWithCrc(ByteBuf body) {
    long bodyCrc = body.readLong();

    int headerStart = body.readerIndex();
    body.markReaderIndex();/*from   w w w.ja  va 2s .c  o m*/
    MessageHeader header = deserializeMessageHeader(body);
    header.setBodyCrc(bodyCrc);
    int bodyLen = body.readInt();
    int headerLen = body.readerIndex() - headerStart;

    int totalLen = headerLen + bodyLen;
    body.resetReaderIndex();
    ByteBuf messageBuf = body.readSlice(totalLen);
    return new RawMessage(header, messageBuf, totalLen);
}