本文整理汇总了Java中io.netty.buffer.ByteBuf.order方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.order方法的具体用法?Java ByteBuf.order怎么用?Java ByteBuf.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.order方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUnadjustedFrameLength
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* Decodes the specified region of the buffer into an unadjusted frame length. The default implementation is
* capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer. Override this method to
* decode the length field encoded differently. Note that this method must not modify the state of the specified
* buffer (e.g. {@code readerIndex}, {@code writerIndex}, and the content of the buffer.)
*
* @throws DecoderException
* if failed to decode the specified region
*/
protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) {
buf = buf.order(order);
long frameLength;
switch (length) {
case 1:
frameLength = buf.getUnsignedByte(offset);
break;
case 2:
frameLength = buf.getUnsignedShort(offset);
break;
case 3:
frameLength = buf.getUnsignedMedium(offset);
break;
case 4:
frameLength = buf.getUnsignedInt(offset);
break;
case 8:
frameLength = buf.getLong(offset);
break;
default:
throw new DecoderException(
"unsupported lengthFieldLength: " + lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)");
}
return frameLength;
}
示例2: handleIFormat
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void handleIFormat ( final InformationTransfer msg, ByteBuf out )
{
final ByteBuf data = msg.getData ();
try
{
out = out.order ( ByteOrder.LITTLE_ENDIAN );
final int len = data.readableBytes ();
if ( len > Constants.APCI_MAX_DATA_LENGTH )
{
throw new EncoderException ( String.format ( "Packet too big - %s bytes", len ) );
}
out.ensureWritable ( 6 + len );
out.writeByte ( Constants.START_BYTE );
out.writeByte ( 4 + len );
out.writeShort ( msg.getSendSequenceNumber () << 1 );
out.writeShort ( msg.getReceiveSequenceNumber () << 1 );
out.writeBytes ( data );
}
finally
{
ReferenceCountUtil.release ( msg.getData () );
}
}
示例3: handleSFormat
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void handleSFormat ( final Supervisory msg, ByteBuf out )
{
out = out.order ( ByteOrder.LITTLE_ENDIAN );
out.ensureWritable ( 6 );
out.writeByte ( Constants.START_BYTE );
out.writeByte ( 4 );
out.writeBytes ( new byte[] { 0x01, 0x00 } );
out.writeShort ( msg.getReceiveSequenceNumber () << 1 );
}
示例4: encodeMessage
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public void encodeMessage ( final Object msg, ByteBuf buf )
{
logger.debug ( "Encode message: {}", msg );
final ASDU asdu = msg.getClass ().getAnnotation ( ASDU.class );
if ( asdu == null )
{
throw new IllegalStateException ( String.format ( "Unable to send message of type %s, no %s annotation found", msg.getClass (), ASDU.class.getName () ) );
}
final MessageCodec codec = this.codecs.get ( new MessageTypeId ( asdu.id (), asdu.informationStructure () ) );
if ( codec == null )
{
throw new IllegalStateException ( String.format ( "Unable to send message of type %s, no codec is registered", msg.getClass () ) );
}
try
{
buf = buf.order ( ByteOrder.LITTLE_ENDIAN );
codec.encode ( this.options, msg, buf );
logger.debug ( "Encoded to {} bytes", buf.writerIndex () );
}
catch ( final Exception e )
{
logger.warn ( "Failed to encode message", e );
throw new RuntimeException ( e );
}
}
示例5: 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();
}
}
示例6: readUTF16
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String readUTF16(ByteBuf in) {
in = in.order(ByteOrder.BIG_ENDIAN);
ByteBuf buffer = in.alloc().buffer();
char chr;
while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) {
buffer.writeChar(chr);
}
return buffer.toString(Charsets.UTF_16LE);
}
示例7: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
{
if ((in == null) || !in.isReadable())
{
return;
}
if (in.order() != _byteOrder)
{
in = in.order(_byteOrder);
}
try
{
final short packetId = in.readUnsignedByte();
if (packetId >= _incomingPackets.length)
{
LOGGER.finer("Unknown packet: " + Integer.toHexString(packetId));
return;
}
final IIncomingPackets<T> incomingPacket = _incomingPackets[packetId];
if (incomingPacket == null)
{
LOGGER.finer("Unknown packet: " + Integer.toHexString(packetId));
return;
}
final IConnectionState connectionState = ctx.channel().attr(IConnectionState.ATTRIBUTE_KEY).get();
if ((connectionState == null) || !incomingPacket.getConnectionStates().contains(connectionState))
{
// LOGGER.warning(incomingPacket + ": Connection at invalid state: " + connectionState + " Required States: " + incomingPacket.getConnectionStates());
return;
}
final IIncomingPacket<T> packet = incomingPacket.newIncomingPacket();
if ((packet != null) && packet.read(_client, new PacketReader(in)))
{
out.add(packet);
}
}
finally
{
// We always consider that we read whole packet.
in.readerIndex(in.writerIndex());
}
}