2014-05-15 23:05:20 +00:00
|
|
|
package org.capnproto;
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
2014-05-19 12:43:58 +00:00
|
|
|
public final class MessageReader {
|
2014-06-18 01:06:50 +00:00
|
|
|
final ReaderArena arena;
|
2014-10-08 19:16:17 +00:00
|
|
|
final int nestingLimit;
|
2014-05-15 23:05:20 +00:00
|
|
|
|
2014-10-08 19:16:17 +00:00
|
|
|
final static long DEFAULT_TRAVERSAL_LIMIT_IN_WORDS = 8 * 1024 * 1024;
|
|
|
|
final static int DEFAULT_NESTING_LIMIT = 64;
|
|
|
|
|
|
|
|
public MessageReader(ByteBuffer[] segmentSlices, long traversalLimitInWords, int nestingLimit) {
|
|
|
|
this.nestingLimit = nestingLimit;
|
|
|
|
this.arena = new ReaderArena(segmentSlices, traversalLimitInWords);
|
2014-05-15 23:05:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 02:35:08 +00:00
|
|
|
public <T> T getRoot(FromPointerReader<T> factory) {
|
2014-06-18 01:06:50 +00:00
|
|
|
SegmentReader segment = this.arena.tryGetSegment(0);
|
2014-10-08 19:16:17 +00:00
|
|
|
AnyPointer.Reader any = new AnyPointer.Reader(segment, 0, this.nestingLimit);
|
2014-10-08 02:35:08 +00:00
|
|
|
return any.getAs(factory);
|
2014-05-15 23:05:20 +00:00
|
|
|
}
|
|
|
|
}
|