Physical Record Handler

Physical Record Attributes

Bit Description
15 Unused, reserved
14 Physical record type (only 0 is defined)
13-12 00 - No checksum, 01 - 16bit checksum, 10, 11 - Undefined
11 Unused, reserved
10 If 1 File number is present in trailer
09 If 1 Record number is present in trailer
08 Unused
07 Unused, reserved
06 If 1 then a previous parity error has occurred
05 If 1 then a previous checksum error has occurred
04 Unused
03 Unused, reserved
02 Unused
01 If 1 there is a predecessor Physical Record
00 If 1 there is a succcessor Physical Record
exception TotalDepth.LIS.core.PhysRec.ExceptionPhysRec

Specialisation of exception for Physical Records.

exception TotalDepth.LIS.core.PhysRec.ExceptionPhysRecEOF

Physical Record unexpected EOF.

exception TotalDepth.LIS.core.PhysRec.ExceptionPhysRecUndefinedChecksum

Physical Record encountered undefined checksum bit.

exception TotalDepth.LIS.core.PhysRec.ExceptionPhysRecUnknownType

Encountered unknown type 1 Physical Record.

exception TotalDepth.LIS.core.PhysRec.ExceptionPhysRecWrite

Physical Record writing.

exception TotalDepth.LIS.core.PhysRec.ExceptionPhysRecTail

Physical Record Trailer exception.

TotalDepth.LIS.core.PhysRec.PR_PRH_LEN_FORMAT = <Struct object at 0x10358e420>

PR Header 4 bytes long, two big-endian 16 bit numbers The struct.Struct() format for the Physical Record Header

TotalDepth.LIS.core.PhysRec.PR_PRH_ATTR_FORMAT = <Struct object at 0x10358e458>

The struct.Struct() format for the Physical Record Header attributes

TotalDepth.LIS.core.PhysRec.PR_PRH_LENGTH = 4

The length of the Physical Record Header

TotalDepth.LIS.core.PhysRec.PR_ATTRIBUTE_BITS = 16

Number of bits in the 2 byte attributes

TotalDepth.LIS.core.PhysRec.PR_SUCCESSOR_ATTRIBUTE_BIT = 0

Successor bit position

TotalDepth.LIS.core.PhysRec.PR_PREDECESSOR_ATTRIBUTE_BIT = 1

Predessor bit position

TotalDepth.LIS.core.PhysRec.PR_OLD_CHECK_ERROR_BIT = 5

Checksum error bit position

TotalDepth.LIS.core.PhysRec.PR_OLD_PARITY_ERROR_BIT = 6

Parity error bit position

TotalDepth.LIS.core.PhysRec.PR_RECORD_NUMBER_BIT = 9

Bit position to indicate there is a record number in the trailer

TotalDepth.LIS.core.PhysRec.PR_FILE_NUMBER_BIT = 10

Bit position to indicate there is a file number in the trailer

TotalDepth.LIS.core.PhysRec.PR_CHECKSUM_BIT = 12

Bit position to indicate there is a 16bit checksum in the trailer

TotalDepth.LIS.core.PhysRec.PR_CHECKSUM_UNDEFINED_BIT = 13

Bit position to indicate checksum is undefined

TotalDepth.LIS.core.PhysRec.PR_TYPE_BIT = 14

Bit position to indicate Physical Record Type

TotalDepth.LIS.core.PhysRec.PR_ATTRIBUTE_UNUSED_ONLY_MASK = 276

Unused only bits - i.e. Unused but not Unused, reserved

TotalDepth.LIS.core.PhysRec.PR_ATTRIBUTE_UNUSED_RESERVED_MASK = 34952

Unused, reserved bit mask

TotalDepth.LIS.core.PhysRec.PR_ATTRIBUTE_UNUSED_MASK = 0

Unused and Unused, reserved bits, 0x899C

TotalDepth.LIS.core.PhysRec.PR_PRT_REC_NUM_FORMAT = <Struct object at 0x10358e490>

The struct.Struct() format for the Physical Record Trailer record number

TotalDepth.LIS.core.PhysRec.PR_PRT_REC_NUM_LEN = 2

The length of the Physical Record Trailer for the record number

TotalDepth.LIS.core.PhysRec.PR_PRT_REC_NUM_MIN = -32768

The minimum record number

TotalDepth.LIS.core.PhysRec.PR_PRT_REC_NUM_MAX = 32767

