本文整理匯總了Java中io.netty.buffer.ByteBufAllocator.buffer方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBufAllocator.buffer方法的具體用法?Java ByteBufAllocator.buffer怎麽用?Java ByteBufAllocator.buffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.buffer.ByteBufAllocator
的用法示例。
在下文中一共展示了ByteBufAllocator.buffer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
byte[] pathBytes = fileId.pathBytes();
int length = 2 * FDFS_LONG_LEN + FDFS_GROUP_LEN + pathBytes.length;
byte cmd = FILE_DOWNLOAD;
ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
buf.writeLong(length);
buf.writeByte(cmd);
buf.writeByte(ERRNO_OK);
buf.writeLong(offset);
buf.writeLong(size);
writeFixLength(buf, fileId.group(), FDFS_GROUP_LEN);
ByteBufUtil.writeUtf8(buf, fileId.path());
return Collections.singletonList(buf);
}
示例2: encodeMessageWithOnlySingleByteFixedHeaderAndMessageId
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
private static ByteBuf encodeMessageWithOnlySingleByteFixedHeaderAndMessageId(
ByteBufAllocator byteBufAllocator,
MqttMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) message.variableHeader();
int msgId = variableHeader.messageId();
int variableHeaderBufferSize = 2; // variable part only has a message id
int fixedHeaderBufferSize = 1 + getVariableLengthInt(variableHeaderBufferSize);
ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variableHeaderBufferSize);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
writeVariableLengthInt(buf, variableHeaderBufferSize);
buf.writeShort(msgId);
return buf;
}
示例3: encodeRequest
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
static ByteBuf encodeRequest(TProtocolFactory protocolFactory, ByteBufAllocator allocator, int sequenceId, MethodMetadata method, List<Object> parameters)
throws Exception
{
TChannelBufferOutputTransport transport = new TChannelBufferOutputTransport(allocator.buffer(1024));
TProtocolWriter protocol = protocolFactory.getProtocol(transport);
// Note that though setting message type to ONEWAY can be helpful when looking at packet
// captures, some clients always send CALL and so servers are forced to rely on the "oneway"
// attribute on thrift method in the interface definition, rather than checking the message
// type.
protocol.writeMessageBegin(new TMessage(method.getName(), method.isOneway() ? ONEWAY : CALL, sequenceId));
// write the parameters
ProtocolWriter writer = new ProtocolWriter(protocol);
writer.writeStructBegin(method.getName() + "_args");
for (int i = 0; i < parameters.size(); i++) {
Object value = parameters.get(i);
ParameterMetadata parameter = method.getParameters().get(i);
writer.writeField(parameter.getName(), parameter.getId(), parameter.getCodec(), value);
}
writer.writeStructEnd();
protocol.writeMessageEnd();
return transport.getOutputBuffer();
}
示例4: encode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
byte[] pathBytes = fileId.pathBytes();
byte[] metadatas = metadata.toBytes(UTF_8);
int length = 2 * FDFS_LONG_LEN + 1 + FDFS_GROUP_LEN + pathBytes.length + metadatas.length;
byte cmd = FastdfsConstants.Commands.METADATA_SET;
ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
buf.writeLong(length);
buf.writeByte(cmd);
buf.writeByte(ERRNO_OK);
buf.writeLong(pathBytes.length);
buf.writeLong(metadatas.length);
buf.writeByte(flag);
writeFixLength(buf, fileId.group(), FDFS_GROUP_LEN);
buf.writeBytes(pathBytes);
buf.writeBytes(metadatas);
return Collections.singletonList(buf);
}
示例5: preEncode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
static ByteBuf preEncode(Object msg, Codec<Object> codec, ByteBufAllocator allocator) throws CodecException {
ByteBuf buf = null;
try {
buf = allocator.buffer();
ByteBufDataWriter writer = new ByteBufDataWriter(buf);
doEncode(msg, writer, codec);
return buf;
} catch (CodecException e) {
if (buf != null) {
buf.release();
}
throw e;
}
}
示例6: encodeMessageWithOnlySingleByteFixedHeaderAndPacketId
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
private static ByteBuf encodeMessageWithOnlySingleByteFixedHeaderAndPacketId(
ByteBufAllocator byteBufAllocator,
MqttMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
MqttPacketIdVariableHeader variableHeader = (MqttPacketIdVariableHeader) message.variableHeader();
int msgId = variableHeader.packetId();
int variableHeaderBufferSize = 2; // variable part only has a message id
int fixedHeaderBufferSize = 1 + getVariableLengthInt(variableHeaderBufferSize);
ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variableHeaderBufferSize);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
writeVariableLengthInt(buf, variableHeaderBufferSize);
buf.writeShort(msgId);
return buf;
}
示例7: metadata
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
protected ByteBuf metadata(ByteBufAllocator alloc) {
int metaLen = FDFS_STORE_PATH_INDEX_LEN + FDFS_PROTO_PKG_LEN_SIZE + FDFS_FILE_EXT_LEN;
ByteBuf buf = alloc.buffer(metaLen);
buf.writeByte(pathIdx);
buf.writeLong(size());
writeFixLength(buf, ext, FDFS_FILE_EXT_LEN);
return buf;
}
示例8: encode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
int length = isEmpty(group) ? 0 : FDFS_GROUP_LEN;
byte cmd = isEmpty(group) ? SERVICE_QUERY_STORE_WITHOUT_GROUP_ONE : SERVICE_QUERY_STORE_WITH_GROUP_ONE;
ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
buf.writeLong(length);
buf.writeByte(cmd);
buf.writeByte(ERRNO_OK);
if (!isEmpty(group)) {
FastdfsUtils.writeFixLength(buf, group, FDFS_GROUP_LEN);
}
return Collections.singletonList(buf);
}
示例9: encodeConnAckMessage
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
private static ByteBuf encodeConnAckMessage(
ByteBufAllocator byteBufAllocator,
MqttConnAckMessage message) {
ByteBuf buf = byteBufAllocator.buffer(4);
buf.writeByte(getFixedHeaderByte1(message.fixedHeader()));
buf.writeByte(2);
buf.writeByte(message.variableHeader().isSessionPresent() ? 0x01 : 0x00);
buf.writeByte(message.variableHeader().connectReturnCode().byteValue());
return buf;
}
示例10: encodePublishMessage
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
private static ByteBuf encodePublishMessage(
ByteBufAllocator byteBufAllocator,
MqttPublishMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
MqttPublishVariableHeader variableHeader = message.variableHeader();
ByteBuf payload = message.payload().duplicate();
String topicName = variableHeader.topicName();
byte[] topicNameBytes = encodeStringUtf8(topicName);
int variableHeaderBufferSize = 2 + topicNameBytes.length +
(mqttFixedHeader.qosLevel().value() > 0 ? 2 : 0);
int payloadBufferSize = payload.readableBytes();
int variablePartSize = variableHeaderBufferSize + payloadBufferSize;
int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize);
ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variablePartSize);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
writeVariableLengthInt(buf, variablePartSize);
buf.writeShort(topicNameBytes.length);
buf.writeBytes(topicNameBytes);
if (mqttFixedHeader.qosLevel().value() > 0) {
buf.writeShort(variableHeader.messageId());
}
buf.writeBytes(payload);
return buf;
}
示例11: encode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
int length = isEmpty(group) ? 0 : FDFS_GROUP_LEN;
byte cmd = isEmpty(group) ? SERVICE_QUERY_STORE_WITHOUT_GROUP_ONE
: SERVICE_QUERY_STORE_WITH_GROUP_ONE;
ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
buf.writeLong(length);
buf.writeByte(cmd);
buf.writeByte(ERRNO_OK);
if (!isEmpty(group)) {
writeFixLength(buf, group, FDFS_GROUP_LEN);
}
return Collections.singletonList(buf);
}
示例12: encode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
byte cmd = cmd();
int length = FastdfsConstants.FDFS_GROUP_LEN + fileId.pathBytes().length;
ByteBuf buf = alloc.buffer(length + FastdfsConstants.FDFS_HEAD_LEN);
buf.writeLong(length);
buf.writeByte(cmd);
buf.writeByte(FastdfsConstants.ERRNO_OK);
FastdfsUtils.writeFixLength(buf, fileId.group(), FastdfsConstants.FDFS_GROUP_LEN);
ByteBufUtil.writeUtf8(buf, fileId.path());
return Collections.singletonList(buf);
}
示例13: encode
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
byte[] pathBytes = fileId.path().getBytes(UTF_8);
int length = 2 * FDFS_PROTO_PKG_LEN_SIZE + pathBytes.length;
byte cmd = FastdfsConstants.Commands.FILE_TRUNCATE;
ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
buf.writeLong(length);
buf.writeByte(cmd);
buf.writeByte(ERRNO_OK);
buf.writeLong(pathBytes.length);
buf.writeLong(truncatedSize);
buf.writeBytes(pathBytes);
return Collections.singletonList(buf);
}
示例14: metadata
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
@Override
protected ByteBuf metadata(ByteBufAllocator alloc) {
byte[] pathBytes = fileId.pathBytes();
int metaSize = 2 * FastdfsConstants.FDFS_PROTO_PKG_LEN_SIZE + pathBytes.length;
ByteBuf buf = alloc.buffer(metaSize);
buf.writeLong(pathBytes.length);
buf.writeLong(size());
buf.writeBytes(pathBytes);
return buf;
}
示例15: encodeConnAckMessage
import io.netty.buffer.ByteBufAllocator; //導入方法依賴的package包/類
private static ByteBuf encodeConnAckMessage(
ByteBufAllocator byteBufAllocator,
MqttConnAckMessage message) {
ByteBuf buf = byteBufAllocator.buffer(4);
buf.writeByte(getFixedHeaderByte1(message.fixedHeader()));
buf.writeByte(2);
buf.writeByte(message.variableHeader().sessionPresent() ? 0x01 : 0x00);
buf.writeByte(message.variableHeader().returnCode().byteValue());
return buf;
}