def ASCII(ld: LogicalData) -> bytes: """ Representation code 20, Variable length identifier. Length up to 2**30-1 bytes. [RP66V1 Appendix B Section B.20] """ size: int = UVARI(ld) return ld.chunk(size)
def SNORM(ld: LogicalData) -> int: """ Representation code 13, Signed 2-byte integer. [RP66V1 Appendix B Section B.13] """ by = ld.chunk(2) value = struct.unpack('>h', by) return value[0]
def ULONG(ld: LogicalData) -> int: """ Representation code 16, Unsigned 4-byte integer. [RP66V1 Appendix B Section B.17] """ by = ld.chunk(4) value = struct.unpack('>I', by) return value[0]
def VSINGL(ld: LogicalData) -> float: """Representation code 6, VAX single precision floating point.""" by = ld.chunk(4) s = (by[1] & 0x80) m = ((by[0] & 0x7f) << 16) | (by[3] << 8) | by[2] e = ((by[1] & 0x7f) << 1) | ((by[0] & 0x80) >> 7) if e == 0 and s == 0: # m is arbitrary return 0.0 m = float(m) / (1 << 23) value = (0.5 + m) * 2**(e - 128) if s: return -value return value
def _pascal_string(ld: LogicalData) -> bytes: """Reads a Pascal like string from the LogicalData.""" siz: int = ld.read() return ld.chunk(siz)
def FDOUBL(ld: LogicalData) -> float: """Representation code 7, IEEE double precision floating point.""" by = ld.chunk(8) value = struct.unpack('>d', by) return value[0]
def FSINGL(ld: LogicalData) -> float: """Representation code 2, IEEE single precision floating point.""" by = ld.chunk(4) value = struct.unpack('>f', by) return value[0]
def __init__(self, ld: LogicalData): self.size = UNORM(ld) self.producer_code = UNORM(ld) self.encryption_information = ld.chunk(self.size) self.bytes = ld.chunk(ld.remain)