/** * Compare this ObjectId to a network-byte-order ObjectId. * * @param bs * array containing the other ObjectId in network byte order. * @param p * position within {@code bs} to start the compare at. At least * 20 bytes, starting at this position are required. * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. */ public final int compareTo(byte[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, NB.decodeInt32(bs, p)); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w2, NB.decodeInt32(bs, p + 4)); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w3, NB.decodeInt32(bs, p + 8)); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w4, NB.decodeInt32(bs, p + 12)); if (cmp != 0) return cmp; return NB.compareUInt32(w5, NB.decodeInt32(bs, p + 16)); }
/** {@inheritDoc} */ @Override public long readLong() throws IOException { readFully(buf, 0, 8); return NB.decodeInt64(buf, 0); }
/** * Copy the ObjectId and other meta fields from an existing entry. * <p> * This method copies everything except the path and possibly stage from one * entry to another, supporting renaming. * * @param src * the entry to copy ObjectId and meta fields from. * @param keepStage * if true, the stage attribute will not be copied */ void copyMetaData(DirCacheEntry src, boolean keepStage) { int origflags = NB.decodeUInt16(info, infoOffset + P_FLAGS); int newflags = NB.decodeUInt16(src.info, src.infoOffset + P_FLAGS); System.arraycopy(src.info, src.infoOffset, info, infoOffset, INFO_LEN); final int pLen = origflags & NAME_MASK; final int SHIFTED_STAGE_MASK = 0x3 << 12; final int pStageShifted; if (keepStage) pStageShifted = origflags & SHIFTED_STAGE_MASK; else pStageShifted = newflags & SHIFTED_STAGE_MASK; NB.encodeInt16(info, infoOffset + P_FLAGS, pStageShifted | pLen | (newflags & ~NAME_MASK & ~SHIFTED_STAGE_MASK)); }
private long getOffset(int levelOne, int levelTwo) { final long p = NB.decodeUInt32(offset32[levelOne], levelTwo << 2); if ((p & IS_O64) != 0) return NB.decodeUInt64(offset64, (8 * (int) (p & ~IS_O64))); return p; }
private void encodeHeader(byte[] hdr) { System.arraycopy(FILE_HEADER_MAGIC, 0, hdr, 0, 4); int bs = alignBlocks ? refBlockSize : 0; NB.encodeInt32(hdr, 4, (VERSION_1 << 24) | bs); NB.encodeInt64(hdr, 8, minUpdateIndex); NB.encodeInt64(hdr, 16, maxUpdateIndex); }
private long decodeTS(int pIdx) { final int base = infoOffset + pIdx; final int sec = NB.decodeInt32(info, base); final int ms = NB.decodeInt32(info, base + 4) / 1000000; return 1000L * sec + ms; }
final int version = NB.decodeUInt16(scratch, 4); if (version != 1) throw new IOException(MessageFormat.format( final int opts = NB.decodeUInt16(scratch, 6); if ((opts & OPT_FULL) == 0) throw new IOException(MessageFormat.format( long numEntries = NB.decodeUInt32(scratch, 8); if (numEntries > Integer.MAX_VALUE) throw new IOException(JGitText.get().indexFileIsTooLargeForJgit); for (int i = 0; i < (int) numEntries; i++) { IO.readFully(fd, scratch, 0, 6); int nthObjectId = NB.decodeInt32(scratch, 0); int xorOffset = scratch[4]; int flags = scratch[5];
private byte[] readHeaderOrFooter(long pos, int len) throws IOException { ByteBuffer buf = src.read(pos, len); if (buf.position() != len) { throw new IOException(JGitText.get().shortReadOfBlock); } byte[] tmp = new byte[len]; buf.flip(); buf.get(tmp); if (!isFileHeaderMagic(tmp, 0, len)) { throw new IOException(JGitText.get().invalidReftableFile); } int v = NB.decodeInt32(tmp, 4); int version = v >>> 24; if (VERSION_1 != version) { throw new IOException(MessageFormat.format( JGitText.get().unsupportedReftableVersion, Integer.valueOf(version))); } if (blockSize == -1) { blockSize = v & 0xffffff; } minUpdateIndex = NB.decodeInt64(tmp, 8); maxUpdateIndex = NB.decodeInt64(tmp, 16); return tmp; }
private void encodeTS(int pIdx, long when) { final int base = infoOffset + pIdx; NB.encodeInt32(info, base, (int) (when / 1000)); NB.encodeInt32(info, base + 4, ((int) (when % 1000)) * 1000000); }
/** {@inheritDoc} */ @Override public void writeLong(long v) throws IOException { NB.encodeInt64(buf, 0, v); fd.write(buf, 0, 8); }
int typeAndSize = NB.decodeInt32(buf, ptr); ptr += 4; restartCnt = NB.decodeUInt16(buf, bufLen - 2); restartTbl = bufLen - (restartCnt * 3 + 2); keysStart = ptr;
/** {@inheritDoc} */ @Override public void writeShort(int v) throws IOException { NB.encodeInt16(buf, 0, v); fd.write(buf, 0, 2); }
private short readInt16() { return (short) NB.decodeUInt16(buf, ptr += 2); }
case 2: for (int i = 0; i < 256; i++, ptr += 2) NB.encodeInt16(index, ptr, buckets[i]); break; case 3: case 4: for (int i = 0; i < 256; i++, ptr += 4) NB.encodeInt32(index, ptr, buckets[i]); break; NB.encodeInt16(index, ptr, (int) oe.getOffset()); ptr += 2; NB.encodeInt32(index, ptr, (int) oe.getOffset()); ptr += 4;
/** * Compare this LongObjectId to a network-byte-order LongObjectId. * * @param bs * array containing the other LongObjectId in network byte order. * @param p * position within {@code bs} to start the compare at. At least * 32 bytes, starting at this position are required. * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. */ public final int compareTo(final byte[] bs, final int p) { int cmp; cmp = NB.compareUInt64(w1, NB.decodeInt64(bs, p)); if (cmp != 0) return cmp; cmp = NB.compareUInt64(w2, NB.decodeInt64(bs, p + 8)); if (cmp != 0) return cmp; cmp = NB.compareUInt64(w3, NB.decodeInt64(bs, p + 16)); if (cmp != 0) return cmp; return NB.compareUInt64(w4, NB.decodeInt64(bs, p + 24)); }
fanoutTable = new long[FANOUT]; for (int k = 0; k < FANOUT; k++) fanoutTable[k] = NB.decodeUInt32(fanoutRaw, k * 4); objectCnt = fanoutTable[FANOUT - 1]; IO.readFully(fd, raw, 0, raw.length); for (int i = 0; i < bin.length; i++) bin[i] = NB.decodeInt32(raw, i << 2);
/** * {@inheritDoc} * <p> * Compare this ObjectId to another and obtain a sort ordering. */ @Override public final int compareTo(AnyObjectId other) { if (this == other) return 0; int cmp; cmp = NB.compareUInt32(w1, other.w1); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w2, other.w2); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w3, other.w3); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w4, other.w4); if (cmp != 0) return cmp; return NB.compareUInt32(w5, other.w5); }
if (crc.getValue() != NB.decodeUInt32(ftr, ftrLen - 4)) { throw new IOException(JGitText.get().invalidReftableCRC); refIndexPosition = NB.decodeInt64(ftr, 24); long p = NB.decodeInt64(ftr, 32); objPosition = p >>> 5; objIdLen = (int) (p & 0x1f); objIndexPosition = NB.decodeInt64(ftr, 40); logPosition = NB.decodeInt64(ftr, 48); logIndexPosition = NB.decodeInt64(ftr, 56);
/** * Convert sequence of 8 bytes (network byte order) into unsigned value. * * @param intbuf * buffer to acquire the 8 bytes of data from. * @param offset * position within the buffer to begin reading from. This * position and the next 7 bytes after it (for a total of 8 * bytes) will be read. * @return unsigned integer value that matches the 64 bits read. */ public static long decodeUInt64(final byte[] intbuf, final int offset) { return (decodeUInt32(intbuf, offset) << 32) | decodeUInt32(intbuf, offset + 4); }
long readLogUpdateIndex() { return reverseUpdateIndex(NB.decodeUInt64(nameBuf, nameLen - 8)); }