<s> import sys <EOL> from steel import base , fields <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class Structure ( base . Structure ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Structure , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _bits_left = <NUM_LIT:0> <EOL> self . _bit_buffer = <NUM_LIT:0> <EOL> def read ( self , size = None ) : <EOL> bit_buffer = self . _bit_buffer <EOL> if size > self . _bits_left : <EOL> read_size = int ( ( ( size - self . _bits_left ) + <NUM_LIT:7> ) / <NUM_LIT:8> ) <EOL> field = fields . Integer ( size = read_size ) <EOL> bytes = self . _file . read ( read_size ) <EOL> value = field . decode ( bytes ) <EOL> bit_buffer = ( bit_buffer << ( read_size * <NUM_LIT:8> ) ) | value <EOL> self . _bits_left += read_size * <NUM_LIT:8> <EOL> self . _bits_left -= size <EOL> bits = bit_buffer >> self . _bits_left <EOL> self . _bit_buffer = bit_buffer & ( <NUM_LIT:1> << self . _bits_left ) - <NUM_LIT:1> <EOL> return bits <EOL> def get_raw_bytes ( self ) : <EOL> output = bytearray ( ) <EOL> bits_read = <NUM_LIT:0> <EOL> byte = <NUM_LIT:0> <EOL> for name , field in self . __class__ . _fields . items ( ) : <EOL> if name not in self . _raw_values : <EOL> setattr ( self , name , getattr ( self , name ) ) <EOL> bits_read += field . size <EOL> bits = self . _raw_values [ name ] <EOL> byte = ( byte << field . size ) + bits <EOL> while bits_read >= <NUM_LIT:8> : <EOL> byte >>= <NUM_LIT:8> <EOL> output . append ( byte & <NUM_LIT> ) <EOL> bits_read -= <NUM_LIT:8> <EOL> return bytes ( output ) </s>
