From 00cc63dfe88b7590739e600b9f0c91f9fcda9cef Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Sun, 16 Nov 2014 14:14:15 -0500 Subject: [PATCH] reading double far pointers --- .../org/capnproto/benchmark/Benchmark.java | 28 ------------------- .../scala/org/capnproto/EncodingTest.scala | 14 +++++++++- .../main/java/org/capnproto/WireHelpers.java | 7 +++-- 3 files changed, 17 insertions(+), 32 deletions(-) delete mode 100644 benchmark/src/main/java/org/capnproto/benchmark/Benchmark.java diff --git a/benchmark/src/main/java/org/capnproto/benchmark/Benchmark.java b/benchmark/src/main/java/org/capnproto/benchmark/Benchmark.java deleted file mode 100644 index 9742c90..0000000 --- a/benchmark/src/main/java/org/capnproto/benchmark/Benchmark.java +++ /dev/null @@ -1,28 +0,0 @@ -// 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.benchmark; - -public class Benchmark { - public static void main(String[] args) { - System.out.println("hello world"); - } -} diff --git a/compiler/src/test/scala/org/capnproto/EncodingTest.scala b/compiler/src/test/scala/org/capnproto/EncodingTest.scala index c998a85..8ccff1b 100644 --- a/compiler/src/test/scala/org/capnproto/EncodingTest.scala +++ b/compiler/src/test/scala/org/capnproto/EncodingTest.scala @@ -26,7 +26,6 @@ import org.scalatest.FunSuite import org.scalatest.Matchers._; class EncodingSuite extends FunSuite { - test("AllTypes") { val message = new MessageBuilder(); val allTypes = message.initRoot(TestAllTypes.factory); @@ -86,6 +85,19 @@ class EncodingSuite extends FunSuite { } } + test("DoubleFarPointers") { + val bytes = Array[Byte](2,0,0,0, 1,0,0,0, 2,0,0,0, 1,0,0,0, + 6,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0, + 0,0,0,0, 1,0,0,0, 1,7, -1, 127, 0,0,0,0); + + val input = new ArrayInputStream (java.nio.ByteBuffer.wrap(bytes)); + val message = org.capnproto.Serialize.read(input); + val root = message.getRoot(TestAllTypes.factory); + root.getBoolField() should equal (true); + root.getInt8Field() should equal (7); + root.getInt16Field() should equal (32767); + } + test("Generics") { val message = new MessageBuilder(); val factory = TestGenerics.newFactory(TestAllTypes.factory, Text.factory); diff --git a/runtime/src/main/java/org/capnproto/WireHelpers.java b/runtime/src/main/java/org/capnproto/WireHelpers.java index 91f27c5..2b368a4 100644 --- a/runtime/src/main/java/org/capnproto/WireHelpers.java +++ b/runtime/src/main/java/org/capnproto/WireHelpers.java @@ -143,7 +143,6 @@ final class WireHelpers { //# so there are no FAR pointers. if (segment != null && WirePointer.kind(ref) == WirePointer.FAR) { SegmentReader resultSegment = segment.arena.tryGetSegment(FarPointer.getSegmentId(ref)); - int padOffset = FarPointer.positionInSegment(ref); long pad = resultSegment.get(padOffset); @@ -158,9 +157,11 @@ final class WireHelpers { //# Landing pad is another far pointer. It is //# followed by a tag describing the pointed-to //# object. - throw new Error("unimplemented"); - } + long tag = resultSegment.get(padOffset + 1); + resultSegment = resultSegment.arena.tryGetSegment(FarPointer.getSegmentId(pad)); + return new FollowFarsResult(FarPointer.positionInSegment(pad), tag, resultSegment); + } } else { return new FollowFarsResult(refTarget, ref, segment); }