diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index aac8078..7c2e139 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -1251,6 +1251,9 @@ private: structNode.getDiscriminantOffset(), ")];\n", spaces(indent), " }\n") : kj::strTree()), + spaces(indent), " public final Reader asReader() {\n", + spaces(indent), " return new Reader(this._builder.asReader());\n", + spaces(indent), " }\n", kj::mv(methodDecls), spaces(indent), "}\n", "\n"); diff --git a/runtime/src/main/java/org/capnproto/WireHelpers.java b/runtime/src/main/java/org/capnproto/WireHelpers.java index f26bc1c..1f0c2f6 100644 --- a/runtime/src/main/java/org/capnproto/WireHelpers.java +++ b/runtime/src/main/java/org/capnproto/WireHelpers.java @@ -112,7 +112,26 @@ final class WireHelpers { //# so there are no FAR pointers. if (segment != null && WirePointer.kind(ref) == WirePointer.FAR) { - throw new Error("unimplemented"); + SegmentReader resultSegment = segment.arena.tryGetSegment(FarPointer.getSegmentId(ref)); + + int ptr = FarPointer.positionInSegment(ref); + + int padWords = FarPointer.isDoubleFar(ref) ? 2 : 1; + // TODO read limiting + + int pad = ptr; + + if (!FarPointer.isDoubleFar(ref)) { + + return new FollowFarsResult(WirePointer.target(pad, + WirePointer.get(resultSegment.buffer, pad)), + pad, resultSegment); + } else { + //# Landing pad is another far pointer. It is + //# followed by a tag describing the pointed-to + //# object. + throw new Error("unimplemented"); + } } else { return new FollowFarsResult(refTarget, ref, segment);