Example usage for io.netty.buffer ByteBuf readShort

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

Introduction

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

Prototype

public abstract short readShort();

Source Link

Document

Gets a 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:matteroverdrive.api.weapon.WeaponShot.java

License:Open Source License

public WeaponShot(ByteBuf buf) {
    this(buf.readInt(), buf.readFloat(), buf.readFloat(), buf.readInt(), buf.readShort());
    setCount(buf.readByte());
}

From source file:matteroverdrive.network.packet.server.PacketMatterScannerUpdate.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    this.selected = new ItemPattern(buf);
    this.page = buf.readShort();
    //this.panelOpen = buffer.readBoolean();
    this.slot = buf.readShort();
}

From source file:me.ferrybig.p2pnetwork.codec.packets.PeerExchangePacket.java

public PeerExchangePacket(ByteBuf buf) {
    addresses = new LinkedHashMap<>();
    int size = buf.readByte();
    for (int i = 0; i < size; i++) {
        try {//from  w ww. j a  va 2  s.co m
            byte aType = buf.readByte();
            switch (aType) {
            case 1: {
                int addrLength = buf.readByte();
                byte[] addr = new byte[addrLength];
                buf.readBytes(addr);
                addresses.put(new InetSocketAddress(InetAddress.getByAddress(addr), buf.readShort()),
                        buf.readByte());
            }
                break;
            }
        } catch (UnknownHostException ex) {
            LOG.log(Level.WARNING, "Peer exchange packet contained invalid ip address", ex);
        }
    }
}

From source file:me.ferrybig.p2pnetwork.codec.packets.PingPacket.java

public PingPacket(ByteBuf buf) {
    data = new byte[buf.readShort()];
    buf.readBytes(data);
}

From source file:me.ferrybig.p2pnetwork.codec.packets.PongPacket.java

public PongPacket(ByteBuf buf) {
    data = new byte[buf.readShort()];
    buf.readBytes(data);
}

From source file:mysql.client.Session_Old.java

public void doHandshake() throws Exception {

    ByteBuf buf = readPacket();
    byte protocolVersion = buf.readByte();
    String serverVersion = readString(buf, "ASCII");
    System.out.println("protocolVersion = " + protocolVersion);
    System.out.println("serverVersion = " + serverVersion);

    long threadId = buf.readUnsignedInt();
    System.out.println("threadId = " + threadId);
    String seed;/*from w  ww.j  av a  2s  .co  m*/
    if (protocolVersion > 9) {//fuck ?mysql jdbc ?,,?mysql internal manualV10
        // read auth-plugin-data-part-1 (string[8])
        seed = readString(buf, "ASCII", 8);//????,ssl??
        // read filler ([00])
        buf.readByte();
        System.out.println("seed=" + seed);
    } else {
        // read scramble (string[NUL])
        seed = readString(buf, "ASCII");//v9 handshake?,?
    }

    //v10 ???

    int serverCapabilities = 0;
    // read capability flags (lower 2 bytes)
    if (buf.readerIndex() < buf.capacity()) {
        serverCapabilities = buf.readShort();
    }

    //??,???,??,????,?,?
    //?,???????,??

    //???,?debug,??
    int serverCharsetIndex = buf.readByte();
    int serverStatus = buf.readShort();
    serverCapabilities |= buf.readShort() << 16;//??,??

    int clientParam = 3842703;//??serverCapabilitiesconnection?
    //        clientParam |= 0x00200000;
    clientParam &= ~0x00100000; // ignore connection attributes
    //        if capabilities & CLIENT_PLUGIN_AUTH {
    //            1              length of auth-plugin-data
    //        } else {
    //            1              [00]
    //        }
    int authPluginDataLength = buf.readByte();//length of auth-plugin-data

    // next 10 bytes are reserved (all [00])
    //        buf.setPosition(buf.getPosition() + 10);
    buf.readerIndex(buf.readerIndex() + 10);//10??
    String seed2 = readString(buf, "ASCII", authPluginDataLength - 8);
    seed += seed2;
    System.out.println("seed =" + seed);

    //        if ((this.serverCapabilities & CLIENT_PLUGIN_AUTH) != 0) {
    //            proceedHandshakeWithPluggableAuthentication(user, password, database, buf);
    //            return;
    //        }
    //?????,filter-chain??
    //?MysqlOldPasswordPlugin,MysqlNativePasswordPlugin,MysqlClearPasswordPlugin...

    boolean skipPassword = false;
    int passwordLength = 16;
    int userLength = (user != null) ? user.length() : 0;
    int databaseLength = (database != null) ? database.length() : 0;

    int packLength = ((userLength + passwordLength + databaseLength) * 3) + 7 + 4 + 33;

    String pluginName = readString(buf, "ASCII");
    //initial handshake packet ?,??Handshake response packet

    ByteBuf fromServer = buf.alloc().buffer(seed.getBytes().length).writeBytes(seed.getBytes());

    byte[] bytes = Security.scramble411(password, seed, "utf-8");
    ByteBuf authBuf = buf.alloc().buffer(bytes.length).writeBytes(bytes);
    // write Auth Response Packet
    String enc = "utf-8";
    ByteBuf sendBuf = createSendByteBuf(packLength);
    sendBuf = sendBuf.order(ByteOrder.LITTLE_ENDIAN);
    //        last_sent.writeLong(this.clientParam);
    //        last_sent.writeLong(this.maxThreeBytes);
    //0x00100000

    //        "_runtime_version" -> "1.8.0_65"
    //        "_client_version" -> "5.1.38"
    //        "_client_name" -> "MySQL Connector Java"
    //        "_client_license" -> "GPL"
    //        "_runtime_vendor" -> "Oracle Corporation"
    sendBuf.writeInt(clientParam);
    sendBuf.writeInt(16777215);//writeLong(this.maxThreeBytes);
    sendBuf.writeByte(33);//CharsetMapping.MYSQL_COLLATION_INDEX_utf8;
    sendBuf.writeBytes(new byte[23]);

    //user  string<null>
    sendBuf.writeBytes(user.getBytes());
    sendBuf.writeByte(0);

    //wite toserver length
    sendBuf.writeByte(0);

    //write database
    sendBuf.writeBytes(database.getBytes());
    sendBuf.writeByte(0);

    sendBuf.writeBytes("mysql_native_password".getBytes());
    sendBuf.writeByte(0);

    //propertie
    ByteBuf propertieBuf = allocator.heapBuffer(100);
    Properties properties = new Properties();
    properties.setProperty("_runtime_version", "1.8.0_65");
    properties.setProperty("_client_version", "5.1.38");
    properties.setProperty("_client_name", "MySQL Connector Java");
    properties.setProperty("_client_license", "GPL");
    properties.setProperty("_runtime_vendor", "Oracle Corporation");
    Buffer lb = new Buffer(100);
    for (Object p : properties.keySet()) {
        lb.writeLenString((String) p);
        lb.writeLenString(properties.getProperty((String) p));
        //mysql buffer , ?int ,,?251,?65536
    }

    //        sendBuf.writeByte((byte) (lb.getPosition() - 4));
    //        sendBuf.writeBytes(lb.getByteBuffer(), 4, lb.getBufLength() - 4);

    send(sendBuf);
    //      sendBuf.writeBytes(authBuf); //?,fromServertoServer

    //jdbc driver????,,sql

}

