List of usage examples for io.netty.buffer ByteBuf readBytes
public abstract ByteBuf readBytes(ByteBuffer dst);
From source file:com.almuradev.almurasdk.server.network.play.S00PacketPermissions.java
License:MIT License
@Override public void fromBytes(ByteBuf buf) { container = ReplicatedPermissionsContainer.fromBytes(buf.readBytes(buf.readableBytes()).array()); }
From source file:com.antsdb.saltedfish.server.mysql.packet.AuthPacket.java
License:Open Source License
@Override public void read(MysqlServerHandler handler, ByteBuf in) { if (!checkResponseVer41(in)) { clientParam = BufferUtils.readInt(in); maxThreeBytes = BufferUtils.readLongInt(in); user = BufferUtils.readString(in); rawPwd = BufferUtils.readString(in); dbname = BufferUtils.readString(in); } else {//from ww w . ja va2s.c om clientParam = BufferUtils.readLong(in); maxThreeBytes = BufferUtils.readLong(in); in.readByte(); // charset in.skipBytes(23); // reserved for future user = BufferUtils.readString(in); if ((clientParam & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA) != 0) { int passwordLength = in.readByte(); byte[] bytes = new byte[passwordLength]; in.readBytes(bytes); rawPwd = new String(bytes, Charsets.ISO_8859_1); } else { if ((clientParam & CLIENT_SECURE_CONNECTION) != 0) { int passwordLength = in.readByte(); byte[] bytes = new byte[passwordLength]; in.readBytes(bytes); rawPwd = new String(bytes, Charsets.ISO_8859_1); } else { rawPwd = BufferUtils.readString(in); } } if ((clientParam & MysqlServerHandler.CLIENT_CONNECT_WITH_DB) != 0) { dbname = BufferUtils.readString(in); } if ((clientParam & MysqlServerHandler.CLIENT_PLUGIN_AUTH) != 0) { BufferUtils.readString(in); } } }
From source file:com.antsdb.saltedfish.server.mysql.packet.replication.GenericPacket.java
License:Open Source License
@Override public void read(MysqlClientHandler handler, ByteBuf in) { // ignore packet info if (_log.isTraceEnabled()) { // event length - header length is body size byte[] bytes = new byte[(int) eventlength - 19]; in.readBytes(bytes); String dump = '\n' + UberUtil.hexDump(bytes); _log.trace(dump);/*from w ww . java2 s. c o m*/ } }
From source file:com.antsdb.saltedfish.server.mysql.packet.replication.HandshakeInitPacket.java
License:Open Source License
@Override public void read(MysqlClientHandler handler, ByteBuf in) { // ignore handshake info, assure master is mysql 5.6 in.readBytes(in.readableBytes()); }
From source file:com.antsdb.saltedfish.server.mysql.packet.replication.RowsEventV2Packet.java
License:Open Source License
@Override public void read(MysqlClientHandler handler, ByteBuf in) { // header//from www .j a v a2 s . c o m int begin = in.readerIndex(); // 6 bytes tabble id tableId = BufferUtils.readPackedInteger(in, 6); // 2 bytes flags flags = BufferUtils.readInt(in); extraDataLen = BufferUtils.readInt(in); // body // number of columns int index = in.readerIndex(); colCount = (int) BufferUtils.readLength(in); int presentCount = (colCount + 7) / 8; byte[] presentBits = new byte[presentCount]; in.readBytes(presentBits); colPresentBitmap = BitSet.valueOf(presentBits); if (eventType == ReplicationPacket.UPDATE_ROWS_EVENT) { byte[] presentUptBits = new byte[presentCount]; in.readBytes(presentUptBits); colPresentBitmapAftImg = BitSet.valueOf(presentUptBits); } int readCnt = in.readerIndex() - index; // eventlength - event_header_length - post_header_length - rest data length rawRows = in.readBytes((int) eventlength - 29 - readCnt); int end = in.readerIndex(); if (_log.isTraceEnabled()) { in.readerIndex(begin); byte[] bytes = new byte[end - begin]; in.readBytes(bytes); String dump = '\n' + UberUtil.hexDump(bytes); _log.trace("Packet Info:\n" + this.toString() + "\nRowsEventV2Packet packet:\n" + dump); } }
From source file:com.antsdb.saltedfish.server.mysql.packet.replication.StateIndicator.java
License:Open Source License
@Override public void read(MysqlClientHandler handler, ByteBuf in) { // ignore packet info, assure master is mysql 5.6 if (_log.isTraceEnabled()) { ByteBuf packet = (ByteBuf) in; ByteBuffer bbuf = packet.nioBuffer(); int i = bbuf.remaining(); byte[] bytes = new byte[i]; packet.readBytes(bytes); String dump = '\n' + UberUtil.hexDump(bytes); _log.trace(dump);// w ww . j ava2 s .c om } }
From source file:com.antsdb.saltedfish.server.mysql.packet.replication.TableMapPacket.java
License:Open Source License
@Override public void read(MysqlClientHandler handler, ByteBuf in) { // header/*from w w w. j av a 2s . c o m*/ int begin = in.readerIndex(); tableId = BufferUtils.readPackedInteger(in, 6); flags = BufferUtils.readInt(in); // payload schemaName = BufferUtils.readStringWithLength(in); // seperated by 0 in.readByte(); tableName = BufferUtils.readStringWithLength(in); // seperated by 0 in.readByte(); colCount = (int) BufferUtils.readLength(in); colTypeDef = BufferUtils.readBytes(in, colCount); metaCount = (int) BufferUtils.readLength(in); colMetaDef = BufferUtils.readBytes(in, metaCount); int nullCount = (colCount + 7) / 8; nullBitMap = new byte[nullCount]; in.readBytes(nullBitMap); int end = in.readerIndex(); if (_log.isTraceEnabled()) { in.readerIndex(begin); byte[] bytes = new byte[end - begin]; in.readBytes(bytes); String dump = '\n' + UberUtil.hexDump(bytes); _log.trace("Packet Info:\n" + this.toString() + "\nTableMapPacket packet:\n" + dump); } }
From source file:com.antsdb.saltedfish.server.mysql.packet.StmtExecutePacket.java
License:Open Source License
@SuppressWarnings("unused") public void read__(MysqlServerHandler handler) { ByteBuf in = this.content; statementId = (int) BufferUtils.readUB4(in); byte flags = BufferUtils.readByte(in); long iterationCount = BufferUtils.readUB4(in); this.pstmt = handler.getPrepared().get(statementId); if (pstmt == null) { throw new OrcaException("prepared statement {} is not found", statementId); }//from w w w . j a v a 2 s . co m // read null bitmap int nullCount = (pstmt.getParameterCount() + 7) / 8; byte[] bytes = new byte[nullCount]; in.readBytes(bytes); BitSet nullBits = BitSet.valueOf(bytes); // type information int sentTypes = in.readByte(); if (sentTypes != 0) { int[] types = new int[pstmt.getParameterCount()]; for (int i = 0; i < pstmt.getParameterCount(); i++) { types[i] = BufferUtils.readInt(in); } pstmt.types = types; } // bind values if (pstmt.types == null) { // type information is supposed to be sent in the first execution. } Heap heap = pstmt.getHeap(); for (int i = 0; i < pstmt.getParameterCount(); i++) { if (nullBits.get(i)) { continue; } if (pstmt.types[i] == Fields.FIELD_TYPE_BLOB) { // BLOB values should be set with long data packet // and already in pstmt. use isSet to indicate using // long data packet in PreparedStmtHandler in execution continue; } long pValue = BindValueUtil.read(heap, in, pstmt.types[i]); pstmt.setParam(i, pValue); } }
From source file:com.antsdb.saltedfish.server.mysql.PacketEncoder.java
License:Open Source License
/** * Add header to finish the full packet/* w w w .j av a 2 s.c o m*/ * @param out * @param packetSeq * @param writeBodyFunc write packet body function */ public static void writePacket(ByteBuf out, byte packetSeq, Callback writeBodyFunc) { int start = out.writerIndex(); out.writeZero(4); writeBodyFunc.callback(); int end = out.writerIndex(); out.writeByte(0); out.writerIndex(start); int length = end - start - MySQLPacket.packetHeaderSize; BufferUtils.writeLongInt(out, length); out.writeByte(packetSeq); out.writerIndex(end); if (_log.isTraceEnabled()) { int readerIndex = out.readerIndex(); out.readerIndex(start); byte[] bytes = new byte[end - start]; out.readBytes(bytes); out.readerIndex(readerIndex); String dump = '\n' + UberUtil.hexDump(bytes); _log.trace(dump); } }
From source file:com.antsdb.saltedfish.server.mysql.ReplicationPacketDecoder.java
License:Open Source License
@SuppressWarnings("unused") private ReplicationPacket readPacket(ByteBuf in, int size) { // packet sequence number for multiple packets // byte packetSequence = in.readByte(); byte seqId = in.readByte(); // handshake//w w w . j av a 2 s . c o m ReplicationPacket packet = null; // using state to decide how to handle connecting messages. if (state == StateIndicator.INITIAL_STATE) { packet = new StateIndicator(StateIndicator.INITIAL_STATE); packet.packetLength = size; packet.packetId = seqId; packet.read(this.handler, in); state = StateIndicator.RESPONSED_STATE; } else if (state == StateIndicator.RESPONSED_STATE) { byte header = in.readByte(); if (header == 0) { packet = new StateIndicator(StateIndicator.HANDSHAKEN_STATE); state = StateIndicator.HANDSHAKEN_STATE; } else { packet = new StateIndicator(StateIndicator.HANDSHAKE_FAIL_STATE); state = StateIndicator.HANDSHAKE_FAIL_STATE; } char[] bytes = new char[size]; for (int i = 0; i < size; i++) { int ch = in.getByte(i); bytes[i] = (char) ch; } packet.packetId = seqId; packet.packetLength = size; packet.read(this.handler, in); } else if (state == StateIndicator.HANDSHAKEN_STATE) { // expecting response for registered slave byte header = in.readByte(); if (header == 0) { packet = new StateIndicator(StateIndicator.REGISTERED_STATE); state = StateIndicator.REGISTERED_STATE; } else { packet = new StateIndicator(StateIndicator.REGISTER_FAIL_STATE); state = StateIndicator.REGISTER_FAIL_STATE; } packet.packetId = seqId; packet.packetLength = size; packet.read(this.handler, in); } else { // binlog stream started with 00 ok-byte byte okByte = in.readByte(); if (okByte == 0) { // read event header // timestamp 4 bytes int timeStamp = in.readInt(); // event type byte eventType = in.readByte(); // server id, 4 bytes int serverId = (int) BufferUtils.readLong(in); // event length, 4 bytes long eventLength = BufferUtils.readLong(in); // next position, 4 bytes long nextPosition = BufferUtils.readLong(in); // flags int flags = in.readShort(); // events switch (eventType) { case ReplicationPacket.ROTATE_EVENT: packet = new RotatePacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.TABLE_MAP_EVENT: packet = new TableMapPacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.WRITE_ROWS_EVENT: case ReplicationPacket.UPDATE_ROWS_EVENT: case ReplicationPacket.DELETE_ROWS_EVENT: packet = new RowsEventV2Packet(eventType, eventLength, nextPosition); break; case ReplicationPacket.STOP_EVENT: packet = new StopPacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.XID_EVENT: packet = new XIDPacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.QUERY_EVENT: case ReplicationPacket.FORMAT_DESCRIPTION_EVENT: case ReplicationPacket.START_EVENT_V3: // use GenericPacket to ignore unsupported events for now packet = new GenericPacket(eventType, eventLength, nextPosition); break; default: _log.error("unknown event: " + eventType); throw new CodingError("unknown event: " + eventType); } if (packet != null) { packet.packetId = seqId; packet.packetLength = size; packet.read(this.handler, in); } } else { ByteBuf pkt = (ByteBuf) in; ByteBuffer bbuf = pkt.nioBuffer(); int i = bbuf.remaining(); byte[] bytes = new byte[i]; pkt.readBytes(bytes); String dump = '\n' + UberUtil.hexDump(bytes); _log.error("unknown packet: " + dump); throw new CodingError("unknown packet"); } } return packet; }