1 /* 2 * Copyright (C) 2008-2009, Robin Rosenberg <robin.rosenberg@dewire.com> 3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others 4 * 5 * This program and the accompanying materials are made available under the 6 * terms of the Eclipse Distribution License v. 1.0 which is available at 7 * https://www.eclipse.org/org/documents/edl-v10.php. 8 * 9 * SPDX-License-Identifier: BSD-3-Clause 10 */ 11 12 package org.eclipse.jgit.transport; 13 14 import org.eclipse.jgit.lib.AnyObjectId; 15 import org.eclipse.jgit.lib.Constants; 16 import org.eclipse.jgit.lib.ObjectIdOwnerMap; 17 18 /** 19 * Description of an object stored in a pack file, including offset. 20 * <p> 21 * When objects are stored in packs Git needs the ObjectId and the offset 22 * (starting position of the object data) to perform random-access reads of 23 * objects from the pack. This extension of ObjectId includes the offset. 24 */ 25 public class PackedObjectInfo extends ObjectIdOwnerMap.Entry { 26 private long offset; 27 28 private int crc; 29 30 private int type = Constants.OBJ_BAD; 31 32 PackedObjectInfo(final long headerOffset, final int packedCRC, 33 final AnyObjectId id) { 34 super(id); 35 offset = headerOffset; 36 crc = packedCRC; 37 } 38 39 /** 40 * Create a new structure to remember information about an object. 41 * 42 * @param id 43 * the identity of the object the new instance tracks. 44 */ 45 public PackedObjectInfo(AnyObjectId id) { 46 super(id); 47 } 48 49 /** 50 * Get offset in pack when object has been already written 51 * 52 * @return offset in pack when object has been already written, or 0 if it 53 * has not been written yet 54 */ 55 public long getOffset() { 56 return offset; 57 } 58 59 /** 60 * Set the offset in pack when object has been written to. 61 * 62 * @param offset 63 * offset where written object starts 64 */ 65 public void setOffset(long offset) { 66 this.offset = offset; 67 } 68 69 /** 70 * Get the 32 bit CRC checksum for the packed data. 71 * 72 * @return the 32 bit CRC checksum for the packed data. 73 */ 74 public int getCRC() { 75 return crc; 76 } 77 78 /** 79 * Record the 32 bit CRC checksum for the packed data. 80 * 81 * @param crc 82 * checksum of all packed data (including object type code, 83 * inflated length and delta base reference) as computed by 84 * {@link java.util.zip.CRC32}. 85 */ 86 public void setCRC(int crc) { 87 this.crc = crc; 88 } 89 90 /** 91 * Get the object type. 92 * 93 * @return the object type. The default type is OBJ_BAD, which is considered 94 * as unknown or invalid type. 95 * @since 4.9 96 */ 97 public int getType() { 98 return type; 99 } 100 101 /** 102 * Record the object type if applicable. 103 * 104 * @param type 105 * the object type. 106 * @since 4.9 107 */ 108 public void setType(int type) { 109 this.type = type; 110 } 111 }