当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.writerIndex方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBuf.writerIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.writerIndex方法的具体用法?Java ByteBuf.writerIndex怎么用?Java ByteBuf.writerIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.writerIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void encode(ByteBuf out) {

  int pos = out.writerIndex();

  out.writeInt(0);
  // protocol version
  out.writeShort(3);
  out.writeShort(0);

  writeCString(out, BUFF_USER);
  Util.writeCStringUTF8(out, username);
  writeCString(out, BUFF_DATABASE);
  Util.writeCStringUTF8(out, database);
  writeCString(out, BUFF_APPLICATION_NAME);
  writeCString(out, BUFF_VERTX_PG_CLIENT);
  writeCString(out, BUFF_CLIENT_ENCODING);
  writeCString(out, BUFF_UTF8);
  writeCString(out, BUFF_DATE_STYLE);
  writeCString(out, BUFF_ISO);
  writeCString(out, BUFF_EXTRA_FLOAT_DIGITS);
  writeCString(out, BUFF_2);

  out.writeByte(0);
  out.setInt(pos, out.writerIndex() - pos);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:27,代码来源:StartupMessage.java

示例2: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, T msg, ByteBuf out)
        throws Exception {

    int lengthIndex = out.writerIndex();
    // length field, will be filled in later.
    out.writeInt(0);

    int startIndex = out.writerIndex();
    ByteBufOutputStream os = new ByteBufOutputStream(out);
    TCompactProtocol thriftProtocol =
            new TCompactProtocol(new TIOStreamTransport(os));
    msg.write(thriftProtocol);
    os.close();
    int endIndex = out.writerIndex();

    // update the length field
    int length = endIndex - startIndex;
    out.setInt(lengthIndex, length);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:21,代码来源:ThriftFrameEncoder.java

示例3: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static void encode(long statement, String query, int[] paramDataTypes, ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(PARSE);
  out.writeInt(0);
  if(statement == 0) {
    out.writeByte(0);
  } else {
    out.writeLong(statement);
  }
  Util.writeCStringUTF8(out, query);
  // no parameter data types (OIDs)
  if(paramDataTypes == null) {
    out.writeShort(0);
  } else {
    // Parameter data types (OIDs)
    out.writeShort(paramDataTypes.length);
    for (int paramDataType : paramDataTypes) {
      out.writeInt(paramDataType);
    }
  }
  out.setInt(pos + 1, out.writerIndex() - pos - 1);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:23,代码来源:Parse.java

示例4: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static int encode(ByteBuf byteBuf, int namespaceId, int serviceId, int methodId, ByteBuf metadata) {
    int offset = 0;

    byteBuf.setShort(offset, 1);
    offset += VERSION_SIZE;

    byteBuf.setInt(offset, namespaceId);
    offset += NAMESPACE_ID_SIZE;

    byteBuf.setInt(offset, serviceId);
    offset += SERVICE_ID_SIZE;

    byteBuf.setInt(offset, methodId);
    offset += METHOD_ID_SIZE;

    int metadataLength = metadata.readableBytes();
    byteBuf.setInt(offset, metadataLength);
    offset += METADATA_LENGTH_SIZE;

    byteBuf.setBytes(offset, metadata);
    offset += metadataLength;

    byteBuf.writerIndex(offset);

    return offset;
}
 
开发者ID:netifi,项目名称:proteus-java,代码行数:27,代码来源:ProteusMetadata.java

示例5: writeString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void writeString(String str, ByteBuf cb)
{
    int writerIndex = cb.writerIndex();
    cb.writeShort(0);
    int lengthBytes = ByteBufUtil.writeUtf8(cb, str);
    cb.setShort(writerIndex, lengthBytes);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:8,代码来源:CBUtil.java

示例6: encodeText

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public void encodeText(T value, ByteBuf buff) {
  int index = buff.writerIndex();
  String s = String.valueOf(value);
  int len = buff.setCharSequence(index + 4, s, StandardCharsets.UTF_8);
  buff.writeInt(len);
  buff.writerIndex(index + 4 + len);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:8,代码来源:DataType.java

示例7: getBytesFast

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static byte[] getBytesFast(ByteBuf byteBuf) {
  if (byteBuf.hasArray()) {
    return byteBuf.array();
  }

  byte[] arr = new byte[byteBuf.writerIndex()];
  byteBuf.getBytes(0, arr);
  return arr;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:10,代码来源:VertxUtils.java

示例8: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static void encode(String portal, int rowCount, ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(EXECUTE);
  out.writeInt(0);
  if (portal != null) {
    out.writeCharSequence(portal, StandardCharsets.UTF_8);
  }
  out.writeByte(0);
  out.writeInt(rowCount); // Zero denotes "no limit" maybe for ReadStream<Row>
  out.setInt(pos + 1, out.writerIndex() - pos - 1);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:12,代码来源:Execute.java

示例9: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void encode(ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(CLOSE);
  out.writeInt(0);
  out.writeByte('S'); // 'S' to close a prepared statement or 'P' to close a portal
  Util.writeCStringUTF8(out, statement != null ? statement : "");
  out.setInt(pos + 1, out.writerIndex() - pos - 1);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:10,代码来源:Close.java

示例10: decipher

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
protected ByteBuf decipher(ChannelHandlerContext ctx, ByteBuf buffer) throws ShortBufferException
{
    int i = buffer.readableBytes();
    byte[] abyte = this.bufToBytes(buffer);
    ByteBuf bytebuf = ctx.alloc().heapBuffer(this.cipher.getOutputSize(i));
    bytebuf.writerIndex(this.cipher.update(abyte, 0, i, bytebuf.array(), bytebuf.arrayOffset()));
    return bytebuf;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:9,代码来源:NettyEncryptionTranslator.java

示例11: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void encode(ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(QUERY);
  out.writeInt(0);
  Util.writeCStringUTF8(out, getQuery());
  out.setInt(pos + 1, out.writerIndex() - pos - 1);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:9,代码来源:Query.java

示例12: decipher

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
protected ByteBuf decipher(ChannelHandlerContext ctx, ByteBuf buffer) throws ShortBufferException
{
    int i = buffer.readableBytes();
    byte[] abyte = this.func_150502_a(buffer);
    ByteBuf bytebuf = ctx.alloc().heapBuffer(this.cipher.getOutputSize(i));
    bytebuf.writerIndex(this.cipher.update(abyte, 0, i, bytebuf.array(), bytebuf.arrayOffset()));
    return bytebuf;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:9,代码来源:NettyEncryptionTranslator.java

示例13: decrypt

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public ByteBuf decrypt( ChannelHandlerContext paramChannelHandlerContext, ByteBuf input ) throws ShortBufferException {
    int readableBytes = input.readableBytes();
    this.lock.lock();
    try {
        byte[] array = toByteArray( input );
        ByteBuf output = paramChannelHandlerContext.alloc().heapBuffer( this.cipher.getOutputSize( readableBytes ) );
        output.writerIndex( this.cipher.update( array, 0, readableBytes, output.array(), output.arrayOffset() ) );
        return output;
    } finally {
        this.lock.unlock();
    }
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:13,代码来源:EncryptionBufWrapper.java

示例14: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void encode(ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(PASSWORD_MESSAGE);
  out.writeInt(0);
  Util.writeCStringUTF8(out, hash);
  out.setInt(pos + 1, out.writerIndex() - pos- 1);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:9,代码来源:PasswordMessage.java

示例15: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, IOutgoingPacket packet, ByteBuf out)
{
	if (out.order() != _byteOrder)
	{
		out = out.order(_byteOrder);
	}
	
	try
	{
		if (packet.write(new PacketWriter(out)))
		{
			if (out.writerIndex() > _maxPacketSize)
			{
				throw new IllegalStateException("Packet (" + packet + ") size (" + out.writerIndex() + ") is bigger than the limit (" + _maxPacketSize + ")");
			}
		}
		else
		{
			// Avoid sending the packet
			out.clear();
		}
	}
	catch (Throwable e)
	{
		LOGGER.log(Level.WARNING, "Failed sending Packet(" + packet + ")", e);
		// Avoid sending the packet if some exception happened
		out.clear();
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:31,代码来源:PacketEncoder.java


注:本文中的io.netty.buffer.ByteBuf.writerIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。