/** * Encode a signed long as a variable length array. * * This method is appropriate for signed integers. It uses zig zag encoding to so that negative * numbers will be represented more compactly. For unsigned values, writeUnsignedVL will be more * efficient. */ public static void writeSignedVL(long data, DataOutput out) throws IOException { writeUnsignedVL(encodeZigZag64(data), out); }
@Override public void toData(DataOutput out) throws IOException { InternalDataSerializer.writeUnsignedVL(this.previousVersion, out); writeReceived(out); }
@Override public void toData(DataOutput out) throws IOException { InternalDataSerializer.writeUnsignedVL(this.previousVersion, out); writeReceived(out); }
@Override public synchronized void toData(DataOutput out) throws IOException { mergeBitSet(); InternalDataSerializer.writeUnsignedVL(this.version, out); int size = (this.exceptions == null) ? 0 : this.exceptions.size(); InternalDataSerializer.writeUnsignedVL(size, out); out.writeBoolean(this.isDepartedMember); if (size > 0) { for (RVVException e : this.exceptions) { InternalDataSerializer.invokeToData(e, out); } } }
public static int calculateBytesForTSandDSID(int dsid) { HeapDataOutputStream out = new HeapDataOutputStream(4 + 8, Version.CURRENT); long now = System.currentTimeMillis(); try { writeUnsignedVL(now, out); writeUnsignedVL(InternalDataSerializer.encodeZigZag64(dsid), out); } catch (IOException ignored) { return 0; } return out.size(); }
private void serializeVersionTag(int entryVersion, long regionVersion, VersionSource versionMember, long timestamp, int dsId, DataOutput out) throws IOException { int memberId = getParent().getDiskInitFile().getOrCreateCanonicalId(versionMember); InternalDataSerializer.writeSignedVL(entryVersion, out); InternalDataSerializer.writeUnsignedVL(regionVersion, out); InternalDataSerializer.writeUnsignedVL(memberId, out); InternalDataSerializer.writeUnsignedVL(timestamp, out); InternalDataSerializer.writeSignedVL(dsId, out); }
@Test public void testMinusOne() throws IOException { InternalDataSerializer.writeUnsignedVL(-1, createDOS()); assertEquals(-1, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMinLong() throws IOException { InternalDataSerializer.writeUnsignedVL(0x7fffffffL + 1, createDOS()); assertEquals(0x7fffffffL + 1, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMaxNegativeShort() throws IOException { InternalDataSerializer.writeUnsignedVL(-0x7fff, createDOS()); assertEquals(-0x7fff, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMaxLong() throws IOException { InternalDataSerializer.writeUnsignedVL(Long.MAX_VALUE, createDOS()); assertEquals(Long.MAX_VALUE, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMinShort() throws IOException { InternalDataSerializer.writeUnsignedVL(0xFF, createDOS()); assertEquals(0xFF, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMinNegativeShort() throws IOException { InternalDataSerializer.writeUnsignedVL(-0xFF, createDOS()); assertEquals(-0xFF, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testZero() throws IOException { InternalDataSerializer.writeUnsignedVL(0, createDOS()); assertEquals(0, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testOne() throws IOException { InternalDataSerializer.writeUnsignedVL(1, createDOS()); assertEquals(1, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMaxByte() throws IOException { InternalDataSerializer.writeUnsignedVL(0x7F, createDOS()); assertEquals(0x7F, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMaxNegativeByte() throws IOException { InternalDataSerializer.writeUnsignedVL(-0x7F, createDOS()); assertEquals(-0x7F, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMaxShort() throws IOException { InternalDataSerializer.writeUnsignedVL(0x7fff, createDOS()); assertEquals(0x7fff, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMin3Byte() throws IOException { InternalDataSerializer.writeUnsignedVL(0xffff, createDOS()); assertEquals(0xffff, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMin3Negative() throws IOException { InternalDataSerializer.writeUnsignedVL(-0xffff, createDOS()); assertEquals(-0xffff, InternalDataSerializer.readUnsignedVL(createDIS())); }
@Test public void testMaxInt() throws IOException { InternalDataSerializer.writeUnsignedVL(0x7fffffff, createDOS()); assertEquals(0x7fffffff, InternalDataSerializer.readUnsignedVL(createDIS())); }