本文整理匯總了Java中io.netty.buffer.ByteBuf.readCharSequence方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.readCharSequence方法的具體用法?Java ByteBuf.readCharSequence怎麽用?Java ByteBuf.readCharSequence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.readCharSequence方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processProtocolInitFrame
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private void processProtocolInitFrame(ByteBuf buffer, List<Object> out) {
if (buffer.readableBytes() >= 8) {
CharSequence protocolName = buffer.readCharSequence(4, CharsetUtil.US_ASCII);
buffer.skipBytes(1);
byte majorVersion = buffer.readByte();
byte minorVersion = buffer.readByte();
byte revision = buffer.readByte();
if (!AMQP_PROTOCOL_IDENTIFIER.equals(protocolName)) {
out.add(new AmqpBadMessage(new IllegalArgumentException("Unknown protocol name " +
protocolName.toString())));
currentState = State.BAD_MESSAGE;
}
out.add(new ProtocolInitFrame(majorVersion, minorVersion, revision));
}
}
示例2: decodeText
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public Number decodeText(int len, ByteBuf buff) {
// Todo optimize that
CharSequence cs = buff.readCharSequence(len, StandardCharsets.UTF_8);
BigDecimal big = new BigDecimal(cs.toString());
// julien : that does not seem consistent to either return a Double or BigInteger
if (big.scale() == 0) {
return big.toBigInteger();
} else {
// we might loose precision here
return big.doubleValue();
}
}
示例3: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
protected ClusterMessage decode(ByteBuf in) {
in.markReaderIndex();
try {
ClusterMessage hdr = new ClusterMessage();
hdr.signature = (String) in.readCharSequence(4, UTF_8);
hdr.length = in.readInt();
if (in.readableBytes() < hdr.length - 8) {
in.resetReaderIndex(); return null;
}
hdr.version = Version.valueOf(in.readUnsignedShort());
if (hdr.version == PROTOCOL_V0) decodeMessageV0(hdr, in);
else if (hdr.version == PROTOCOL_V1) decodeMessageV1(hdr, in);
else throw new UnsupportedOperationException("version: " + hdr.version);
return hdr;
} catch (Exception e) {
in.resetReaderIndex(); return null;
}
}
示例4: read
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void read(RakNetByteBuf in) {
super.read(in);
protocolVersion = in.readInt();
edition = in.readUnsignedByte();
ByteBuf buf = in.readBytes(
in.readUnsignedVarInt()
);
chainData = buf.readCharSequence(buf.readIntLE(), Charsets.UTF_8);
skinData = buf.readCharSequence(buf.readIntLE(), Charsets.UTF_8);
buf.release();
}
示例5: processOption
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private String processOption(ChannelHandlerContext ctx, ByteBuf in) throws IOException {
switch (currentOption) {
case Protocol.NBD_OPT_EXPORT_NAME:
CharSequence exportName = in.readCharSequence((int) currentOptionLen, Charset.forName("UTF-8"));
if (!exportProvider.supportsClientFlags(clientFlags)) {
LOGGER.error("client flags {} not supported", clientFlags);
ctx.channel().close();
break;
}
long exportSize = 0;
if ((exportSize = exportProvider.open(exportName)) < 0) {
// ep us unwilling to export this name
ctx.channel().close();
break;
}
/* build response */
ByteBuf resp = ctx.alloc().buffer(256);
resp.writeLong(exportSize);
short transmissionFlags =
Protocol.NBD_FLAG_HAS_FLAGS
| Protocol.NBD_FLAG_SEND_FLUSH
| Protocol.NBD_FLAG_SEND_TRIM;
resp.writeShort(transmissionFlags);
if ((clientFlags & Protocol.NBD_FLAG_NO_ZEROES) == 0) {
resp.writeZero(124);
}
ctx.writeAndFlush(resp);
//FIXME: transfer any remaining bytes into the transmission phase!
/* The NBD protocol has two phases: the handshake (HS_) and the transmission (TM_) */
// Handshake complete, switch to transmission phase
ctx.pipeline().addLast("transmission", new TransmissionPhase(config, exportProvider));
ctx.pipeline().remove(this);
return exportName.toString();
default:
sendHandshakeOptionHagglingReply(ctx, currentOption, Protocol.NBD_REP_ERR_UNSUP, null);
}
return null;
}