List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer()
From source file:com.streamsets.pipeline.lib.parser.net.netflow.NetflowTestUtil.java
License:Apache License
public static void writeV5NetflowFlowRecord(EmbeddedChannel channel, long srcAddr, long destAddr, long nextHop, int snmpInput, int snmpOutput, long packets, long octets, long first, long last, int srcPort, int destPort, int tcpFlags, int proto, int tos, int srcAs, int destAs, int srcMask, int destMask ) {/*from w w w .ja va 2 s . c o m*/ final ByteBuf buf = Unpooled.buffer(); buf.writeInt((int) srcAddr); buf.writeInt((int) destAddr); buf.writeInt((int) nextHop); buf.writeShort(snmpInput); buf.writeShort(snmpOutput); buf.writeInt((int) packets); buf.writeInt((int) octets); buf.writeInt((int) first); buf.writeInt((int) last); buf.writeShort(srcPort); buf.writeShort(destPort); // one empty pad byte buf.writeByte(0); buf.writeByte(tcpFlags); buf.writeByte(proto); buf.writeByte(tos); buf.writeShort(srcAs); buf.writeShort(destAs); buf.writeByte(srcMask); buf.writeByte(destMask); // two empty pad bytes buf.writeByte(0); buf.writeByte(0); channel.writeInbound(buf); }
From source file:com.tesora.dve.db.mysql.libmy.MyBinaryResultRow.java
License:Open Source License
public MyBinaryResultRow append(DecodedMeta valueFunc, Object value) { ByteBuf valueBuf = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); valueFunc.writeObject(valueBuf, value); return this.append(valueFunc, valueBuf); }
From source file:com.tesora.dve.db.mysql.libmy.MyBinaryResultRowTest.java
License:Open Source License
@Before public void setUp() throws Exception { rawRow = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); rawRow.writeZero(1);//bin row marker. MyNullBitmap bitmap = new MyNullBitmap(5, MyNullBitmap.BitmapType.RESULT_ROW); bitmap.setBit(2);//one based indexing, so second field is null rawRow.writeBytes(bitmap.getBitmapArray()); List<DecodedMeta> fieldConvertors = new ArrayList<>(); {/*from w ww. j a va 2 s . c o m*/ DataTypeValueFunc mysqlTypeFunc = DBTypeBasedUtils.getMysqlTypeFunc(MyFieldType.FIELD_TYPE_LONG); mysqlTypeFunc.writeObject(rawRow, 45); fieldConvertors.add(new DecodedMeta(mysqlTypeFunc)); } { DataTypeValueFunc mysqlTypeFunc = DBTypeBasedUtils.getMysqlTypeFunc(MyFieldType.FIELD_TYPE_LONG); //nothing in packet, this was null. fieldConvertors.add(new DecodedMeta(mysqlTypeFunc)); } { DataTypeValueFunc mysqlTypeFunc = DBTypeBasedUtils.getMysqlTypeFunc(MyFieldType.FIELD_TYPE_VARCHAR); mysqlTypeFunc.writeObject(rawRow, "one"); fieldConvertors.add(new DecodedMeta(mysqlTypeFunc)); } { DataTypeValueFunc mysqlTypeFunc = DBTypeBasedUtils.getMysqlTypeFunc(MyFieldType.FIELD_TYPE_VARCHAR); mysqlTypeFunc.writeObject(rawRow, "two"); fieldConvertors.add(new DecodedMeta(mysqlTypeFunc)); } { DataTypeValueFunc mysqlTypeFunc = DBTypeBasedUtils.getMysqlTypeFunc(MyFieldType.FIELD_TYPE_VARCHAR); mysqlTypeFunc.writeObject(rawRow, "three"); fieldConvertors.add(new DecodedMeta(mysqlTypeFunc)); } origRow = new MyBinaryResultRow(fieldConvertors); origRow.unmarshallMessage(rawRow); }
From source file:com.tesora.dve.db.mysql.libmy.MyBinaryResultRowTest.java
License:Open Source License
@Test public void testProjection_Identity() throws Exception { MyBinaryResultRow fullProj = origRow.projection(new int[] { 0, 1, 2, 3, 4 }); //check that the sizes are the same. assertEquals(origRow.size(), fullProj.size()); ByteBuf marshallProj = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); fullProj.marshallMessage(marshallProj); //check that the raw bytes are byte for byte equal. for (int i = 0; i < rawRow.readableBytes(); i++) { assertEquals("byte at index=" + i, rawRow.getByte(i), marshallProj.getByte(i)); }/* w w w. j a v a 2s .c o m*/ //check that all the slices are byte for byte equal. for (int i = 0; i < origRow.size(); i++) { assertEquals(origRow.getSlice(i), fullProj.getSlice(i)); } //check that the decoded objects are equal for (int i = 0; i < origRow.size(); i++) { assertEquals(origRow.getValue(i), fullProj.getValue(i)); } }
From source file:com.tesora.dve.db.mysql.libmy.MyFieldPktResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { if (state == CacheState.NOT_CACHED) { ByteBuf newCache = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); fullPack(newCache);/* ww w. ja v a 2 s. co m*/ updateCache(newCache); } cb.writeBytes(cachedBuffer.slice()); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComQueryRequestMessage.java
License:Open Source License
public static MSPComQueryRequestMessage newMessage(byte[] rawQuery) { ByteBuf buf = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN).ensureWritable(rawQuery.length + 1); buf.writeByte(TYPE_IDENTIFIER);//w ww.j a v a 2 s . c o m buf.writeBytes(rawQuery); return new MSPComQueryRequestMessage(buf); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComQuitRequestMessage.java
License:Open Source License
protected MSPComQuitRequestMessage() { super(Unpooled.buffer()); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MysqlClientAuthenticationHandler.java
License:Open Source License
private void processGreeting(ChannelHandlerContext ctx, ByteBuf payload, Byte protocolVersion) throws Exception { if (protocolVersion == MyErrorResponse.ERRORPKT_FIELD_COUNT) { processErrorPacket(ctx, payload); } else {/*from w w w . j ava 2s . com*/ MyHandshakeV10 handshake = new MyHandshakeV10(); handshake.unmarshallMessage(payload); ctx.channel().attr(HANDSHAKE_KEY).set(handshake); serverCharset = handshake.getServerCharset(javaCharsetCatalog); targetCharset.set(serverCharset); serverThreadID = handshake.getThreadID(); ByteBuf out = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); try { String userName = userCredentials.getName(); String userPassword = userCredentials.getPassword(); String salt = handshake.getSalt(); Charset charset = javaCharsetCatalog.findJavaCharsetById(handshake.getServerCharsetId()); int mysqlCharsetID = MysqlNativeConstants.MYSQL_CHARSET_UTF8; int capabilitiesFlag = (int) clientCapabilities; handshake.setServerCharset((byte) mysqlCharsetID); MSPAuthenticateV10MessageMessage.write(out, userName, userPassword, salt, charset, mysqlCharsetID, capabilitiesFlag); ctx.writeAndFlush(out); } catch (Exception e) { out.release(); log.debug("Couldn't write auth handshake to socket", e); } enterState(AuthenticationState.AWAIT_ACKNOWLEGEMENT); } }
From source file:com.tesora.dve.db.mysql.portal.protocol.Packet.java
License:Open Source License
public static int encodeFullMessage(int sequenceStart, MysqlMessage mysql, ByteBuf destination) { //copies the message payload to a heap buffer, so we can size the actual output. ByteBuf payloadHolder = Unpooled.buffer(); mysql.marshallPayload(payloadHolder); //copy full payload to heap buffer (might be an extended payload) return encodeFullPayload(sequenceStart, payloadHolder, destination); }
From source file:com.tesora.dve.parlb.MysqlClientHandler.java
License:Open Source License
/** * Closes the specified channel after all queued write requests are flushed. *//*from w w w.ja va 2 s . c o m*/ static void closeOnFlush(Channel ch) { if (ch.isActive()) { ch.write(Unpooled.buffer()).addListener(ChannelFutureListener.CLOSE); } }