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 User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
17 private static final long serialVersionUID = 2154150202977610190L;
18 public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"de.trion.microservices.avro\",\"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<User> ENCODER =
24 new BinaryMessageEncoder<User>(MODEL$, SCHEMA$);
26 private static final BinaryMessageDecoder<User> DECODER =
27 new BinaryMessageDecoder<User>(MODEL$, SCHEMA$);
30 * Return the BinaryMessageEncoder instance used by this class.
31 * @return the message encoder used by this class
33 public static BinaryMessageEncoder<User> getEncoder() {
38 * Return the BinaryMessageDecoder instance used by this class.
39 * @return the message decoder used by this class
41 public static BinaryMessageDecoder<User> 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<User> createDecoder(SchemaStore resolver) {
51 return new BinaryMessageDecoder<User>(MODEL$, SCHEMA$, resolver);
55 * Serializes this User 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 User from a ByteBuffer.
65 * @param b a byte buffer holding serialized data for an instance of this class
66 * @return a User 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 User fromByteBuffer(
70 java.nio.ByteBuffer b) throws java.io.IOException {
71 return DECODER.decode(b);
74 @Deprecated public long id;
75 @Deprecated public de.trion.microservices.avro.CustomerLevel level;
76 @Deprecated public java.lang.CharSequence name;
79 * Default constructor. Note that this does not initialize fields
80 * to their default values from the schema. If that is desired then
81 * one should use <code>newBuilder()</code>.
86 * All-args constructor.
87 * @param id The new value for id
88 * @param level The new value for level
89 * @param name The new value for name
91 public User(java.lang.Long id, de.trion.microservices.avro.CustomerLevel level, java.lang.CharSequence name) {
97 public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }
98 public org.apache.avro.Schema getSchema() { return SCHEMA$; }
99 // Used by DatumWriter. Applications should not call.
100 public java.lang.Object get(int field$) {
103 case 1: return level;
105 default: throw new org.apache.avro.AvroRuntimeException("Bad index");
109 // Used by DatumReader. Applications should not call.
110 @SuppressWarnings(value="unchecked")
111 public void put(int field$, java.lang.Object value$) {
113 case 0: id = (java.lang.Long)value$; break;
114 case 1: level = (de.trion.microservices.avro.CustomerLevel)value$; break;
115 case 2: name = (java.lang.CharSequence)value$; break;
116 default: throw new org.apache.avro.AvroRuntimeException("Bad index");
121 * Gets the value of the 'id' field.
122 * @return The value of the 'id' field.
124 public long getId() {
130 * Sets the value of the 'id' field.
131 * @param value the value to set.
133 public void setId(long value) {
138 * Gets the value of the 'level' field.
139 * @return The value of the 'level' field.
141 public de.trion.microservices.avro.CustomerLevel getLevel() {
147 * Sets the value of the 'level' field.
148 * @param value the value to set.
150 public void setLevel(de.trion.microservices.avro.CustomerLevel value) {
155 * Gets the value of the 'name' field.
156 * @return The value of the 'name' field.
158 public java.lang.CharSequence getName() {
164 * Sets the value of the 'name' field.
165 * @param value the value to set.
167 public void setName(java.lang.CharSequence value) {
172 * Creates a new User RecordBuilder.
173 * @return A new User RecordBuilder
175 public static de.trion.microservices.avro.User.Builder newBuilder() {
176 return new de.trion.microservices.avro.User.Builder();
180 * Creates a new User RecordBuilder by copying an existing Builder.
181 * @param other The existing builder to copy.
182 * @return A new User RecordBuilder
184 public static de.trion.microservices.avro.User.Builder newBuilder(de.trion.microservices.avro.User.Builder other) {
186 return new de.trion.microservices.avro.User.Builder();
188 return new de.trion.microservices.avro.User.Builder(other);
193 * Creates a new User RecordBuilder by copying an existing User instance.
194 * @param other The existing instance to copy.
195 * @return A new User RecordBuilder
197 public static de.trion.microservices.avro.User.Builder newBuilder(de.trion.microservices.avro.User other) {
199 return new de.trion.microservices.avro.User.Builder();
201 return new de.trion.microservices.avro.User.Builder(other);
206 * RecordBuilder for User instances.
208 public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<User>
209 implements org.apache.avro.data.RecordBuilder<User> {
212 private de.trion.microservices.avro.CustomerLevel level;
213 private java.lang.CharSequence name;
215 /** Creates a new Builder */
221 * Creates a Builder by copying an existing Builder.
222 * @param other The existing Builder to copy.
224 private Builder(de.trion.microservices.avro.User.Builder other) {
226 if (isValidValue(fields()[0], other.id)) {
227 this.id = data().deepCopy(fields()[0].schema(), other.id);
228 fieldSetFlags()[0] = other.fieldSetFlags()[0];
230 if (isValidValue(fields()[1], other.level)) {
231 this.level = data().deepCopy(fields()[1].schema(), other.level);
232 fieldSetFlags()[1] = other.fieldSetFlags()[1];
234 if (isValidValue(fields()[2], other.name)) {
235 this.name = data().deepCopy(fields()[2].schema(), other.name);
236 fieldSetFlags()[2] = other.fieldSetFlags()[2];
241 * Creates a Builder by copying an existing User instance
242 * @param other The existing instance to copy.
244 private Builder(de.trion.microservices.avro.User other) {
246 if (isValidValue(fields()[0], other.id)) {
247 this.id = data().deepCopy(fields()[0].schema(), other.id);
248 fieldSetFlags()[0] = true;
250 if (isValidValue(fields()[1], other.level)) {
251 this.level = data().deepCopy(fields()[1].schema(), other.level);
252 fieldSetFlags()[1] = true;
254 if (isValidValue(fields()[2], other.name)) {
255 this.name = data().deepCopy(fields()[2].schema(), other.name);
256 fieldSetFlags()[2] = true;
261 * Gets the value of the 'id' field.
264 public long getId() {
270 * Sets the value of the 'id' field.
271 * @param value The value of 'id'.
272 * @return This builder.
274 public de.trion.microservices.avro.User.Builder setId(long value) {
275 validate(fields()[0], value);
277 fieldSetFlags()[0] = true;
282 * Checks whether the 'id' field has been set.
283 * @return True if the 'id' field has been set, false otherwise.
285 public boolean hasId() {
286 return fieldSetFlags()[0];
291 * Clears the value of the 'id' field.
292 * @return This builder.
294 public de.trion.microservices.avro.User.Builder clearId() {
295 fieldSetFlags()[0] = false;
300 * Gets the value of the 'level' field.
303 public de.trion.microservices.avro.CustomerLevel getLevel() {
309 * Sets the value of the 'level' field.
310 * @param value The value of 'level'.
311 * @return This builder.
313 public de.trion.microservices.avro.User.Builder setLevel(de.trion.microservices.avro.CustomerLevel value) {
314 validate(fields()[1], value);
316 fieldSetFlags()[1] = true;
321 * Checks whether the 'level' field has been set.
322 * @return True if the 'level' field has been set, false otherwise.
324 public boolean hasLevel() {
325 return fieldSetFlags()[1];
330 * Clears the value of the 'level' field.
331 * @return This builder.
333 public de.trion.microservices.avro.User.Builder clearLevel() {
335 fieldSetFlags()[1] = false;
340 * Gets the value of the 'name' field.
343 public java.lang.CharSequence getName() {
349 * Sets the value of the 'name' field.
350 * @param value The value of 'name'.
351 * @return This builder.
353 public de.trion.microservices.avro.User.Builder setName(java.lang.CharSequence value) {
354 validate(fields()[2], value);
356 fieldSetFlags()[2] = true;
361 * Checks whether the 'name' field has been set.
362 * @return True if the 'name' field has been set, false otherwise.
364 public boolean hasName() {
365 return fieldSetFlags()[2];
370 * Clears the value of the 'name' field.
371 * @return This builder.
373 public de.trion.microservices.avro.User.Builder clearName() {
375 fieldSetFlags()[2] = false;
380 @SuppressWarnings("unchecked")
381 public User build() {
383 User record = new User();
384 record.id = fieldSetFlags()[0] ? this.id : (java.lang.Long) defaultValue(fields()[0]);
385 record.level = fieldSetFlags()[1] ? this.level : (de.trion.microservices.avro.CustomerLevel) defaultValue(fields()[1]);
386 record.name = fieldSetFlags()[2] ? this.name : (java.lang.CharSequence) defaultValue(fields()[2]);
388 } catch (org.apache.avro.AvroMissingFieldException e) {
390 } catch (java.lang.Exception e) {
391 throw new org.apache.avro.AvroRuntimeException(e);
396 @SuppressWarnings("unchecked")
397 private static final org.apache.avro.io.DatumWriter<User>
398 WRITER$ = (org.apache.avro.io.DatumWriter<User>)MODEL$.createDatumWriter(SCHEMA$);
400 @Override public void writeExternal(java.io.ObjectOutput out)
401 throws java.io.IOException {
402 WRITER$.write(this, SpecificData.getEncoder(out));
405 @SuppressWarnings("unchecked")
406 private static final org.apache.avro.io.DatumReader<User>
407 READER$ = (org.apache.avro.io.DatumReader<User>)MODEL$.createDatumReader(SCHEMA$);
409 @Override public void readExternal(java.io.ObjectInput in)
410 throws java.io.IOException {
411 READER$.read(this, SpecificData.getDecoder(in));
414 @Override protected boolean hasCustomCoders() { return true; }
416 @Override public void customEncode(org.apache.avro.io.Encoder out)
417 throws java.io.IOException
419 out.writeLong(this.id);
421 out.writeEnum(this.level.ordinal());
423 out.writeString(this.name);
427 @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
428 throws java.io.IOException
430 org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
431 if (fieldOrder == null) {
432 this.id = in.readLong();
434 this.level = de.trion.microservices.avro.CustomerLevel.values()[in.readEnum()];
436 this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null);
439 for (int i = 0; i < 3; i++) {
440 switch (fieldOrder[i].pos()) {
442 this.id = in.readLong();
446 this.level = de.trion.microservices.avro.CustomerLevel.values()[in.readEnum()];
450 this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null);
454 throw new java.io.IOException("Corrupt ResolvingDecoder.");