@Override public Object read(Object reuse, Decoder in) throws IOException { if (written == null) // same schema return Json.readObject(in); // use a resolver to adapt alternate version of Json schema if (resolver == null) resolver = DecoderFactory.get().resolvingDecoder(written, SCHEMA, null); resolver.configure(in); Object result = Json.readObject(resolver); resolver.drain(); return result; } }
@Override protected void readInternal(Decoder d) throws IOException { ResolvingDecoder r = (ResolvingDecoder) d; Field[] ff = r.readFieldOrder(); for (int i = 0; i < count; i++) { for (int j = 0; j < ff.length; j++) { Field f = ff[j]; switch (f.pos()) { case 0: case 1: case 2: r.readDouble(); break; case 3: case 4: case 5: r.readInt(); break; case 6: case 7: r.readString(null); break; } } } } }
protected Object readWithoutConversion(Object old, Schema expected, ResolvingDecoder in) throws IOException { switch (expected.getType()) { case RECORD: return readRecord(old, expected, in); case ENUM: return readEnum(expected, in); case ARRAY: return readArray(old, expected, in); case MAP: return readMap(old, expected, in); case UNION: return read(old, expected.getTypes().get(in.readIndex()), in); case FIXED: return readFixed(old, expected, in); case STRING: return readString(old, expected, in); case BYTES: return readBytes(old, expected, in); case INT: return readInt(old, expected, in); case LONG: return in.readLong(); case FLOAT: return in.readFloat(); case DOUBLE: return in.readDouble(); case BOOLEAN: return in.readBoolean(); case NULL: in.readNull(); return null; default: throw new AvroRuntimeException("Unknown type: " + expected); } }
static int[] readArray(int[] array, long l, ResolvingDecoder in) throws IOException { int index = 0; do { int limit = index + (int) l; if (array.length < limit) { array = Arrays.copyOf(array, limit); } while (index < limit) { array[index] = in.readInt(); index++; } } while ((l = in.arrayNext()) > 0); return array; }
static double[] readArray(double[] array, long l, ResolvingDecoder in) throws IOException { int index = 0; do { int limit = index + (int) l; if (array.length < limit) { array = Arrays.copyOf(array, limit); } while (index < limit) { array[index] = in.readDouble(); index++; } } while ((l = in.arrayNext()) > 0); return array; }
static boolean[] readArray(boolean[] array, long l, ResolvingDecoder in) throws IOException { int index = 0; do { int limit = index + (int) l; if (array.length < limit) { array = Arrays.copyOf(array, limit); } while (index < limit) { array[index] = in.readBoolean(); index++; } } while ((l = in.arrayNext()) > 0); return array; }
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { if (in.readIndex() != 1) { in.readNull(); this.nullableString = null; } else { this.nullableString = in.readString(); if (in.readIndex() != 1) { in.readNull(); this.nullableLong = null; } else { this.nullableLong = in.readLong(); if (in.readIndex() != 1) { in.readNull(); this.nullableInt = null; } else { this.nullableInt = in.readInt(); if (in.readIndex() != 1) { in.readNull(); this.nullableMap = null; } else { long size0 = in.readMapStart(); java.util.Map<java.lang.String,java.lang.String> m0 = this.nullableMap; // Need fresh name due to limitation of macro system if (m0 == null) { this.nullableMap = m0;
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { this.id = in.readInt(); this.name = in.readString(); long size0 = in.readArrayStart(); java.util.List<java.lang.String> a0 = this.nicknames; if (a0 == null) { } else a0.clear(); SpecificData.Array<java.lang.String> ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array<java.lang.String>)a0 : null); for ( ; 0 < size0; size0 = in.arrayNext()) { for ( ; size0 != 0; size0--) { java.lang.String e0 = (ga0 != null ? ga0.peek() : null); e0 = in.readString(); a0.add(e0); long size1 = in.readArrayStart(); java.util.List<java.lang.Integer> a1 = this.relatedids; if (a1 == null) { } else a1.clear(); SpecificData.Array<java.lang.Integer> ga1 = (a1 instanceof SpecificData.Array ? (SpecificData.Array<java.lang.Integer>)a1 : null); for ( ; 0 < size1; size1 = in.arrayNext()) { for ( ; size1 != 0; size1--) { java.lang.Integer e1 = (ga1 != null ? ga1.peek() : null); e1 = in.readInt(); a1.add(e1);
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { long size0 = in.readArrayStart(); java.util.List<java.lang.String> a0 = this.productsInCart; if (a0 == null) { } else a0.clear(); SpecificData.Array<java.lang.String> ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array<java.lang.String>)a0 : null); for ( ; 0 < size0; size0 = in.arrayNext()) { for ( ; size0 != 0; size0--) { java.lang.String e0 = (ga0 != null ? ga0.peek() : null); e0 = in.readString(); a0.add(e0); switch (fieldOrder[i].pos()) { case 0: long size0 = in.readArrayStart(); java.util.List<java.lang.String> a0 = this.productsInCart; if (a0 == null) { } else a0.clear(); SpecificData.Array<java.lang.String> ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array<java.lang.String>)a0 : null); for ( ; 0 < size0; size0 = in.arrayNext()) { for ( ; size0 != 0; size0--) { java.lang.String e0 = (ga0 != null ? ga0.peek() : null); e0 = in.readString(); a0.add(e0);
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { this.match = org.apache.avro.ipc.HandshakeMatch.values()[in.readEnum()]; if (in.readIndex() != 1) { in.readNull(); this.serverProtocol = null; } else { this.serverProtocol = in.readString(); if (in.readIndex() != 1) { in.readNull(); this.serverHash = null; } else { in.readFixed(this.serverHash.bytes(), 0, 16); if (in.readIndex() != 1) { in.readNull(); this.meta = null; } else { long size0 = in.readMapStart(); java.util.Map<java.lang.String,java.nio.ByteBuffer> m0 = this.meta; // Need fresh name due to limitation of macro system if (m0 == null) { this.meta = m0; } else m0.clear(); for ( ; 0 < size0; size0 = in.mapNext()) { for ( ; size0 != 0; size0--) {
@Override protected void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { if (in.readIndex() != 1) { in.readNull(); this.id = null; } else { this.id = in.readString(); this.useragent = in.readString(); switch (fieldOrder[i].pos()) { case 0: if (in.readIndex() != 1) { in.readNull(); this.id = null; } else { this.id = in.readString(); this.useragent = in.readString(); break;
/** Called to read a map instance. May be overridden for alternate map * representations.*/ protected Object readMap(Object old, Schema expected, ResolvingDecoder in) throws IOException { Schema eValue = expected.getValueType(); long l = in.readMapStart(); LogicalType logicalType = eValue.getLogicalType(); Conversion<?> conversion = getData().getConversionFor(logicalType); Object map = newMap(old, (int) l); if (l > 0) { do { if (logicalType != null && conversion != null) { for (int i = 0; i < l; i++) { addToMap(map, readMapKey(null, expected, in), readWithConversion(null, eValue, logicalType, conversion, in)); } } else { for (int i = 0; i < l; i++) { addToMap(map, readMapKey(null, expected, in), readWithoutConversion(null, eValue, in)); } } } while ((l = in.mapNext()) > 0); } return map; }
/** Called to read a record instance. May be overridden for alternate record * representations.*/ protected Object readRecord(Object old, Schema expected, ResolvingDecoder in) throws IOException { Object r = data.newRecord(old, expected); Object state = data.getRecordState(r, expected); for (Field f : in.readFieldOrder()) { int pos = f.pos(); String name = f.name(); Object oldDatum = null; if (old!=null) { oldDatum = data.getField(r, name, pos, state); } readField(r, f, oldDatum, in, state); } return r; }
@Override protected void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { this.timestamp = in.readLong(); if (in.readIndex() != 1) { in.readNull(); this.connection = null; } else { switch (fieldOrder[i].pos()) { case 0: this.timestamp = in.readLong(); break; if (in.readIndex() != 1) { in.readNull(); this.connection = null; } else {
@Override protected void readInternal(Decoder d) throws IOException { ResolvingDecoder r = (ResolvingDecoder) d; Field[] ff = r.readFieldOrder(); for (int i = 0; i < count; i++) { for (int j = 0; j < ff.length; j++) { Field f = ff[j]; switch (f.pos()) { case 0: case 1: case 2: r.readDouble(); break; case 3: case 4: case 5: r.readLong(); break; } } } } }
@Override protected void readInternal(Decoder d) throws IOException { ResolvingDecoder r = (ResolvingDecoder) d; Field[] ff = r.readFieldOrder(); for (int i = 0; i < count; i++) { for (int j = 0; j < ff.length; j++) { Field f = ff[j]; switch (f.pos()) { case 0: case 1: case 3: r.readDouble(); break; case 2: case 4: case 5: r.readInt(); break; } } } } }
/** Called to read an array instance. May be overridden for alternate array * representations.*/ protected Object readArray(Object old, Schema expected, ResolvingDecoder in) throws IOException { Schema expectedType = expected.getElementType(); long l = in.readArrayStart(); long base = 0; if (l > 0) { LogicalType logicalType = expectedType.getLogicalType(); Conversion<?> conversion = getData().getConversionFor(logicalType); Object array = newArray(old, (int) l, expected); do { if (logicalType != null && conversion != null) { for (long i = 0; i < l; i++) { addToArray(array, base + i, readWithConversion( peekArray(array), expectedType, logicalType, conversion, in)); } } else { for (long i = 0; i < l; i++) { addToArray(array, base + i, readWithoutConversion( peekArray(array), expectedType, in)); } } base += l; } while ((l = in.arrayNext()) > 0); return array; } else { return newArray(old, 0, expected); } }
/** * Creates a {@link ResolvingDecoder} wrapping the Decoder provided. This * ResolvingDecoder will resolve input conforming to the <i>writer</i> schema * from the wrapped Decoder, and present it as the <i>reader</i> schema. * * @param writer * The Schema that the source data is in. Cannot be null. * @param reader * The Schema that the reader wishes to read the data as. Cannot be * null. * @param wrapped * The Decoder to wrap. * @return A ResolvingDecoder configured to resolve <i>writer</i> to * <i>reader</i> from <i>in</i> * @throws IOException */ public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException { return new ResolvingDecoder(writer, reader, wrapped); }
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { this.value = new java.math.BigDecimal(in.readString()); long size0 = in.readMapStart(); java.util.Map<java.math.BigInteger,java.lang.String> m0 = this.mapWithBigIntKeys; // Need fresh name due to limitation of macro system if (m0 == null) { this.mapWithBigIntKeys = m0; } else m0.clear(); for ( ; 0 < size0; size0 = in.mapNext()) { for ( ; size0 != 0; size0--) { java.math.BigInteger k0 = null; k0 = new java.math.BigInteger(in.readString()); java.lang.String v0 = null; v0 = in.readString(); m0.put(k0, v0); long size1 = in.readMapStart(); java.util.Map<java.lang.String,java.math.BigDecimal> m1 = this.mapWithBigDecimalElements; // Need fresh name due to limitation of macro system if (m1 == null) { this.mapWithBigDecimalElements = m1; } else m1.clear(); for ( ; 0 < size1; size1 = in.mapNext()) { for ( ; size1 != 0; size1--) { java.lang.String k1 = null; k1 = in.readString(); java.math.BigDecimal v1 = null;
@Override protected void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); if (fieldOrder == null) { this.station = in.readString(); this.time = in.readLong(); this.temp = in.readInt(); switch (fieldOrder[i].pos()) { case 0: this.station = in.readString(); break; this.time = in.readLong(); break; this.temp = in.readInt(); break;