The maximum record number

TotalDepth.LIS.core.PhysRec.PR_PRT_FILE_NUM_FORMAT = <Struct object at 0x10358e4c8>

The struct.Struct() format for the Physical Record Trailer file number

TotalDepth.LIS.core.PhysRec.PR_PRT_FILE_NUM_LEN = 2

The length of the Physical Record Trailer for the file number

TotalDepth.LIS.core.PhysRec.PR_PRT_FILE_NUM_MIN = -32768

The minimum file number

TotalDepth.LIS.core.PhysRec.PR_PRT_FILE_NUM_MAX = 32767

The maximum file number

TotalDepth.LIS.core.PhysRec.PR_PRT_CHECKSUM_FORMAT = <Struct object at 0x10358e500>

The struct.Struct() format for the Physical Record Trailer checksum

TotalDepth.LIS.core.PhysRec.PR_PRT_CHECKSUM_LEN = 2

The length of the Physical Record Trailer for the checksum

TotalDepth.LIS.core.PhysRec.PR_MAX_LENGTH = 65535

Maximum possible Physical Record length represented by an unsigned 16 bit int

class TotalDepth.LIS.core.PhysRec.PhysRecBase(theFileId, keepGoing)

Base class for physical record read and write. TODO: Checksum reading, writing and testing.

close()

Close the underlying stream, further operations will raise a ValueError.

strHeader()

Returns the header string to go at the top of a list of __str__().

class TotalDepth.LIS.core.PhysRec.PhysRecRead(theFile, theFileId=None, keepGoing=False)

Specialisation of PhysRecBase for reading streams.

readLrBytes(theSize=-1, theLd=None)

Reads theSize logical data bytes and returns it as a bytes() object. If theSize is -1 all logical data for this logical record is returned. If theLd is not None it is extended and returned, otherwise a new bytes() object is created and returned. Returns None on end of logical record.

skipLrBytes(theSize=-1)

Skips logical data and returns a count of skipped bytes. If theSize is -1 all logical data for this logical record is skipped positioning the stream at end of this logical record (Note: not the beginning of the next logical record). Returns 0 on end of logical record.

skipToNextLr()

Skips all remaining logical data, the PR trailer, and the next PR header. This positions stream at the start of the next logical record. May raise an ExceptionPhysRecEOF if there is no further Logical or Physical record. Returns the number of Logical Data bytes skipped.

tellLr()

Returns the absolute file position of the start current Logical record. This value can be safely used in seekLr.

tell()

Returns the absolute position of the file.

seekLr(offset)

External setting of file position directly to the beginning of a PRH or TIF marker (if present). The caller is fully responsible for getting this right!

seekCurrentLrStart()

Setting the file position directly to the beginning of a PRH or TIF marker (if present) for the current Logical Rcord.

hasLd()

Returns True if there is logical data to be read, False otherwise. NOTE: This will return False on file initialisation and only return True once the Physical Record Header has been read.

ldRemaingInPr()

Returns the number of bytes remaining in this particular Physical Record. NOTE: The can be 0 and hasLd() be True if at the end of a Physical Record that has a successor record.

genLd()

A generator that produces a tuple of (logical data, isLrStart) where: logical data - A bytes() object for the logical data in the current PR. isLrStart - A boolean that is True of that LogicalData is the start of a logical record. NOTE: This rewinds the current state of this instance.

class TotalDepth.LIS.core.PhysRec.PhysRecTail(hasRecNum=False, fileNum=None, hasCheckSum=False)

Represents Physical Record Tail fields.

prhAttr

Returns the PRH attributes, to be or’d with any other attributes.

hasTail()

Returns True if any PRT field is present, False otherwise.

computeCheckSum(theB)

Computes the checksum of the byte stream.

class TotalDepth.LIS.core.PhysRec.PhysRecWrite(theFile, theFileId=None, keepGoing=False, hasTif=False, thePrLen=65535, thePrt=<TotalDepth.LIS.core.PhysRec.PhysRecTail object at 0x10356ab10>)

Specialisation of PhysRecBase for writing to files.

close()

Close the Physical Record Handler and the underlying stream.

writeLr(theLr)

Splits a Logical Record into into Physical Records and writes them to the stream. These Physical Records have trailer records if required. Returns the tell() of the start of the LR.

Table Of Contents

Previous topic

TIF Marker Handling

Next topic

Logical Record Handler

This Page