本文整理汇总了Java中io.netty.buffer.ByteBuf.readByte方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.readByte方法的具体用法?Java ByteBuf.readByte怎么用?Java ByteBuf.readByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.readByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readVarInt
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static int readVarInt(ByteBuf buf, int maxSize) {
Validate.isTrue(maxSize < 6 && maxSize > 0, "Varint length is between 1 and 5, not %d", maxSize);
int i = 0;
int j = 0;
byte b0;
do {
b0 = buf.readByte();
i |= (b0 & 127) << j++ * 7;
if (j > maxSize) {
throw new RuntimeException("VarInt too big");
}
}
while ((b0 & 128) == 128);
return i;
}
示例2: decodeHeaders
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static Map<String, String> decodeHeaders(int expectedHeadersType, ByteBuf messageHeader)
{
if (messageHeader.readableBytes() == 0) {
return ImmutableMap.of();
}
byte headersType = messageHeader.readByte();
if (headersType != expectedHeadersType) {
return ImmutableMap.of();
}
ImmutableMap.Builder<String, String> headers = ImmutableMap.builder();
int headerCount = readVarint(messageHeader);
for (int i = 0; i < headerCount; i++) {
String key = readString(messageHeader);
String value = readString(messageHeader);
headers.put(key, value);
}
return headers.build();
}
示例3: readVarInt
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static int readVarInt(ByteBuf buf, int maxSize) {
Validate.isTrue(maxSize < 6 && maxSize > 0, "Varint length is between 1 and 5, not %d", maxSize);
int i = 0;
int j = 0;
byte b0;
do {
b0 = buf.readByte();
i |= (b0 & 127) << j++ * 7;
if (j > maxSize) {
throw new RuntimeException("VarInt too big");
}
}
while ((b0 & 128) == 128);
return i;
}
示例4: channelRead0
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
while (true) {
if (byteBuf.readableBytes() < FrameSetting.FRAME_HEAD_LENGTH) {
return;
}
if (byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_1
|| byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_2) {
return;
}
int groupId = byteBuf.readByte() & 0xFF;
int msgId = byteBuf.readByte() & 0xFF;
int deviceId = byteBuf.readByte() & 0xFF;
int backupMsg = byteBuf.readByte() & 0xFF;
int dataLength = byteBuf.readShort() & 0xFF;
FrameMajorHeader headMsg = new FrameMajorHeader(msgId, groupId, deviceId, dataLength, backupMsg);
ByteBuf subBuf = ctx.alloc().buffer(dataLength);
byteBuf.readBytes(subBuf, dataLength);
ctx.fireChannelRead(new FrameMajor(headMsg, subBuf));
}
}
示例5: readBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public ByteBuf readBytes(ByteBuf is) throws IOException {
long l = readLong(is);
if (l > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
"Java only supports arrays up to " + Integer.MAX_VALUE + " in size");
}
int size = (int) l;
if (size == -1) {
return null;
}
ByteBuf buffer = is.readSlice(size);
int cr = is.readByte();
int lf = is.readByte();
if (cr != CR || lf != LF) {
throw new IOException("Improper line ending: " + cr + ", " + lf);
}
return buffer;
}
示例6: onRawPacketSending
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void onRawPacketSending(RawPacketEvent event) {
super.onRawPacketSending(event);
ByteBuf data = event.getData();
int packetId = VarNumberSerializer.readVarInt(data);
if (packetId != PEPacketIDs.SPAWN_PLAYER)
return;
data.readByte();
data.readByte();
MiscSerializer.readUUID(data);
String name = StringSerializer.readString(data, con.getVersion());
long entityId = VarNumberSerializer.readSVarLong(data);
cachedUsers.put(name, (int) entityId);
}
示例7: encodeCallingParameter
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void encodeCallingParameter() throws Exception {
ChannelHandlerContext ctx = new MockChannelHandlerContext();
ByteBuf buf = Unpooled.buffer();
ArrayList<Parameter> parmameters = new ArrayList<>();
CallingTsapParameter callingParameter = new CallingTsapParameter(DeviceGroup.PG_OR_PC, (byte) 0x7, (byte) 0xe1); // slot number too big and overflows into rack
parmameters.add(callingParameter);
ErrorTpdu tpdu = new ErrorTpdu((short)0x1, RejectCause.REASON_NOT_SPECIFIED, parmameters, buf);
ArrayList<Object> out = new ArrayList<>();
isoTPProtocol.encode(ctx, tpdu, out);
assertTrue(out.size() == 1, "Message not decoded");
ByteBuf userData = ((IsoOnTcpMessage)out.get(0)).getUserData();
assertTrue(userData.writerIndex() == 9, "Incorrect message length");
assertTrue(userData.readByte() == (byte)0x8, "Incorrect header length");
assertTrue(userData.readByte() == TpduCode.TPDU_ERROR.getCode(), "Incorrect Tpdu code");
assertTrue(userData.readShort() == (short)0x1, "Incorrect destination reference code");
assertTrue(userData.readByte() == RejectCause.REASON_NOT_SPECIFIED.getCode(), "Incorrect reject cause code");
assertTrue(userData.readByte() == ParameterCode.CALLING_TSAP.getCode(), "Incorrect parameter code");
assertTrue(userData.readByte() == (byte)0x2, "Incorrect parameter length");
assertTrue(userData.readByte() == DeviceGroup.PG_OR_PC.getCode(), "Incorrect device group code");
byte rackAndSlot = userData.readByte();
assertTrue((rackAndSlot & 0xf0) >> 4 == 0x7, "Incorrect rack number");
assertTrue((rackAndSlot & 0x0f) == (0xe1 & 0x0f), "Incorrect slot number");
}
示例8: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* Decodes the machine information of the user during the {@link WorldLoginDecoder}.
*
* @param buffer The {@link ByteBuf}.
* @return The created machine information.
*/
public static MachineInformation decode(ByteBuf buffer) {
buffer.readByte();
int osArch = buffer.readByte();
boolean is64Bit = buffer.readByte() == 1;
int osBuild = buffer.readByte();
int vendor = buffer.readByte();
buffer.readByte();
buffer.readByte();
buffer.readByte();
buffer.readByte();
buffer.readShort();
buffer.readByte();
buffer.readMedium();
buffer.readShort();
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
buffer.readByte();
buffer.readShort();
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
buffer.readByte();
buffer.readByte();
return new MachineInformation(osArch, is64Bit, osBuild, vendor);
}
示例9: fromBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void fromBytes(ByteBuf buf)
{
player = buf.readInt();
where = ContainingInventory.VALUES[buf.readByte()];
slot = buf.readByte();
stack = ByteBufUtils.readItemStack(buf);
}
示例10: fromBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void fromBytes(ByteBuf buf) {
selectedBlock = BlockPos.fromLong(buf.readLong());
selectedSide = EnumFacing.VALUES[buf.readByte()];
destination = new TeleportDestination(NetworkTools.readStringUTF8(buf), buf.readInt(), BlockPos.fromLong(buf.readLong()),
EnumFacing.VALUES[buf.readByte()]);
}
示例11: readLine
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private String readLine(ByteBuf in) {
while (in.isReadable()) {
byte b = in.readByte();
byteBuf.writeByte(b);
lineBuf.append((char) b);
int len = lineBuf.length();
if (len >= 2 && lineBuf.substring(len - 2).equals("\r\n")) {
String line = lineBuf.substring(0, len - 2);
lineBuf.delete(0, len);
return line;
}
}
return null;
}
示例12: readFromBuf
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static AnimaStack readFromBuf(ByteBuf from)
{
int count = from.readByte();
int id = from.readShort();
if (count < 0)
{
return AnimaStack.EMPTY;
} else
{
AnimaStack stack = new AnimaStack(Anima.getAnimaByID(id), count);
return stack;
}
}
示例13: readField
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static Object readField(ByteBuf buf, int type) {
switch (type) {
case 0:
return buf.readInt();
case 1:
return buf.readFloat();
case 2:
return buf.readDouble();
case 3:
return buf.readBoolean();
case 4:
return ByteBufUtils.readUTF8String(buf);
case 5:
return buf.readByte();
case 6:
return ByteBufUtils.readItemStack(buf);
case 7:
if (!buf.readBoolean()) return null;
return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
case 8:
try {
PacketBuffer packetBuffer = new PacketBuffer(buf);
NBTTagCompound tag = packetBuffer.readCompoundTag();
if (tag == null) return EmptyHandler.INSTANCE;
ItemStackHandler handler = new ItemStackHandler();
handler.deserializeNBT(tag);
return handler;
} catch (IOException e) {
return EmptyHandler.INSTANCE;
}
}
throw new IllegalArgumentException("Invalid sync type! " + type);
}
示例14: parseBooleanValue
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* Parse Single-point information with quality descriptor
*
* @param withTimestamp
* <code>true</code> if the time should be parsed as well,
* <code>false</code> otherwise
*/
public static Value<Boolean> parseBooleanValue ( final ProtocolOptions options, final ByteBuf data, final boolean withTimestamp )
{
final byte siq = data.readByte ();
final Boolean value = ( siq & 0x01 ) > 0 ? Boolean.TRUE : Boolean.FALSE; // we need to use a boolean object due to the following generic object
final QualityInformation qualityInformation = QualityInformation.parse ( siq );
final long timestamp = withTimestamp ? parseTimestamp ( options, data ) : System.currentTimeMillis ();
return new Value<Boolean> ( value, timestamp, qualityInformation );
}
示例15: readString
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* Converts data from a {@link ByteBuf} into a readable string.
*
* @param buffer The {@link ByteBuf}.
* @return The string.
*/
public static String readString(ByteBuf buffer) {
StringBuilder bldr = new StringBuilder();
byte b;
while (buffer.isReadable() && (b = buffer.readByte()) != STRING_TERMINATOR) {
bldr.append((char) b);
}
return bldr.toString();
}