OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 * compiled before the new types were added. | 50 * compiled before the new types were added. |
51 * | 51 * |
52 * <p>Every {@link Message} contains an {@code UnknownFieldSet} (and every | 52 * <p>Every {@link Message} contains an {@code UnknownFieldSet} (and every |
53 * {@link Message.Builder} contains an {@link Builder}). | 53 * {@link Message.Builder} contains an {@link Builder}). |
54 * | 54 * |
55 * <p>Most users will never need to use this class. | 55 * <p>Most users will never need to use this class. |
56 * | 56 * |
57 * @author kenton@google.com Kenton Varda | 57 * @author kenton@google.com Kenton Varda |
58 */ | 58 */ |
59 public final class UnknownFieldSet implements MessageLite { | 59 public final class UnknownFieldSet implements MessageLite { |
60 | |
61 private UnknownFieldSet() {} | 60 private UnknownFieldSet() {} |
62 | 61 |
63 /** Create a new {@link Builder}. */ | 62 /** Create a new {@link Builder}. */ |
64 public static Builder newBuilder() { | 63 public static Builder newBuilder() { |
65 return Builder.create(); | 64 return Builder.create(); |
66 } | 65 } |
67 | 66 |
68 /** | 67 /** |
69 * Create a new {@link Builder} and initialize it to be a copy | 68 * Create a new {@link Builder} and initialize it to be a copy |
70 * of {@code copyFrom}. | 69 * of {@code copyFrom}. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 */ | 123 */ |
125 public Field getField(final int number) { | 124 public Field getField(final int number) { |
126 final Field result = fields.get(number); | 125 final Field result = fields.get(number); |
127 return (result == null) ? Field.getDefaultInstance() : result; | 126 return (result == null) ? Field.getDefaultInstance() : result; |
128 } | 127 } |
129 | 128 |
130 /** Serializes the set and writes it to {@code output}. */ | 129 /** Serializes the set and writes it to {@code output}. */ |
131 @Override | 130 @Override |
132 public void writeTo(final CodedOutputStream output) throws IOException { | 131 public void writeTo(final CodedOutputStream output) throws IOException { |
133 for (final Map.Entry<Integer, Field> entry : fields.entrySet()) { | 132 for (final Map.Entry<Integer, Field> entry : fields.entrySet()) { |
134 Field field = entry.getValue(); | 133 entry.getValue().writeTo(entry.getKey(), output); |
135 field.writeTo(entry.getKey(), output); | |
136 } | 134 } |
137 } | 135 } |
138 | 136 |
139 /** | 137 /** |
140 * Converts the set to a string in protocol buffer text format. This is | 138 * Converts the set to a string in protocol buffer text format. This is |
141 * just a trivial wrapper around | 139 * just a trivial wrapper around |
142 * {@link TextFormat#printToString(UnknownFieldSet)}. | 140 * {@link TextFormat#printToString(UnknownFieldSet)}. |
143 */ | 141 */ |
144 @Override | 142 @Override |
145 public String toString() { | 143 public String toString() { |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 @Override | 1013 @Override |
1016 public UnknownFieldSet parsePartialFrom( | 1014 public UnknownFieldSet parsePartialFrom( |
1017 CodedInputStream input, ExtensionRegistryLite extensionRegistry) | 1015 CodedInputStream input, ExtensionRegistryLite extensionRegistry) |
1018 throws InvalidProtocolBufferException { | 1016 throws InvalidProtocolBufferException { |
1019 Builder builder = newBuilder(); | 1017 Builder builder = newBuilder(); |
1020 try { | 1018 try { |
1021 builder.mergeFrom(input); | 1019 builder.mergeFrom(input); |
1022 } catch (InvalidProtocolBufferException e) { | 1020 } catch (InvalidProtocolBufferException e) { |
1023 throw e.setUnfinishedMessage(builder.buildPartial()); | 1021 throw e.setUnfinishedMessage(builder.buildPartial()); |
1024 } catch (IOException e) { | 1022 } catch (IOException e) { |
1025 throw new InvalidProtocolBufferException(e) | 1023 throw new InvalidProtocolBufferException(e.getMessage()) |
1026 .setUnfinishedMessage(builder.buildPartial()); | 1024 .setUnfinishedMessage(builder.buildPartial()); |
1027 } | 1025 } |
1028 return builder.buildPartial(); | 1026 return builder.buildPartial(); |
1029 } | 1027 } |
1030 } | 1028 } |
1031 | 1029 |
1032 private static final Parser PARSER = new Parser(); | 1030 private static final Parser PARSER = new Parser(); |
1033 @Override | 1031 @Override |
1034 public final Parser getParserForType() { | 1032 public final Parser getParserForType() { |
1035 return PARSER; | 1033 return PARSER; |
1036 } | 1034 } |
1037 } | 1035 } |
OLD | NEW |