• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 package com.google.protobuf;
32 
33 import java.io.IOException;
34 
35 class UnknownFieldSetLiteSchema
36     extends UnknownFieldSchema<UnknownFieldSetLite, UnknownFieldSetLite> {
37 
UnknownFieldSetLiteSchema()38   UnknownFieldSetLiteSchema() {}
39 
40   @Override
shouldDiscardUnknownFields(Reader reader)41   boolean shouldDiscardUnknownFields(Reader reader) {
42     // We never drop unknown fields in lite.
43     return false;
44   }
45 
46   @Override
newBuilder()47   UnknownFieldSetLite newBuilder() {
48     return UnknownFieldSetLite.newInstance();
49   }
50 
51   @Override
addVarint(UnknownFieldSetLite fields, int number, long value)52   void addVarint(UnknownFieldSetLite fields, int number, long value) {
53     fields.storeField(WireFormat.makeTag(number, WireFormat.WIRETYPE_VARINT), value);
54   }
55 
56   @Override
addFixed32(UnknownFieldSetLite fields, int number, int value)57   void addFixed32(UnknownFieldSetLite fields, int number, int value) {
58     fields.storeField(WireFormat.makeTag(number, WireFormat.WIRETYPE_FIXED32), value);
59   }
60 
61   @Override
addFixed64(UnknownFieldSetLite fields, int number, long value)62   void addFixed64(UnknownFieldSetLite fields, int number, long value) {
63     fields.storeField(WireFormat.makeTag(number, WireFormat.WIRETYPE_FIXED64), value);
64   }
65 
66   @Override
addLengthDelimited(UnknownFieldSetLite fields, int number, ByteString value)67   void addLengthDelimited(UnknownFieldSetLite fields, int number, ByteString value) {
68     fields.storeField(WireFormat.makeTag(number, WireFormat.WIRETYPE_LENGTH_DELIMITED), value);
69   }
70 
71   @Override
addGroup(UnknownFieldSetLite fields, int number, UnknownFieldSetLite subFieldSet)72   void addGroup(UnknownFieldSetLite fields, int number, UnknownFieldSetLite subFieldSet) {
73     fields.storeField(WireFormat.makeTag(number, WireFormat.WIRETYPE_START_GROUP), subFieldSet);
74   }
75 
76   @Override
toImmutable(UnknownFieldSetLite fields)77   UnknownFieldSetLite toImmutable(UnknownFieldSetLite fields) {
78     fields.makeImmutable();
79     return fields;
80   }
81 
82   @Override
setToMessage(Object message, UnknownFieldSetLite fields)83   void setToMessage(Object message, UnknownFieldSetLite fields) {
84     ((GeneratedMessageLite<?, ?>) message).unknownFields = fields;
85   }
86 
87   @Override
getFromMessage(Object message)88   UnknownFieldSetLite getFromMessage(Object message) {
89     return ((GeneratedMessageLite<?, ?>) message).unknownFields;
90   }
91 
92   @Override
getBuilderFromMessage(Object message)93   UnknownFieldSetLite getBuilderFromMessage(Object message) {
94     UnknownFieldSetLite unknownFields = getFromMessage(message);
95     // When parsing into a lite message object, its UnknownFieldSet is either the default instance
96     // or mutable. It can't be in a state where it's immutable but not default instance.
97     if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) {
98       unknownFields = UnknownFieldSetLite.newInstance();
99       setToMessage(message, unknownFields);
100     }
101     return unknownFields;
102   }
103 
104   @Override
setBuilderToMessage(Object message, UnknownFieldSetLite fields)105   void setBuilderToMessage(Object message, UnknownFieldSetLite fields) {
106     setToMessage(message, fields);
107   }
108 
109   @Override
makeImmutable(Object message)110   void makeImmutable(Object message) {
111     getFromMessage(message).makeImmutable();
112   }
113 
114   @Override
writeTo(UnknownFieldSetLite fields, Writer writer)115   void writeTo(UnknownFieldSetLite fields, Writer writer) throws IOException {
116     fields.writeTo(writer);
117   }
118 
119   @Override
writeAsMessageSetTo(UnknownFieldSetLite fields, Writer writer)120   void writeAsMessageSetTo(UnknownFieldSetLite fields, Writer writer) throws IOException {
121     fields.writeAsMessageSetTo(writer);
122   }
123 
124   @Override
merge(UnknownFieldSetLite message, UnknownFieldSetLite other)125   UnknownFieldSetLite merge(UnknownFieldSetLite message, UnknownFieldSetLite other) {
126     return other.equals(UnknownFieldSetLite.getDefaultInstance())
127         ? message
128         : UnknownFieldSetLite.mutableCopyOf(message, other);
129   }
130 
131   @Override
getSerializedSize(UnknownFieldSetLite unknowns)132   int getSerializedSize(UnknownFieldSetLite unknowns) {
133     return unknowns.getSerializedSize();
134   }
135 
136   @Override
getSerializedSizeAsMessageSet(UnknownFieldSetLite unknowns)137   int getSerializedSizeAsMessageSet(UnknownFieldSetLite unknowns) {
138     return unknowns.getSerializedSizeAsMessageSet();
139   }
140 }
141