use of io.netty.handler.codec.DecoderException in project LanternServer by LanternPowered.
the class AbstractCodecPlayInOutCustomPayload method decode.
@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
final String channel = buf.readLimitedString(LanternChannelRegistrar.MAX_NAME_LENGTH);
final int length = buf.available();
if (length > Short.MAX_VALUE) {
throw new DecoderException("CustomPayload messages may not be longer then " + Short.MAX_VALUE + " bytes");
}
final ByteBuffer content = buf.slice();
final Message message = decode0(context, content, channel);
if (content.available() > 0) {
Lantern.getLogger().warn("Trailing bytes {}b after decoding with custom payload message codec {} with channel {}!\n{}", content.available(), getClass().getName(), channel, message);
}
// Skip all the bytes, we already processed them
buf.setReadIndex(buf.readerIndex() + buf.available());
return message;
}
use of io.netty.handler.codec.DecoderException in project LanternServer by LanternPowered.
the class CodecPlayInPlayerDigging method decode.
@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
int action = buf.readByte();
Vector3i position = buf.read(Types.VECTOR_3_I);
int face = buf.readByte();
switch(action) {
case 0:
case 1:
case 2:
return new MessagePlayInPlayerDigging(MessagePlayInPlayerDigging.Action.values()[action], position, fromFace(face));
case 3:
case 4:
return new MessagePlayInDropHeldItem(action == 3);
case 5:
return new MessagePlayInOutFinishUsingItem();
case 6:
return new MessagePlayInSwapHandItems();
default:
throw new DecoderException("Unknown player digging message action: " + action);
}
}
use of io.netty.handler.codec.DecoderException in project scalecube by scalecube.
the class MessageCodec method deserialize.
/**
* Deserializes message from given byte buffer.
*
* @param bb byte buffer
*/
public static Message deserialize(ByteBuf bb) {
Schema<Message> schema = RuntimeSchema.getSchema(Message.class);
Message message = schema.newMessage();
try {
ProtostuffIOUtil.mergeFrom(new ByteBufInputStream(bb), message, schema);
} catch (Exception e) {
throw new DecoderException(e.getMessage(), e);
}
return message;
}
use of io.netty.handler.codec.DecoderException in project graylog2-server by Graylog2.
the class SyslogOctetCountFrameDecoderTest method testBrokenFrames.
@Test
public void testBrokenFrames() throws Exception {
final ByteBuf buf = Unpooled.copiedBuffer("1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - ", StandardCharsets.US_ASCII);
try {
channel.writeInbound(buf);
fail("Expected DecoderException");
} catch (DecoderException e) {
assertTrue(e.getCause() instanceof NumberFormatException);
channel.close().sync().await();
}
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class Socks4ServerDecoder method fail.
private void fail(List<Object> out, Exception cause) {
if (!(cause instanceof DecoderException)) {
cause = new DecoderException(cause);
}
Socks4CommandRequest m = new DefaultSocks4CommandRequest(type != null ? type : Socks4CommandType.CONNECT, dstAddr != null ? dstAddr : "", dstPort != 0 ? dstPort : 65535, userId != null ? userId : "");
m.setDecoderResult(DecoderResult.failure(cause));
out.add(m);
checkpoint(State.FAILURE);
}
Aggregations