List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
License:Open Source License
public static void putLengthCodedLong(ByteBuf cb, long length) { if (length <= LEN_CODED_8_BITS) { cb.writeByte((int) length); // length is 1 byte } else if (length <= UNSIGNED_SHORT_MAX) { cb.writeByte(LEN_CODED_16_BITS); // length is 2 bytes cb.writeShort((int) length); } else if (length <= UNSIGNED_MEDIUM_MAX) { cb.writeByte(LEN_CODED_24_BITS); // length is 3 bytes cb.writeMedium((int) length); } else {/* w w w . j av a 2s . c o m*/ cb.writeByte(LEN_CODED_64_BITS); // length is 8 bytes cb.writeLong(length); } }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
License:Open Source License
public static void putLengthCodedDate(ByteBuf cb, Date inDate) { byte length = 0; Calendar cal = null;//w ww. j av a 2s.c o m if (inDate != null) { cal = DateUtils.toCalendar(inDate); if (cal.get(Calendar.MILLISECOND) > 0) { // indicates we need full 11 byte date length = 11; } else if (cal.get(Calendar.HOUR_OF_DAY) > 0 || cal.get(Calendar.MINUTE) > 0 || cal.get(Calendar.SECOND) > 0) { // this is the 7 byte format length = 7; } else if (cal.get(Calendar.YEAR) > 0 || cal.get(Calendar.MONTH) > 0 || cal.get(Calendar.DAY_OF_MONTH) > 0) { length = 4; } } cb.writeByte(length); if (length >= 4) { cb.writeShort(cal.get(Calendar.YEAR)); cb.writeByte(cal.get(Calendar.MONTH) + 1); // MONTH is zero based cb.writeByte(cal.get(Calendar.DAY_OF_MONTH)); } if (length >= 7) { cb.writeByte(cal.get(Calendar.HOUR_OF_DAY)); cb.writeByte(cal.get(Calendar.MINUTE)); cb.writeByte(cal.get(Calendar.SECOND)); } if (length == 11) { // 1 millisecond = 1000 microseconds, right? int microSeconds = cal.get(Calendar.MILLISECOND) * 1000; cb.writeInt(microSeconds); } }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
License:Open Source License
public static void putLengthCodedTime(ByteBuf cb, Time inTime) { byte length = 0; Calendar cal = null;/*w ww. j ava 2 s .c o m*/ if (inTime != null) { cal = DateUtils.toCalendar(inTime); if (cal.get(Calendar.MILLISECOND) > 0) { // indicates we need full 12 byte date length = 12; } else if (cal.get(Calendar.HOUR_OF_DAY) > 0 || cal.get(Calendar.MINUTE) > 0 || cal.get(Calendar.SECOND) > 0) { // this is the 8 byte format length = 8; } } cb.writeByte(length); if (length >= 8) { cb.writeZero(5); // this is the sign and days - we are not supporting this cb.writeByte(cal.get(Calendar.HOUR_OF_DAY)); cb.writeByte(cal.get(Calendar.MINUTE)); cb.writeByte(cal.get(Calendar.SECOND)); } if (length == 12) { // 1 millisecond = 1000 microseconds, right? int microSeconds = cal.get(Calendar.MILLISECOND) * 1000; cb.writeInt(microSeconds); } }
From source file:com.tesora.dve.db.mysql.libmy.BufferedExecute.java
License:Open Source License
public void marshallMessage(ByteBuf stmtExecuteBuf) { //header and type are marshalled by parent class. int rowsToFlush = this.size(); MyNullBitmap nullBitmap = new MyNullBitmap(rowsToFlush * columnsPerTuple, MyNullBitmap.BitmapType.EXECUTE_REQUEST); // stmtExecuteBuf.writeByte(MSPComStmtExecuteRequestMessage.TYPE_IDENTIFIER); stmtExecuteBuf.writeInt(this.stmtID); stmtExecuteBuf.writeZero(1); // flags stmtExecuteBuf.writeInt(1); // iteration count int nullBitmapIndex = stmtExecuteBuf.writerIndex(); stmtExecuteBuf.writeZero(nullBitmap.length()); // write the parameter types, as appropriate if (this.needsNewParams) { stmtExecuteBuf.writeByte(1); for (int i = 0; i < rowsToFlush; ++i) { stmtExecuteBuf.writeBytes(metadataFragment.slice()); }/*from ww w .j a v a 2s . c o m*/ } else stmtExecuteBuf.writeZero(1); // Copy the parameter values, updating the null bitmap // null bitmap is 1-based int rowsWritten = 0; int execStmtColIndex = 1; for (Iterator<MyBinaryResultRow> i = this.queuedPackets.iterator(); i.hasNext();) { MyBinaryResultRow rowPacketData = i.next(); // ByteBuf rowSet = Unpooled.buffer(rowPacketData.binRow.sizeInBytes()).order(ByteOrder.LITTLE_ENDIAN); // rowPacketData.binRow.marshallFullMessage(rowSet); // while (rowSet.isReadable() && rowsToWrite-- > 0) { // System.out.println(siteCtx + "/" + myi + ": adding row"); // int payloadLen = rowSet.readMedium(); // rowSet.skipBytes(1); // byte packetHeader = rowSet.readByte(); // if (packetHeader != 0) // throw new PEException("Out-of-sync reading redist rowSet"); int bitmapSize = MyNullBitmap.computeSize(columnsPerTuple, MyNullBitmap.BitmapType.RESULT_ROW); int rowFields = rowPacketData.size(); for (int colIndex = 1; colIndex <= columnsPerTuple; colIndex++, execStmtColIndex++) { //we are looping through target columns, which may exceed the source column count. if ((colIndex <= rowFields) && rowPacketData.isNull(colIndex - 1 /* zero based indexing */)) nullBitmap.setBit(execStmtColIndex); } // rowSet.skipBytes(bitmapSize); // stmtExecuteBuf.writeBytes(rowSet, payloadLen-bitmapSize-1); rowPacketData.marshallRawValues(stmtExecuteBuf); ++rowsWritten; } if (rowsWritten != rowsToFlush) { // System.out.println("At failure " + stmtExecuteBuf + "/" + siteCtx); throw new PECodingException("Asked to write " + rowsToFlush + " rows, but only " + rowsWritten + " were (" + rowsToFlush + " were made available to flushBuffers)"); } // Go back and set the null bitmap and the payload size stmtExecuteBuf.setBytes(nullBitmapIndex, nullBitmap.getBitmapArray()); }
From source file:com.tesora.dve.db.mysql.libmy.MyEOFPktResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(EOFPKK_FIELD_COUNT); cb.writeShort(warningCount); cb.writeShort(statusFlags); }
From source file:com.tesora.dve.db.mysql.libmy.MyErrorResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(ERRORPKT_FIELD_COUNT); cb.writeShort((short) errorNumber); cb.writeBytes("#".getBytes()); cb.writeBytes(sqlState.substring(0, 5).getBytes()); cb.writeBytes(errorMsg.getBytes());//from w w w . j ava 2 s.com }
From source file:com.tesora.dve.db.mysql.libmy.MyFieldPktResponse.java
License:Open Source License
public void fullPack(ByteBuf cb) { MysqlAPIUtils.putLengthCodedString(cb, catalog, true); MysqlAPIUtils.putLengthCodedString(cb, database, true); MysqlAPIUtils.putLengthCodedString(cb, table, true); MysqlAPIUtils.putLengthCodedString(cb, orig_table, true); MysqlAPIUtils.putLengthCodedString(cb, column, true); MysqlAPIUtils.putLengthCodedString(cb, orig_column, true); // The "spec" I used said this next byte was "filler", thru investigation // we determined that it is the number of bytes to the end of // the packet (not including the default). It seems to be always 12 cb.writeByte((byte) 12); cb.writeByte(charset);//w w w.j av a2s.c om cb.writeZero(1); cb.writeInt(column_length); cb.writeByte(column_type.getByteValue()); cb.writeShort(flags); cb.writeByte(scale); cb.writeZero(2); }
From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeErrorResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(ERRORPKT_FIELD_COUNT); cb.writeShort((short) getErrorNumber()); cb.writeBytes(getErrorMsg().getBytes(charset)); }
From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeV10.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(protocolVersion); cb.writeBytes(getServerVersion().getBytes()); cb.writeZero(1);/* ww w .j av a2 s.c o m*/ cb.writeInt(getThreadID()); cb.writeBytes(scrambleBuffer1st.getBytes()); // Salt cb.writeZero(1); cb.writeByte(getServerCapabilities((byte) 0)); cb.writeByte(getServerCapabilities((byte) 1)); cb.writeByte(getServerCharsetId()); cb.writeShort(serverStatus); cb.writeByte(getServerCapabilities((byte) 2)); cb.writeByte(getServerCapabilities((byte) 3)); cb.writeByte(scrambleBufferSize.byteValue()); cb.writeZero(10); // write 10 unused bytes cb.writeBytes(scrambleBuffer2nd.getBytes()); // Salt cb.writeBytes(getPlugInProvidedData().getBytes()); // payload cb.writeZero(1); }
From source file:com.tesora.dve.db.mysql.libmy.MyLoadDataResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(0xFB); cb.writeBytes(fileName.getBytes(CharsetUtil.UTF_8)); }