List of usage examples for io.netty.buffer ByteBuf getBytes
public abstract int getBytes(int index, FileChannel out, long position, int length) throws IOException;
From source file:se.sics.kompics.network.netty.serialization.ProtobufSerializer.java
License:Open Source License
@Override public Object fromBinary(ByteBuf msg, Optional<Class> hint) { final byte[] array; final int offset; final int length = msg.readableBytes(); if (msg.hasArray()) { array = msg.array();/*w w w .j av a 2s . c o m*/ offset = msg.arrayOffset() + msg.readerIndex(); } else { array = new byte[length]; msg.getBytes(msg.readerIndex(), array, 0, length); offset = 0; } Object o = null; try { if (extensionRegistry == null) { if (HAS_PARSER) { o = prototype.getParserForType().parseFrom(array, offset, length); } else { o = prototype.newBuilderForType().mergeFrom(array, offset, length).build(); } } else { if (HAS_PARSER) { o = prototype.getParserForType().parseFrom(array, offset, length, extensionRegistry); } else { o = prototype.newBuilderForType().mergeFrom(array, offset, length, extensionRegistry).build(); } } } catch (InvalidProtocolBufferException ex) { Serializers.LOG.error("ProtobufSerializer: Couldn't deserialize object.", ex); } return o; }