• 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 import java.util.List;
35 import java.util.Map;
36 
37 /** A writer that performs serialization of protobuf message fields. */
38 @ExperimentalApi
39 interface Writer {
40 
41   /** The order in which the fields are written by a {@link Writer}. */
42   enum FieldOrder {
43     /** Fields are written in ascending order by field number. */
44     ASCENDING,
45 
46     /** Fields are written in descending order by field number. */
47     DESCENDING
48   }
49 
50   /** Indicates the order in which the fields are written by this {@link Writer}. */
fieldOrder()51   FieldOrder fieldOrder();
52 
53   /** Writes a field of type {@link FieldType#SFIXED32}. */
writeSFixed32(int fieldNumber, int value)54   void writeSFixed32(int fieldNumber, int value) throws IOException;
55 
56   /** Writes a field of type {@link FieldType#INT64}. */
writeInt64(int fieldNumber, long value)57   void writeInt64(int fieldNumber, long value) throws IOException;
58 
59   /** Writes a field of type {@link FieldType#SFIXED64}. */
writeSFixed64(int fieldNumber, long value)60   void writeSFixed64(int fieldNumber, long value) throws IOException;
61 
62   /** Writes a field of type {@link FieldType#FLOAT}. */
writeFloat(int fieldNumber, float value)63   void writeFloat(int fieldNumber, float value) throws IOException;
64 
65   /** Writes a field of type {@link FieldType#DOUBLE}. */
writeDouble(int fieldNumber, double value)66   void writeDouble(int fieldNumber, double value) throws IOException;
67 
68   /** Writes a field of type {@link FieldType#ENUM}. */
writeEnum(int fieldNumber, int value)69   void writeEnum(int fieldNumber, int value) throws IOException;
70 
71   /** Writes a field of type {@link FieldType#UINT64}. */
writeUInt64(int fieldNumber, long value)72   void writeUInt64(int fieldNumber, long value) throws IOException;
73 
74   /** Writes a field of type {@link FieldType#INT32}. */
writeInt32(int fieldNumber, int value)75   void writeInt32(int fieldNumber, int value) throws IOException;
76 
77   /** Writes a field of type {@link FieldType#FIXED64}. */
writeFixed64(int fieldNumber, long value)78   void writeFixed64(int fieldNumber, long value) throws IOException;
79 
80   /** Writes a field of type {@link FieldType#FIXED32}. */
writeFixed32(int fieldNumber, int value)81   void writeFixed32(int fieldNumber, int value) throws IOException;
82 
83   /** Writes a field of type {@link FieldType#BOOL}. */
writeBool(int fieldNumber, boolean value)84   void writeBool(int fieldNumber, boolean value) throws IOException;
85 
86   /** Writes a field of type {@link FieldType#STRING}. */
writeString(int fieldNumber, String value)87   void writeString(int fieldNumber, String value) throws IOException;
88 
89   /** Writes a field of type {@link FieldType#BYTES}. */
writeBytes(int fieldNumber, ByteString value)90   void writeBytes(int fieldNumber, ByteString value) throws IOException;
91 
92   /** Writes a field of type {@link FieldType#UINT32}. */
writeUInt32(int fieldNumber, int value)93   void writeUInt32(int fieldNumber, int value) throws IOException;
94 
95   /** Writes a field of type {@link FieldType#SINT32}. */
writeSInt32(int fieldNumber, int value)96   void writeSInt32(int fieldNumber, int value) throws IOException;
97 
98   /** Writes a field of type {@link FieldType#SINT64}. */
writeSInt64(int fieldNumber, long value)99   void writeSInt64(int fieldNumber, long value) throws IOException;
100 
101   /** Writes a field of type {@link FieldType#MESSAGE}. */
writeMessage(int fieldNumber, Object value)102   void writeMessage(int fieldNumber, Object value) throws IOException;
103 
104   /** Writes a field of type {@link FieldType#MESSAGE}. */
writeMessage(int fieldNumber, Object value, Schema schema)105   void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException;
106 
107   /**
108    * Writes a field of type {@link FieldType#GROUP}.
109    *
110    * @deprecated groups fields are deprecated.
111    */
112   @Deprecated
writeGroup(int fieldNumber, Object value)113   void writeGroup(int fieldNumber, Object value) throws IOException;
114 
115   /**
116    * Writes a field of type {@link FieldType#GROUP}.
117    *
118    * @deprecated groups fields are deprecated.
119    */
120   @Deprecated
writeGroup(int fieldNumber, Object value, Schema schema)121   void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException;
122 
123   /**
124    * Writes a single start group tag.
125    *
126    * @deprecated groups fields are deprecated.
127    */
128   @Deprecated
writeStartGroup(int fieldNumber)129   void writeStartGroup(int fieldNumber) throws IOException;
130 
131   /**
132    * Writes a single end group tag.
133    *
134    * @deprecated groups fields are deprecated.
135    */
136   @Deprecated
writeEndGroup(int fieldNumber)137   void writeEndGroup(int fieldNumber) throws IOException;
138 
139   /** Writes a list field of type {@link FieldType#INT32}. */
writeInt32List(int fieldNumber, List<Integer> value, boolean packed)140   void writeInt32List(int fieldNumber, List<Integer> value, boolean packed) throws IOException;
141 
142   /** Writes a list field of type {@link FieldType#FIXED32}. */
writeFixed32List(int fieldNumber, List<Integer> value, boolean packed)143   void writeFixed32List(int fieldNumber, List<Integer> value, boolean packed) throws IOException;
144 
145   /** Writes a list field of type {@link FieldType#INT64}. */
writeInt64List(int fieldNumber, List<Long> value, boolean packed)146   void writeInt64List(int fieldNumber, List<Long> value, boolean packed) throws IOException;
147 
148   /** Writes a list field of type {@link FieldType#UINT64}. */
writeUInt64List(int fieldNumber, List<Long> value, boolean packed)149   void writeUInt64List(int fieldNumber, List<Long> value, boolean packed) throws IOException;
150 
151   /** Writes a list field of type {@link FieldType#FIXED64}. */
writeFixed64List(int fieldNumber, List<Long> value, boolean packed)152   void writeFixed64List(int fieldNumber, List<Long> value, boolean packed) throws IOException;
153 
154   /** Writes a list field of type {@link FieldType#FLOAT}. */
writeFloatList(int fieldNumber, List<Float> value, boolean packed)155   void writeFloatList(int fieldNumber, List<Float> value, boolean packed) throws IOException;
156 
157   /** Writes a list field of type {@link FieldType#DOUBLE}. */
writeDoubleList(int fieldNumber, List<Double> value, boolean packed)158   void writeDoubleList(int fieldNumber, List<Double> value, boolean packed) throws IOException;
159 
160   /** Writes a list field of type {@link FieldType#ENUM}. */
writeEnumList(int fieldNumber, List<Integer> value, boolean packed)161   void writeEnumList(int fieldNumber, List<Integer> value, boolean packed) throws IOException;
162 
163   /** Writes a list field of type {@link FieldType#BOOL}. */
writeBoolList(int fieldNumber, List<Boolean> value, boolean packed)164   void writeBoolList(int fieldNumber, List<Boolean> value, boolean packed) throws IOException;
165 
166   /** Writes a list field of type {@link FieldType#STRING}. */
writeStringList(int fieldNumber, List<String> value)167   void writeStringList(int fieldNumber, List<String> value) throws IOException;
168 
169   /** Writes a list field of type {@link FieldType#BYTES}. */
writeBytesList(int fieldNumber, List<ByteString> value)170   void writeBytesList(int fieldNumber, List<ByteString> value) throws IOException;
171 
172   /** Writes a list field of type {@link FieldType#UINT32}. */
writeUInt32List(int fieldNumber, List<Integer> value, boolean packed)173   void writeUInt32List(int fieldNumber, List<Integer> value, boolean packed) throws IOException;
174 
175   /** Writes a list field of type {@link FieldType#SFIXED32}. */
writeSFixed32List(int fieldNumber, List<Integer> value, boolean packed)176   void writeSFixed32List(int fieldNumber, List<Integer> value, boolean packed) throws IOException;
177 
178   /** Writes a list field of type {@link FieldType#SFIXED64}. */
writeSFixed64List(int fieldNumber, List<Long> value, boolean packed)179   void writeSFixed64List(int fieldNumber, List<Long> value, boolean packed) throws IOException;
180 
181   /** Writes a list field of type {@link FieldType#SINT32}. */
writeSInt32List(int fieldNumber, List<Integer> value, boolean packed)182   void writeSInt32List(int fieldNumber, List<Integer> value, boolean packed) throws IOException;
183 
184   /** Writes a list field of type {@link FieldType#SINT64}. */
writeSInt64List(int fieldNumber, List<Long> value, boolean packed)185   void writeSInt64List(int fieldNumber, List<Long> value, boolean packed) throws IOException;
186 
187   /** Writes a list field of type {@link FieldType#MESSAGE}. */
writeMessageList(int fieldNumber, List<?> value)188   void writeMessageList(int fieldNumber, List<?> value) throws IOException;
189 
190   /** Writes a list field of type {@link FieldType#MESSAGE}. */
writeMessageList(int fieldNumber, List<?> value, Schema schema)191   void writeMessageList(int fieldNumber, List<?> value, Schema schema) throws IOException;
192 
193   /**
194    * Writes a list field of type {@link FieldType#GROUP}.
195    *
196    * @deprecated groups fields are deprecated.
197    */
198   @Deprecated
writeGroupList(int fieldNumber, List<?> value)199   void writeGroupList(int fieldNumber, List<?> value) throws IOException;
200 
201   /**
202    * Writes a list field of type {@link FieldType#GROUP}.
203    *
204    * @deprecated groups fields are deprecated.
205    */
206   @Deprecated
writeGroupList(int fieldNumber, List<?> value, Schema schema)207   void writeGroupList(int fieldNumber, List<?> value, Schema schema) throws IOException;
208 
209   /**
210    * Writes a message field in {@code MessageSet} wire-format.
211    *
212    * @param value A message instance or an opaque {@link ByteString} for an unknown field.
213    */
writeMessageSetItem(int fieldNumber, Object value)214   void writeMessageSetItem(int fieldNumber, Object value) throws IOException;
215 
216   /** Writes a map field. */
writeMap(int fieldNumber, MapEntryLite.Metadata<K, V> metadata, Map<K, V> map)217   <K, V> void writeMap(int fieldNumber, MapEntryLite.Metadata<K, V> metadata, Map<K, V> map)
218       throws IOException;
219 }
220