From source file:net.hasor.rsf.protocol.rsf.v1.PoolBlock.java

License:Apache License

public void fillFrom(ByteBuf formData) {
    if (formData == null) {
        return;/*w  w  w.j  av a 2s.  c o  m*/
    }
    //
    short attrPoolSize = (short) (PoolMaxSize & formData.readShort());
    for (int i = 0; i < attrPoolSize; i++) {
        int length = formData.readInt();
        this.poolMap = ArrayUtils.add(this.poolMap, length);
    }
    this.poolData.writeBytes(formData);
}

From source file:net.hasor.rsf.protocol.rsf.v1.RpcRequestProtocolV1.java

License:Apache License

/**decode stream to object*/
public RequestBlock decode(ByteBuf buf) throws IOException {
    //* --------------------------------------------------------bytes =13
    //* byte[1]  version                              RSF(0xC1)
    byte rsfHead = buf.readByte();
    //* byte[8]  requestID                            ?ID
    long requestID = buf.readLong();
    //* byte[1]  keepData                             ?
    buf.skipBytes(1);/*from  w w  w .j  a  v  a2s .co m*/
    //* byte[3]  contentLength                        ?
    buf.skipBytes(3);//.readUnsignedMedium()
    //
    RequestBlock req = new RequestBlock();
    req.setHead(rsfHead);
    req.setRequestID(requestID);
    //* --------------------------------------------------------bytes =14
    //* byte[2]  servicesName-(attr-index)            ???
    req.setServiceName(buf.readShort());
    //* byte[2]  servicesGroup-(attr-index)           ?
    req.setServiceGroup(buf.readShort());
    //* byte[2]  servicesVersion-(attr-index)         ?
    req.setServiceVersion(buf.readShort());
    //* byte[2]  servicesMethod-(attr-index)          ???
    req.setTargetMethod(buf.readShort());
    //* byte[2]  serializeType-(attr-index)           ?
    req.setSerializeType(buf.readShort());
    //* byte[4]  clientTimeout                        
    req.setClientTimeout(buf.readInt());
    //* --------------------------------------------------------bytes =1 ~ 1021
    //* byte[1]  paramCount                           ?
    byte paramCount = buf.readByte();
    for (int i = 0; i < paramCount; i++) {
        //* byte[4]  ptype-0-(attr-index,attr-index)  ?
        int mergeData = buf.readInt();
        req.addParameter(mergeData);
    }
    //* --------------------------------------------------------bytes =1 ~ 1021
    //* byte[1]  optionCount                          ?
    byte optionCount = buf.readByte();
    for (int i = 0; i < optionCount; i++) {
        //* byte[4]  attr-0-(attr-index,attr-index)   ?
        int mergeData = buf.readInt();
        req.addOption(mergeData);
    }
    //* --------------------------------------------------------bytes =n
    //* dataBody                                      ?
    req.fillFrom(buf);
    return req;
}

