List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidCountInvalidLength() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(4); buf.writeShort(5); buf.writeShort(1);//ww w .j a va2s.c o m netflowParser.parse(buf, null, null); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidCountZero() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(4); buf.writeShort(5); buf.writeShort(0);/*from w w w . j a v a 2 s .co m*/ netflowParser.parse(buf, null, null); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidPacketTooShort2() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(2); buf.writeShort(5); netflowParser.parse(buf, null, null); }
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 {/*from w ww. ja va 2 s . c om*/ 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;//from w w w. jav a 2 s .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.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);//w w w. j ava2s.co m cb.writeShort((short) errorNumber); cb.writeBytes("#".getBytes()); cb.writeBytes(sqlState.substring(0, 5).getBytes()); cb.writeBytes(errorMsg.getBytes()); }
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);/*from w w w.ja v a 2 s. c o m*/ 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);/*from w w w . j a v a 2s . co m*/ 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);//from w ww .j ava 2s . co m cb.writeBytes(getServerVersion().getBytes()); cb.writeZero(1); 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); }