Stephan Herhut | 3f026d3 | 2017-08-07 14:58:13 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package nestedproto1; |
| 5 | |
| 6 | import java.io.ByteArrayInputStream; |
| 7 | import java.io.IOException; |
| 8 | import nestedproto1.GeneratedNestedProto.Outer; |
| 9 | |
| 10 | public class Nestedproto { |
| 11 | |
| 12 | private static final byte[] NESTED_MESSAGE_WITH_BOTH = new byte[] {25, 8, 42, 18, 12, 8, 1, 18, 8, |
| 13 | 105, 110, 110, 101, 114, 79, 110, 101, 26, 7, 8, 2, 21, 0, 0, -10, 66}; |
| 14 | |
| 15 | private static final byte[] NESTED_MESSAGE_WITH_ONE = new byte[]{16, 8, 42, 18, 12, 8, 1, 18, 8, |
| 16 | 105, |
| 17 | 110, 110, 101, 114, 79, 110, 101}; |
| 18 | |
| 19 | public static void main(String... args) throws IOException { |
| 20 | testWith(NESTED_MESSAGE_WITH_BOTH); |
| 21 | testWith(NESTED_MESSAGE_WITH_ONE); |
| 22 | } |
| 23 | |
| 24 | public static void testWith(byte[] data) throws IOException { |
| 25 | ByteArrayInputStream input = new ByteArrayInputStream(data); |
| 26 | Outer.Builder builder = Outer.newBuilder(); |
| 27 | builder.mergeDelimitedFrom(input); |
| 28 | Outer outer = builder.build(); |
| 29 | System.out.println(outer.getInner().getOther()); |
| 30 | } |
| 31 | } |