From source file:net.hasor.rsf.protocol.rsf.v1.RpcResponseProtocolV1.java

License:Apache License

/**decode stream to object*/
public ResponseBlock decode(ByteBuf buf) throws IOException {
    //* --------------------------------------------------------bytes =13
    //* byte[1]  version                              RSF
    byte version = buf.readByte();
    //* byte[8]  requestID                            ?ID
    long requestID = buf.readLong();
    //* byte[1]  keepData                             ?
    buf.skipBytes(1);//from  w  ww  .  j a  va  2 s . c o m
    //* byte[3]  contentLength                        ?
    buf.skipBytes(3);//.readUnsignedMedium()
    //
    ResponseBlock res = new ResponseBlock();
    res.setHead(version);
    res.setRequestID(requestID);
    //* --------------------------------------------------------bytes =8
    //* byte[2]  status                               ??
    res.setStatus(buf.readShort());
    //* byte[2]  serializeType-(attr-index)           ?
    res.setSerializeType(buf.readShort());
    //* byte[2]  returnData-(attr-index)              ?
    res.setReturnData(buf.readShort());
    //* --------------------------------------------------------bytes =1 ~ 1021
    //* byte[1]  optionCount                          ?
    byte optionCount = buf.readByte();
    for (int i = 0; i < optionCount; i++) {
        //* byte[4]  attr-0-(attr-index,attr-index)   ?
        int mergeData = buf.readInt();
        res.addOption(mergeData);
    }
    //* --------------------------------------------------------bytes =n
    //* dataBody                                      ?
    res.fillFrom(buf);
    return res;
}

From source file:net.hasor.rsf.remoting.transport.protocol.codec.RpcRequestProtocol.java

License:Apache License

/**decode stream to object*/
public RequestSocketBlock decode(ByteBuf buf) throws IOException {
    //* --------------------------------------------------------bytes =13
    //* byte[1]  version                              RSF(0xC1)
    byte version = buf.readByte();
    //* byte[8]  requestID                            ?ID
    long requestID = buf.readLong();
    //* byte[1]  keepData                             ?
    buf.skipBytes(1);/* w w w  .  j  av  a  2s  .c  o  m*/
    //* byte[3]  contentLength                        ?
    buf.skipBytes(3);//.readUnsignedMedium()
    //
    RequestSocketBlock req = new RequestSocketBlock();
    req.setVersion(version);
    req.setRequestID(requestID);
    //* --------------------------------------------------------bytes =14
    //* byte[2]  servicesName-(attr-index)            ???
    req.setServiceName(buf.readShort());
    //* byte[2]  servicesGroup-(attr-index)           ?
    req.setServiceGroup(buf.readShort());
    //* byte[2]  servicesVersion-(attr-index)         ?
    req.setServiceVersion(buf.readShort());
    //* byte[2]  servicesMethod-(attr-index)          ???
    req.setTargetMethod(buf.readShort());
    //* byte[2]  serializeType-(attr-index)           ?
    req.setSerializeType(buf.readShort());
    //* byte[4]  clientTimeout                        
    req.setClientTimeout(buf.readInt());
    //* --------------------------------------------------------bytes =1 ~ 1021
    //* byte[1]  paramCount                           ?
    byte paramCount = buf.readByte();
    for (int i = 0; i < paramCount; i++) {
        //* byte[4]  ptype-0-(attr-index,attr-index)  ?
        int mergeData = buf.readInt();
        req.addParameter(mergeData);
    }
    //* --------------------------------------------------------bytes =1 ~ 1021
    //* byte[1]  optionCount                          ?
    byte optionCount = buf.readByte();
    for (int i = 0; i < optionCount; i++) {
        //* byte[4]  attr-0-(attr-index,attr-index)   ?
        int mergeData = buf.readInt();
        req.addOption(mergeData);
    }
    //* --------------------------------------------------------bytes =6 ~ 8192
    //* byte[2]  attrPool-size (Max = 2047)           ?
    short attrPoolSize = buf.readShort();
    for (int i = 0; i < attrPoolSize; i++) {
        //* byte[4] att-length                        1?
        int length = buf.readInt();
        req.addPoolData(length);
    }
    //* --------------------------------------------------------bytes =n
    //* dataBody                                      ?
    req.fillFrom(buf.readBytes(req.getPoolSize()));
    return req;
}