List of usage examples for io.netty.buffer ByteBuf writeZero
public abstract ByteBuf writeZero(int length);
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComStmtExecuteRequestMessage.java
License:Open Source License
@Override protected void marshall(ParsedData state, ByteBuf destination) { ByteBuf leBuf = destination.order(ByteOrder.LITTLE_ENDIAN); leBuf.writeByte(TYPE_IDENTIFIER);/* w w w .j a v a2 s.c o m*/ leBuf.writeInt((int) state.statementID); leBuf.writeByte(state.flags); leBuf.writeInt((int) state.iterationCount); if (state.metadata == null) throw new IllegalStateException("Cannot build execute request, no prepare metadata provided."); int numParams = state.metadata.getNumParams(); if (numParams > 0) { MyNullBitmap nullBitmap = new MyNullBitmap(numParams, MyNullBitmap.BitmapType.EXECUTE_REQUEST); int bitmapIndex = leBuf.writerIndex(); leBuf.writeZero(nullBitmap.length()); if (state.metadata.isNewParameterList()) { leBuf.writeByte(1); for (MyParameter param : state.metadata.getParameters()) { leBuf.writeByte(param.getType().getByteValue()); leBuf.writeZero(1); } } else { leBuf.writeZero(1); } List<Object> params = state.values; for (int i = 0; i < params.size(); ++i) { if (params.get(i) != null) DBTypeBasedUtils.getJavaTypeFunc(params.get(i).getClass()).writeObject(leBuf, params.get(i)); else nullBitmap.setBit(i + 1); } leBuf.setBytes(bitmapIndex, nullBitmap.getBitmapArray()); } }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPServerGreetingRequestMessage.java
License:Open Source License
public static void write(ChannelHandlerContext ctx, int connectionId, String salt, int serverCapabilities, String serverVersion, byte serverCharSet, String pluginData) { ByteBuf out = ctx.channel().alloc().heapBuffer(50).order(ByteOrder.LITTLE_ENDIAN); String scrambleBuffer1st = salt.substring(0, 8); String scrambleBuffer2nd = salt.substring(8) + '\0'; Integer scrambleBufferSize = scrambleBuffer1st.length() + scrambleBuffer2nd.length(); ByteBuf serverCapabilitiesBuf = ctx.channel().alloc().heapBuffer(4).order(ByteOrder.LITTLE_ENDIAN); try {// w w w. ja v a 2 s. c o m serverCapabilitiesBuf.writeInt(serverCapabilities); out.writeMedium(0); out.writeByte(0); out.writeByte(MYSQL_PROTOCOL_VERSION); out.writeBytes(serverVersion.getBytes()); out.writeZero(1); out.writeInt(connectionId); out.writeBytes(scrambleBuffer1st.getBytes()); // Salt out.writeZero(1); out.writeByte(serverCapabilitiesBuf.getByte(0)); out.writeByte(serverCapabilitiesBuf.getByte(1)); out.writeByte(serverCharSet); out.writeShort(MyProtocolDefs.SERVER_STATUS_AUTOCOMMIT); out.writeByte(serverCapabilitiesBuf.getByte(2)); out.writeByte(serverCapabilitiesBuf.getByte(3)); out.writeByte(scrambleBufferSize.byteValue()); out.writeZero(10); // write 10 unused bytes out.writeBytes(scrambleBuffer2nd.getBytes()); // Salt out.writeBytes(pluginData.getBytes()); // payload out.writeZero(1); out.setMedium(0, out.writerIndex() - 4); ctx.channel().writeAndFlush(out); } finally { serverCapabilitiesBuf.release(); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyComBinLogDumpRequest.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeInt((int) binlogPosition); cb.writeZero(2); // binlog_flags cb.writeInt(slaveServerID);//w ww. j a va2 s . c om if (binlogFileName != null) { cb.writeBytes(binlogFileName.getBytes(CharsetUtil.UTF_8)); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyComRegisterSlaveRequest.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeInt(slaveServerId);//w ww.j av a 2 s. co m MysqlAPIUtils.putLengthCodedString(cb, reportHost, true /* codeNullasZero */); MysqlAPIUtils.putLengthCodedString(cb, reportUser, true /* codeNullasZero */); MysqlAPIUtils.putLengthCodedString(cb, reportPassword, true /* codeNullasZero */); cb.writeShort(reportPort); cb.writeZero(8); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyFormatDescriptionLogEvent.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeShort(binaryLogVersion);/*from w w w. j av a 2 s. co m*/ cb.writeBytes(serverVersion.getBytes(CharsetUtil.UTF_8)); cb.writeInt((int) createTime); cb.writeByte(0xFF & eventTypeLength); switch (MyBinLogVerType.fromByte((byte) binaryLogVersion)) { case MySQL_5_0: for (int i = 1; i <= eventTypeValues.size(); i++) { cb.writeByte(eventTypeValues.get(MyLogEventType.fromByte((byte) i))); } cb.writeZero(1); break; default: break; } }
From source file:com.uber.tchannel.codecs.TFrameCodec.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, TFrame frame, ByteBuf out) throws Exception { // size:2/*from w w w.ja v a2 s. c o m*/ out.writeShort(frame.size + TFrame.FRAME_HEADER_LENGTH); // type:1 out.writeByte(frame.type); // reserved:1 out.writeZero(1); // id:4 out.writeInt((int) frame.id); // reserved:8 out.writeZero(8); // payload:16+ out.writeBytes(frame.payload); }
From source file:com.uber.tchannel.codecs.TFrameCodec.java
License:Open Source License
public static ByteBuf encode(ByteBufAllocator allocator, TFrame frame) { ByteBuf buffer = allocator.buffer(TFrame.FRAME_HEADER_LENGTH, TFrame.FRAME_HEADER_LENGTH); // size:2//from ww w. j a v a2s .c om buffer.writeShort(frame.size + TFrame.FRAME_HEADER_LENGTH); // type:1 buffer.writeByte(frame.type); // reserved:1 buffer.writeZero(1); // id:4 buffer.writeInt((int) frame.id); // reserved:8 buffer.writeZero(8); // TODO: refactor if (frame.payload instanceof CompositeByteBuf) { CompositeByteBuf cbf = (CompositeByteBuf) frame.payload; cbf.addComponent(0, buffer); cbf.writerIndex(cbf.writerIndex() + TFrame.FRAME_HEADER_LENGTH); return cbf; } return Unpooled.wrappedBuffer(buffer, frame.payload); }
From source file:io.airlift.drift.transport.netty.codec.HeaderTransport.java
License:Apache License
private static ByteBuf getPadding(int headerSize) { int paddingSize = 4 - headerSize % 4; ByteBuf padding = Unpooled.buffer(paddingSize); padding.writeZero(paddingSize); return padding; }
From source file:net.petercashel.nettyCore.common.packetCore.PacketBase.java
License:Apache License
public void sendPacket(ChannelHandlerContext ctx) { ByteBuf b = ctx.alloc().buffer(Packet.packetBufSize + Packet.packetHeaderSize, Packet.packetBufSize + Packet.packetHeaderSize); b.writeInt(PacketRegistry.GetOtherSide()); b.writeInt(packetID);// w w w .j ava2 s .c o m b.writeBytes(packet); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { ctx.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } else { b.writeZero(b.writableBytes()); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { ctx.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } } }
From source file:net.petercashel.nettyCore.common.packetCore.PacketBase.java
License:Apache License
public void sendPacket(Channel c) { ByteBuf b = c.alloc().buffer(Packet.packetBufSize + Packet.packetHeaderSize, Packet.packetBufSize + Packet.packetHeaderSize); b.writeInt(PacketRegistry.GetOtherSide()); b.writeInt(packetID);/*from w w w.j a v a 2 s. c o m*/ b.writeBytes(packet); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { c.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } else { b.writeZero(b.writableBytes()); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { c.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } } }