2 * Autogenerated by Avro
6 package de.trion.microservices.avro;
8 import org.apache.avro.generic.GenericArray;
9 import org.apache.avro.specific.SpecificData;
10 import org.apache.avro.util.Utf8;
11 import org.apache.avro.message.BinaryMessageEncoder;
12 import org.apache.avro.message.BinaryMessageDecoder;
13 import org.apache.avro.message.SchemaStore;
15 @org.apache.avro.specific.AvroGenerated
16 public class OrderAndUser extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
17 private static final long serialVersionUID = 6432660008992245598L;
18 public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"OrderAndUser\",\"namespace\":\"de.trion.microservices.avro\",\"fields\":[{\"name\":\"order\",\"type\":{\"type\":\"record\",\"name\":\"Order\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"state\",\"type\":{\"type\":\"enum\",\"name\":\"OrderState\",\"symbols\":[\"CREATED\",\"APPROVED\",\"DECLINED\"],\"default\":\"CREATED\"}},{\"name\":\"customerId\",\"type\":\"long\"},{\"name\":\"orderId\",\"type\":\"long\"},{\"name\":\"productId\",\"type\":\"long\"},{\"name\":\"quantity\",\"type\":\"int\"}]}},{\"name\":\"user\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"id\",\"type\":\"long\"},{\"name\":\"level\",\"type\":{\"type\":\"enum\",\"name\":\"CustomerLevel\",\"symbols\":[\"BRONZE\",\"SILVER\",\"GOLD\",\"UNWANTED\"]}},{\"name\":\"name\",\"type\":\"string\"}]}]}]}");
19 public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
21 private static SpecificData MODEL$ = new SpecificData();
23 private static final BinaryMessageEncoder<OrderAndUser> ENCODER =
24 new BinaryMessageEncoder<OrderAndUser>(MODEL$, SCHEMA$);
26 private static final BinaryMessageDecoder<OrderAndUser> DECODER =
27 new BinaryMessageDecoder<OrderAndUser>(MODEL$, SCHEMA$);
30 * Return the BinaryMessageEncoder instance used by this class.
31 * @return the message encoder used by this class
33 public static BinaryMessageEncoder<OrderAndUser> getEncoder() {
38 * Return the BinaryMessageDecoder instance used by this class.
39 * @return the message decoder used by this class
41 public static BinaryMessageDecoder<OrderAndUser> getDecoder() {
46 * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
47 * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
48 * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
50 public static BinaryMessageDecoder<OrderAndUser> createDecoder(SchemaStore resolver) {
51 return new BinaryMessageDecoder<OrderAndUser>(MODEL$, SCHEMA$, resolver);
55 * Serializes this OrderAndUser to a ByteBuffer.
56 * @return a buffer holding the serialized data for this instance
57 * @throws java.io.IOException if this instance could not be serialized
59 public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
60 return ENCODER.encode(this);
64 * Deserializes a OrderAndUser from a ByteBuffer.
65 * @param b a byte buffer holding serialized data for an instance of this class
66 * @return a OrderAndUser instance decoded from the given buffer
67 * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class
69 public static OrderAndUser fromByteBuffer(
70 java.nio.ByteBuffer b) throws java.io.IOException {
71 return DECODER.decode(b);
74 @Deprecated public de.trion.microservices.avro.Order order;
75 @Deprecated public de.trion.microservices.avro.User user;
78 * Default constructor. Note that this does not initialize fields
79 * to their default values from the schema. If that is desired then
80 * one should use <code>newBuilder()</code>.
82 public OrderAndUser() {}
85 * All-args constructor.
86 * @param order The new value for order
87 * @param user The new value for user
89 public OrderAndUser(de.trion.microservices.avro.Order order, de.trion.microservices.avro.User user) {
94 public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }
95 public org.apache.avro.Schema getSchema() { return SCHEMA$; }
96 // Used by DatumWriter. Applications should not call.
97 public java.lang.Object get(int field$) {
101 default: throw new org.apache.avro.AvroRuntimeException("Bad index");
105 // Used by DatumReader. Applications should not call.
106 @SuppressWarnings(value="unchecked")
107 public void put(int field$, java.lang.Object value$) {
109 case 0: order = (de.trion.microservices.avro.Order)value$; break;
110 case 1: user = (de.trion.microservices.avro.User)value$; break;
111 default: throw new org.apache.avro.AvroRuntimeException("Bad index");
116 * Gets the value of the 'order' field.
117 * @return The value of the 'order' field.
119 public de.trion.microservices.avro.Order getOrder() {
125 * Sets the value of the 'order' field.
126 * @param value the value to set.
128 public void setOrder(de.trion.microservices.avro.Order value) {
133 * Gets the value of the 'user' field.
134 * @return The value of the 'user' field.
136 public de.trion.microservices.avro.User getUser() {
142 * Sets the value of the 'user' field.
143 * @param value the value to set.
145 public void setUser(de.trion.microservices.avro.User value) {
150 * Creates a new OrderAndUser RecordBuilder.
151 * @return A new OrderAndUser RecordBuilder
153 public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder() {
154 return new de.trion.microservices.avro.OrderAndUser.Builder();
158 * Creates a new OrderAndUser RecordBuilder by copying an existing Builder.
159 * @param other The existing builder to copy.
160 * @return A new OrderAndUser RecordBuilder
162 public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder(de.trion.microservices.avro.OrderAndUser.Builder other) {
164 return new de.trion.microservices.avro.OrderAndUser.Builder();
166 return new de.trion.microservices.avro.OrderAndUser.Builder(other);
171 * Creates a new OrderAndUser RecordBuilder by copying an existing OrderAndUser instance.
172 * @param other The existing instance to copy.
173 * @return A new OrderAndUser RecordBuilder
175 public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder(de.trion.microservices.avro.OrderAndUser other) {
177 return new de.trion.microservices.avro.OrderAndUser.Builder();
179 return new de.trion.microservices.avro.OrderAndUser.Builder(other);
184 * RecordBuilder for OrderAndUser instances.
186 public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<OrderAndUser>
187 implements org.apache.avro.data.RecordBuilder<OrderAndUser> {
189 private de.trion.microservices.avro.Order order;
190 private de.trion.microservices.avro.Order.Builder orderBuilder;
191 private de.trion.microservices.avro.User user;
192 private de.trion.microservices.avro.User.Builder userBuilder;
194 /** Creates a new Builder */
200 * Creates a Builder by copying an existing Builder.
201 * @param other The existing Builder to copy.
203 private Builder(de.trion.microservices.avro.OrderAndUser.Builder other) {
205 if (isValidValue(fields()[0], other.order)) {
206 this.order = data().deepCopy(fields()[0].schema(), other.order);
207 fieldSetFlags()[0] = other.fieldSetFlags()[0];
209 if (other.hasOrderBuilder()) {
210 this.orderBuilder = de.trion.microservices.avro.Order.newBuilder(other.getOrderBuilder());
212 if (isValidValue(fields()[1], other.user)) {
213 this.user = data().deepCopy(fields()[1].schema(), other.user);
214 fieldSetFlags()[1] = other.fieldSetFlags()[1];
216 if (other.hasUserBuilder()) {
217 this.userBuilder = de.trion.microservices.avro.User.newBuilder(other.getUserBuilder());
222 * Creates a Builder by copying an existing OrderAndUser instance
223 * @param other The existing instance to copy.
225 private Builder(de.trion.microservices.avro.OrderAndUser other) {
227 if (isValidValue(fields()[0], other.order)) {
228 this.order = data().deepCopy(fields()[0].schema(), other.order);
229 fieldSetFlags()[0] = true;
231 this.orderBuilder = null;
232 if (isValidValue(fields()[1], other.user)) {
233 this.user = data().deepCopy(fields()[1].schema(), other.user);
234 fieldSetFlags()[1] = true;
236 this.userBuilder = null;
240 * Gets the value of the 'order' field.
243 public de.trion.microservices.avro.Order getOrder() {
249 * Sets the value of the 'order' field.
250 * @param value The value of 'order'.
251 * @return This builder.
253 public de.trion.microservices.avro.OrderAndUser.Builder setOrder(de.trion.microservices.avro.Order value) {
254 validate(fields()[0], value);
255 this.orderBuilder = null;
257 fieldSetFlags()[0] = true;
262 * Checks whether the 'order' field has been set.
263 * @return True if the 'order' field has been set, false otherwise.
265 public boolean hasOrder() {
266 return fieldSetFlags()[0];
270 * Gets the Builder instance for the 'order' field and creates one if it doesn't exist yet.
271 * @return This builder.
273 public de.trion.microservices.avro.Order.Builder getOrderBuilder() {
274 if (orderBuilder == null) {
276 setOrderBuilder(de.trion.microservices.avro.Order.newBuilder(order));
278 setOrderBuilder(de.trion.microservices.avro.Order.newBuilder());
285 * Sets the Builder instance for the 'order' field
286 * @param value The builder instance that must be set.
287 * @return This builder.
289 public de.trion.microservices.avro.OrderAndUser.Builder setOrderBuilder(de.trion.microservices.avro.Order.Builder value) {
291 orderBuilder = value;
296 * Checks whether the 'order' field has an active Builder instance
297 * @return True if the 'order' field has an active Builder instance
299 public boolean hasOrderBuilder() {
300 return orderBuilder != null;
304 * Clears the value of the 'order' field.
305 * @return This builder.
307 public de.trion.microservices.avro.OrderAndUser.Builder clearOrder() {
310 fieldSetFlags()[0] = false;
315 * Gets the value of the 'user' field.
318 public de.trion.microservices.avro.User getUser() {
324 * Sets the value of the 'user' field.
325 * @param value The value of 'user'.
326 * @return This builder.
328 public de.trion.microservices.avro.OrderAndUser.Builder setUser(de.trion.microservices.avro.User value) {
329 validate(fields()[1], value);
330 this.userBuilder = null;
332 fieldSetFlags()[1] = true;
337 * Checks whether the 'user' field has been set.
338 * @return True if the 'user' field has been set, false otherwise.
340 public boolean hasUser() {
341 return fieldSetFlags()[1];
345 * Gets the Builder instance for the 'user' field and creates one if it doesn't exist yet.
346 * @return This builder.
348 public de.trion.microservices.avro.User.Builder getUserBuilder() {
349 if (userBuilder == null) {
351 setUserBuilder(de.trion.microservices.avro.User.newBuilder(user));
353 setUserBuilder(de.trion.microservices.avro.User.newBuilder());
360 * Sets the Builder instance for the 'user' field
361 * @param value The builder instance that must be set.
362 * @return This builder.
364 public de.trion.microservices.avro.OrderAndUser.Builder setUserBuilder(de.trion.microservices.avro.User.Builder value) {
371 * Checks whether the 'user' field has an active Builder instance
372 * @return True if the 'user' field has an active Builder instance
374 public boolean hasUserBuilder() {
375 return userBuilder != null;
379 * Clears the value of the 'user' field.
380 * @return This builder.
382 public de.trion.microservices.avro.OrderAndUser.Builder clearUser() {
385 fieldSetFlags()[1] = false;
390 @SuppressWarnings("unchecked")
391 public OrderAndUser build() {
393 OrderAndUser record = new OrderAndUser();
394 if (orderBuilder != null) {
396 record.order = this.orderBuilder.build();
397 } catch (org.apache.avro.AvroMissingFieldException e) {
398 e.addParentField(record.getSchema().getField("order"));
402 record.order = fieldSetFlags()[0] ? this.order : (de.trion.microservices.avro.Order) defaultValue(fields()[0]);
404 if (userBuilder != null) {
406 record.user = this.userBuilder.build();
407 } catch (org.apache.avro.AvroMissingFieldException e) {
408 e.addParentField(record.getSchema().getField("user"));
412 record.user = fieldSetFlags()[1] ? this.user : (de.trion.microservices.avro.User) defaultValue(fields()[1]);
415 } catch (org.apache.avro.AvroMissingFieldException e) {
417 } catch (java.lang.Exception e) {
418 throw new org.apache.avro.AvroRuntimeException(e);
423 @SuppressWarnings("unchecked")
424 private static final org.apache.avro.io.DatumWriter<OrderAndUser>
425 WRITER$ = (org.apache.avro.io.DatumWriter<OrderAndUser>)MODEL$.createDatumWriter(SCHEMA$);
427 @Override public void writeExternal(java.io.ObjectOutput out)
428 throws java.io.IOException {
429 WRITER$.write(this, SpecificData.getEncoder(out));
432 @SuppressWarnings("unchecked")
433 private static final org.apache.avro.io.DatumReader<OrderAndUser>
434 READER$ = (org.apache.avro.io.DatumReader<OrderAndUser>)MODEL$.createDatumReader(SCHEMA$);
436 @Override public void readExternal(java.io.ObjectInput in)
437 throws java.io.IOException {
438 READER$.read(this, SpecificData.getDecoder(in));
441 @Override protected boolean hasCustomCoders() { return true; }
443 @Override public void customEncode(org.apache.avro.io.Encoder out)
444 throws java.io.IOException
446 this.order.customEncode(out);
448 if (this.user == null) {
453 this.user.customEncode(out);
458 @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
459 throws java.io.IOException
461 org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
462 if (fieldOrder == null) {
463 if (this.order == null) {
464 this.order = new de.trion.microservices.avro.Order();
466 this.order.customDecode(in);
468 if (in.readIndex() != 1) {
472 if (this.user == null) {
473 this.user = new de.trion.microservices.avro.User();
475 this.user.customDecode(in);
479 for (int i = 0; i < 2; i++) {
480 switch (fieldOrder[i].pos()) {
482 if (this.order == null) {
483 this.order = new de.trion.microservices.avro.Order();
485 this.order.customDecode(in);
489 if (in.readIndex() != 1) {
493 if (this.user == null) {
494 this.user = new de.trion.microservices.avro.User();
496 this.user.customDecode(in);
501 throw new java.io.IOException("Corrupt ResolvingDecoder.");