@Override public void decode(TransactionEdit dest, DataInput in) throws IOException { super.decode(dest, in); int typeIdx = in.readInt(); // null transaction type is represented as -1 if (typeIdx < 0) { dest.setType(null); } else { try { dest.setType(TransactionType.values()[typeIdx]); } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("Type enum ordinal value is out of range: " + typeIdx); } } int truncateInvalidTxSize = in.readInt(); Set<Long> truncateInvalidTx = emptySet(dest.getTruncateInvalidTx()); for (int i = 0; i < truncateInvalidTxSize; i++) { truncateInvalidTx.add(in.readLong()); } dest.setTruncateInvalidTx(truncateInvalidTx); dest.setTruncateInvalidTxTime(in.readLong()); }
@Override public void encode(TransactionEdit src, DataOutput out) throws IOException { super.encode(src, out); // null transaction type is represented as -1 if (src.getType() == null) { out.writeInt(-1); } else { out.writeInt(src.getType().ordinal()); } Set<Long> truncateInvalidTx = src.getTruncateInvalidTx(); if (truncateInvalidTx == null) { out.writeInt(0); } else { out.writeInt(truncateInvalidTx.size()); for (long id : truncateInvalidTx) { out.writeLong(id); } } out.writeLong(src.getTruncateInvalidTxTime()); }
@Override public void decode(TransactionEdit dest, DataInput in) throws IOException { super.decode(dest, in); int typeIdx = in.readInt(); // null transaction type is represented as -1 if (typeIdx < 0) { dest.setType(null); } else { try { dest.setType(TransactionType.values()[typeIdx]); } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("Type enum ordinal value is out of range: " + typeIdx); } } int truncateInvalidTxSize = in.readInt(); Set<Long> truncateInvalidTx = emptySet(dest.getTruncateInvalidTx()); for (int i = 0; i < truncateInvalidTxSize; i++) { truncateInvalidTx.add(in.readLong()); } dest.setTruncateInvalidTx(truncateInvalidTx); dest.setTruncateInvalidTxTime(in.readLong()); }
@Override public void decode(TransactionEdit dest, DataInput in) throws IOException { super.decode(dest, in); int typeIdx = in.readInt(); // null transaction type is represented as -1 if (typeIdx < 0) { dest.setType(null); } else { try { dest.setType(TransactionType.values()[typeIdx]); } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("Type enum ordinal value is out of range: " + typeIdx); } } int truncateInvalidTxSize = in.readInt(); Set<Long> truncateInvalidTx = emptySet(dest.getTruncateInvalidTx()); for (int i = 0; i < truncateInvalidTxSize; i++) { truncateInvalidTx.add(in.readLong()); } dest.setTruncateInvalidTx(truncateInvalidTx); dest.setTruncateInvalidTxTime(in.readLong()); }
@Override public void encode(TransactionEdit src, DataOutput out) throws IOException { super.encode(src, out); // null transaction type is represented as -1 if (src.getType() == null) { out.writeInt(-1); } else { out.writeInt(src.getType().ordinal()); } Set<Long> truncateInvalidTx = src.getTruncateInvalidTx(); if (truncateInvalidTx == null) { out.writeInt(0); } else { out.writeInt(truncateInvalidTx.size()); for (long id : truncateInvalidTx) { out.writeLong(id); } } out.writeLong(src.getTruncateInvalidTxTime()); }
@Override public void encode(TransactionEdit src, DataOutput out) throws IOException { super.encode(src, out); // null transaction type is represented as -1 if (src.getType() == null) { out.writeInt(-1); } else { out.writeInt(src.getType().ordinal()); } Set<Long> truncateInvalidTx = src.getTruncateInvalidTx(); if (truncateInvalidTx == null) { out.writeInt(0); } else { out.writeInt(truncateInvalidTx.size()); for (long id : truncateInvalidTx) { out.writeLong(id); } } out.writeLong(src.getTruncateInvalidTxTime()); }
@Test public void testV2SerdeCompat() throws Exception { TransactionEditCodecs.TransactionEditCodec olderCodec = new TransactionEditCodecs.TransactionEditCodecV2(); // start tx edit and committed tx edit cover all fields of tx edit // NOTE: transaction type to null as this is expected default for decoding older versions that doesn't store it verifyDecodingSupportsOlderVersion(TransactionEdit.createStarted(2L, 100L, 1000L, null), olderCodec); verifyDecodingSupportsOlderVersion( TransactionEdit.createCommitted(2L, Sets.newHashSet(new ChangeId(COL)), 3L, true), olderCodec); }
@Override public void write(DataOutput out) throws IOException { TransactionEditCodecs.encode(this, out, new TransactionEditCodecs.TransactionEditCodecV2()); } }