Decoders¶
Used to decode the low level contents of files extracted from MPQFiles
ByteDecoder¶
-
class
sc2reader.decoders.
ByteDecoder
(contents, endian)¶ Parameters: - contents – The string or file-like object to decode
- endian – Either > or <. Indicates the endian the bytes are stored in.
Used to unpack parse byte aligned files.
-
done
()¶ Returns true when all bytes have been decoded
-
peek
(count)¶ Returns the raw byte string for the next
count
bytes
-
read_bytes
(count)¶ Returns the next
count
bytes as a byte string
-
read_cstring
(encoding=u'utf8')¶ Read a NULL byte terminated character string decoded with given encoding (default utf8). Ignores endian.
-
read_range
(start, end)¶ Returns the raw byte string from the indicated address range
-
read_string
(count, encoding=u'utf8')¶ Read a string in given encoding (default utf8) that is
count
bytes long
-
read_uint
(count)¶ Returns the next
count
bytes as an unsigned integer
-
read_uint16
()¶ Returns the next two bytes as an unsigned integer
-
read_uint32
()¶ Returns the next four bytes as an unsigned integer
-
read_uint64
()¶ Returns the next eight bytes as an unsigned integer
-
read_uint8
()¶ Returns the next byte as an unsigned integer
BitPackedDecoder¶
-
class
sc2reader.decoders.
BitPackedDecoder
(contents)¶ Parameters: contents – The string of file-like object to decode Extends
ByteDecoder
. Always packed BIG_ENDIANAdds capabilities for parsing files that Blizzard has packed in bits and not in bytes.
-
byte_align
()¶ Moves cursor to the beginning of the next byte
-
done
()¶ Returns true when all bytes in the buffer have been used
-
read_aligned_bytes
(count)¶ Skips to the beginning of the next byte and returns the next
count
bytes as a byte string
-
read_aligned_string
(count, encoding=u'utf8')¶ Skips to the beginning of the next byte and returns the next
count
bytes decoded with encoding (default utf8)
-
read_bits
(count)¶ Returns the next
count
bits as an unsigned integer
-
read_bytes
(count)¶ Returns the next
count*8
bits as a byte string
-
read_frames
()¶ Reads a frame count as an unsigned integer
-
read_struct
(datatype=None)¶ Reads a nested data structure. If the type is not specified the first byte is used as the type identifier.
-
read_uint16
()¶ Returns the next 16 bits as an unsigned integer
-
read_uint32
()¶ Returns the next 32 bits as an unsigned integer
-
read_uint64
()¶ Returns the next 64 bits as an unsigned integer
-
read_uint8
()¶ Returns the next 8 bits as an unsigned integer
-
read_vint
()¶ Reads a signed integer of variable length
-