@Override public Long deserialize(DataInput in, int available) throws IOException { return Varint.readUnsignedVarLong(in); } };
/** * @param in to read bytes from * @return decode value * @throws IOException if {@link DataInput} throws {@link IOException} * @throws IllegalArgumentException if variable-length value does not terminate after 9 bytes * have been read * @see #writeSignedVarLong(long, DataOutput) */ public static long readSignedVarLong(DataInput in) throws IOException { long raw = readUnsignedVarLong(in); // This undoes the trick in writeSignedVarLong() long temp = (((raw << 63) >> 63) ^ raw) >> 1; // This extra step lets us deal with the largest signed values by treating // negative results from read unsigned methods as like unsigned values // Must re-flip the top bit if the original read value had it set. return temp ^ (raw & (1L << 63)); }
/** * @param in to read bytes from * @return decode value * @throws IOException if {@link DataInput} throws {@link IOException} * @throws IllegalArgumentException if variable-length value does not terminate after 9 bytes * have been read * @see #writeSignedVarLong(long, DataOutput) */ public static long readSignedVarLong(DataInput in) throws IOException { long raw = readUnsignedVarLong(in); // This undoes the trick in writeSignedVarLong() long temp = (((raw << 63) >> 63) ^ raw) >> 1; // This extra step lets us deal with the largest signed values by treating // negative results from read unsigned methods as like unsigned values // Must re-flip the top bit if the original read value had it set. return temp ^ (raw & (1L << 63)); }
public static long[] readUnsignedLongArray(DataInput in) throws IOException { final int length = readLength(in); long[] values = new long[length]; for (int i = 0; i < length; i++) { values[i] = readUnsignedVarLong(in); } return values; }
public static long[] readUnsignedLongArray(DataInput in) throws IOException { final int length = readLength(in); long[] values = new long[length]; for (int i = 0; i < length; i++) { values[i] = readUnsignedVarLong(in); } return values; }
public final RevPerson readRevPerson(DataInput in) throws IOException { final String name = in.readUTF(); final String email = in.readUTF(); final long timestamp = readUnsignedVarLong(in); final int tzOffset = readUnsignedVarInt(in); return RevPersonBuilder.build(name.length() == 0 ? null : name, email.length() == 0 ? null : email, timestamp, tzOffset); }
public final RevPerson readRevPerson(DataInput in) throws IOException { final String name = in.readUTF(); final String email = in.readUTF(); final long timestamp = readUnsignedVarLong(in); final int tzOffset = readUnsignedVarInt(in); return RevPerson.builder().build(name.length() == 0 ? null : name, email.length() == 0 ? null : email, timestamp, tzOffset); }
public static Header parse(ByteBuffer data) { DataInput in = RevTreeFormat.asDataInput(data); try { final int type = in.readUnsignedByte(); TYPE _type = TYPE.valueOf(type); Preconditions.checkArgument(TYPE.TREE.equals(_type)); final long size = Varint.readUnsignedVarLong(in); final int trees = Varint.readUnsignedVarInt(in); return new Header(size, trees); } catch (IOException e) { throw new RuntimeException(e); } } }
public static Header parse(ByteBuffer data) { DataInput in = RevTreeFormat.asDataInput(data); try { final int type = in.readUnsignedByte(); TYPE _type = TYPE.valueOf(type); Preconditions.checkArgument(TYPE.TREE.equals(_type)); final long size = Varint.readUnsignedVarLong(in); final int trees = Varint.readUnsignedVarInt(in); return new Header(size, trees); } catch (IOException e) { throw Throwables.propagate(e); } } }
public static DAG deserialize(TreeId id, DataInput in) throws IOException { final ObjectId treeId = ObjectId.readFrom(in); final STATE state = STATE.values()[in.readByte() & 0xFF]; final long childCount = Varint.readUnsignedVarLong(in); final int childrenSize = Varint.readUnsignedVarInt(in); final int bucketSize = Varint.readUnsignedVarInt(in); Set<NodeId> children = ImmutableSet.of(); Set<TreeId> buckets = ImmutableSet.of(); if (childrenSize > 0) { children = new HashSet<>(); for (int i = 0; i < childrenSize; i++) { NodeId nid = NodeId.read(in); children.add(nid); } } if (bucketSize > 0) { buckets = new HashSet<>(); for (int i = 0; i < bucketSize; i++) { final int len = Varint.readUnsignedVarInt(in); final byte[] bucketIndicesByDepth = new byte[len]; in.readFully(bucketIndicesByDepth); buckets.add(new TreeId(bucketIndicesByDepth)); } } DAG dag = new DAG(id, treeId, childCount, state, children, buckets); return dag; }
public RevTree readTree(@Nullable ObjectId id, DataInput in) throws IOException { final long size = readUnsignedVarLong(in); final int treeCount = readUnsignedVarInt(in);
public RevTree readTree(@Nullable ObjectId id, DataInput in) throws IOException { final long size = readUnsignedVarLong(in); final int treeCount = readUnsignedVarInt(in);
private void checkUnsignedVarLong(final long value) throws IOException { ByteArrayDataOutput out = newDataOutput(); writeUnsignedVarLong(value, out); long read = readUnsignedVarLong(newDataInput(out.toByteArray())); assertEquals(value, read); } }
private void checkUnsignedVarLong(final long value) throws IOException { ByteArrayDataOutput out = newDataOutput(); writeUnsignedVarLong(value, out); long read = readUnsignedVarLong(newDataInput(out.toByteArray())); assertEquals(value, read); } }