Skip to content

Commit 0cf0919

Browse files
committed
allow tasty version to be inspected
1 parent cc8ffb1 commit 0cf0919

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dotty.tools.tasty
2+
3+
import java.util.UUID
4+
5+
case class TastyHeader(uuid: UUID, majorVersion: Int, minorVersion: Int)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dotty.tools.tasty
2+
3+
import java.util.UUID
4+
5+
import TastyFormat.{MajorVersion, MinorVersion, header}
6+
7+
class TastyHeaderUnpickler(reader: TastyReader) {
8+
import reader._
9+
10+
def this(bytes: Array[Byte]) = this(new TastyReader(bytes))
11+
12+
/**delegates to `readFullHeader`, expecting the following
13+
* - `majorVersion == TastyFormat.MajorVersion`
14+
* - `0 <= minorVersion <= TastyFormat.MinorVersion`
15+
*/
16+
def readHeader(): UUID = {
17+
val h = readFullHeader()
18+
val validVersion = (
19+
h.majorVersion == MajorVersion
20+
&& h.minorVersion >= 0 && h.minorVersion <= MinorVersion
21+
)
22+
check(validVersion,
23+
s"""TASTy signature has wrong version.
24+
| expected: $MajorVersion.$MinorVersion
25+
| found : ${h.majorVersion}.${h.minorVersion}""".stripMargin
26+
)
27+
h.uuid
28+
}
29+
30+
/**Reads the header of a Tasty File
31+
*/
32+
def readFullHeader(): TastyHeader = {
33+
for (i <- 0 until header.length)
34+
check(readByte() == header(i), "not a TASTy file")
35+
val majorVersion = readNat()
36+
val minorVersion = readNat()
37+
val uuid = new UUID(readUncompressedLong(), readUncompressedLong())
38+
TastyHeader(uuid, majorVersion, minorVersion)
39+
}
40+
41+
def isAtEnd: Boolean = reader.isAtEnd
42+
43+
private def check(cond: Boolean, msg: => String): Unit = {
44+
if (!cond) throw new UnpickleException(msg)
45+
}
46+
}

0 commit comments

Comments
 (0)