// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors // Licensed under the MIT License: // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. package org.capnproto; public final class AnyPointer { public final static class Reader { final SegmentReader segment; final int pointer; // offset in words final int nestingLimit; public Reader(SegmentReader segment, int pointer, int nestingLimit) { this.segment = segment; this.pointer = pointer; this.nestingLimit = nestingLimit; } public final boolean isNull() { return WirePointer.isNull(this.segment.buffer.getLong(this.pointer * Constants.BYTES_PER_WORD)); } public final T getAs(FromPointerReader factory) { return factory.fromPointerReader(this.segment, this.pointer, this.nestingLimit); } } public static final class Builder { final SegmentBuilder segment; final int pointer; public Builder(SegmentBuilder segment, int pointer) { this.segment = segment; this.pointer = pointer; } public final boolean isNull() { return WirePointer.isNull(this.segment.buffer.getLong(this.pointer * Constants.BYTES_PER_WORD)); } public final T getAs(FromPointerBuilder factory) { return factory.fromPointerBuilder(this.segment, this.pointer); } public final T initAs(InitFromPointerBuilder factory) { return factory.initFromPointerBuilder(this.segment, this.pointer); } public final T initAs(InitSizedFromPointerBuilder factory, int elementCount) { return factory.initSizedFromPointerBuilder(this.segment, this.pointer, elementCount); } public final void clear() { WireHelpers.zeroObject(this.segment, this.pointer); this.segment.buffer.putLong(this.pointer * 8, 0L); } } }