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 private long sizeBeforeInflating;
33
34 PackedObjectInfo(final long headerOffset, final int packedCRC,
35 final AnyObjectId id) {
36 super(id);
37 offset = headerOffset;
38 crc = packedCRC;
39 }
40
41 /**
42 * Create a new structure to remember information about an object.
43 *
44 * @param id
45 * the identity of the object the new instance tracks.
46 */
47 public PackedObjectInfo(AnyObjectId id) {
48 super(id);
49 }
50
51 /**
52 * Get offset in pack when object has been already written
53 *
54 * @return offset in pack when object has been already written, or 0 if it
55 * has not been written yet
56 */
57 public long getOffset() {
58 return offset;
59 }
60
61 /**
62 * Set the offset in pack when object has been written to.
63 *
64 * @param offset
65 * offset where written object starts
66 */
67 public void setOffset(long offset) {
68 this.offset = offset;
69 }
70
71 /**
72 * Get the 32 bit CRC checksum for the packed data.
73 *
74 * @return the 32 bit CRC checksum for the packed data.
75 */
76 public int getCRC() {
77 return crc;
78 }
79
80 /**
81 * Record the 32 bit CRC checksum for the packed data.
82 *
83 * @param crc
84 * checksum of all packed data (including object type code,
85 * inflated length and delta base reference) as computed by
86 * {@link java.util.zip.CRC32}.
87 */
88 public void setCRC(int crc) {
89 this.crc = crc;
90 }
91
92 /**
93 * Get the object type.
94 *
95 * @return the object type. The default type is OBJ_BAD, which is considered
96 * as unknown or invalid type.
97 * @since 4.9
98 */
99 public int getType() {
100 return type;
101 }
102
103 /**
104 * Record the object type if applicable.
105 *
106 * @param type
107 * the object type.
108 * @since 4.9
109 */
110 public void setType(int type) {
111 this.type = type;
112 }
113
114 void setSize(long sizeBeforeInflating) {
115 this.sizeBeforeInflating = sizeBeforeInflating;
116 }
117
118 long getSize() {
119 return sizeBeforeInflating;
120 }
121 }