@Override public int skip(PositionedByteRange src) { src.setPosition(src.getPosition() + Bytes.SIZEOF_LONG); return Bytes.SIZEOF_LONG; }
@Override public boolean hasNext() { // hasNext can return true when position == length in the case of a // nullable field trailing a struct. return idx < types.length && src.getPosition() <= src.getLength(); }
@Override public int skip(PositionedByteRange src) { src.setPosition(src.getPosition() + Bytes.SIZEOF_BYTE); return Bytes.SIZEOF_BYTE; }
@Override public int skip(PositionedByteRange src) { src.setPosition(src.getPosition() + Bytes.SIZEOF_FLOAT); return Bytes.SIZEOF_FLOAT; }
@Override public int skip(PositionedByteRange src) { src.setPosition(src.getPosition() + this.length); return this.length; }
/** * Write {@code val} into {@code dst}, respecting {@code voff} and {@code vlen}. * @return number of bytes written. */ public int encode(PositionedByteRange dst, byte[] val, int voff, int vlen) { Bytes.putBytes(dst.getBytes(), dst.getOffset() + dst.getPosition(), val, voff, vlen); dst.setPosition(dst.getPosition() + vlen); return vlen; } }
/** * Skip {@code src} over the encoded varuint64. * @param src source buffer * @param cmp if true, parse the compliment of the value. * @return the number of bytes skipped. */ @VisibleForTesting static int skipVaruint64(PositionedByteRange src, boolean cmp) { final int len = lengthVaruint64(src, cmp); src.setPosition(src.getPosition() + len); return len; }
@Override public Byte decode(PositionedByteRange src) { byte val = src.getBytes()[src.getOffset() + src.getPosition()]; skip(src); return val; }
@Override public Float decode(PositionedByteRange src) { float val = Bytes.toFloat(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
@Override public int encode(PositionedByteRange dst, Float val) { Bytes.putFloat(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
@Override public int encode(PositionedByteRange dst, Integer val) { Bytes.putInt(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
@Override public Short decode(PositionedByteRange src) { short val = Bytes.toShort(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
@Override public int encode(PositionedByteRange dst, Long val) { Bytes.putLong(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
@Override public int encode(PositionedByteRange dst, Byte val) { Bytes.putByte(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
@Override public Double decode(PositionedByteRange src) { double val = Bytes.toDouble(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
@Override public int encode(PositionedByteRange dst, Double val) { Bytes.putDouble(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
@Override public Integer decode(PositionedByteRange src) { int val = Bytes.toInt(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
@Override public int encode(PositionedByteRange dst, Short val) { Bytes.putShort(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
@Override public T decode(PositionedByteRange src) { if (src.getRemaining() < length) { throw new IllegalArgumentException("Not enough buffer remaining. src.offset: " + src.getOffset() + " src.length: " + src.getLength() + " src.position: " + src.getPosition() + " max length: " + length); } // create a copy range limited to length bytes. boo. PositionedByteRange b = new SimplePositionedMutableByteRange(length); src.get(b.getBytes()); return base.decode(b); }
@Override public CellProtos.Cell decode(PositionedByteRange src) { CellProtos.Cell.Builder builder = CellProtos.Cell.newBuilder(); CodedInputStream is = inputStreamFromByteRange(src); is.setSizeLimit(src.getLength()); try { CellProtos.Cell ret = builder.mergeFrom(is).build(); src.setPosition(src.getPosition() + is.getTotalBytesRead()); return ret; } catch (IOException e) { throw new RuntimeException("Error while decoding type.", e); } }