def get_data_stub(self): bits = BitStream() bits += Rect(XMax=self.width, YMax=self.height) bits.flush() bits.write(self.fps, FIXED8) bits.write(self.num_frames, UI16) return bits.serialize()
def test_flush(): # Test when bits has no data. bits = BitStream("") bits.flush() assert str(bits) == "" assert bits.bits_available == 0 # Test when cursor == 0 bits = BitStream("1111") bits.seek(0) bits.flush() assert str(bits) == "11110000" assert bits.bits_available == 0 # Test when cursor != 0. bits = BitStream("11100") bits.seek(0, os.SEEK_END) bits.flush() assert str(bits) == "11100000" assert bits.bits_available == 0 # Test when already flush. bits = BitStream("11111111") bits.seek(0) bits.flush() assert str(bits) == "11111111" assert bits.bits_available == 0 bits = BitStream("11111111 11111") bits.seek(0, os.SEEK_END) bits.flush() assert str(bits) == "1111111111111000" assert bits.bits_available == 0
def serialize_data(self): bits = BitStream() bits.write(self.characterid, UI16) bits += self.rect bits.flush() flags = BitStream() flags.write(self.text != "") flags.write(self.wordwrap) flags.write(self.multiline) flags.write(self.password) flags.write(self.readonly) flags.write(self.color is not None) flags.write(self.maxlength is not None) flags.write(self.font is not None) flags.write(self.fontclass is not None) flags.write(self.autosize) flags.write(self.layout is not None) flags.write(not self.selectable) flags.write(self.border) flags.write(self.wasstatic) flags.write(self.isHTML) flags.write(self.outlines) bits += flags if self.font is not None: bits.write(self.font.id, UI16) # Doesn't exist yet. if self.fontclass is not None: bits.write(self.fontclass, CString) if self.font is not None: bits.write(self.size, UI16) if self.color is not None: bits += self.color if self.maxlength is not None: bits.write(self.maxlength, UI16) if self.layout is not None: bits += self.layout # Doesn't exist yet. bits.write(self.variable, CString) if self.text != "": bits.write(self.text, CString) return bits.serialize()
def serialize_data(self): bits = BitStream() bits.write(self.characterid, UI16) bits += self.rect bits.flush() flags = BitStream() flags.write(self.text != "") flags.write(self.wordwrap) flags.write(self.multiline) flags.write(self.password) flags.write(self.readonly) flags.write(self.color is not None) flags.write(self.maxlength is not None) flags.write(self.font is not None) flags.write(self.fontclass is not None) flags.write(self.autosize) flags.write(self.layout is not None) flags.write(not self.selectable) flags.write(self.border) flags.write(self.wasstatic) flags.write(self.isHTML) flags.write(self.outlines) bits += flags if self.font is not None: bits.write(self.font.id, UI16) # Doesn't exist yet. bits.write(self.size, UI16) if self.fontclass is not None: bits.write(self.fontclass, CString) if self.color is not None: bits += self.color if self.maxlength is not None: bits.write(self.maxlength, UI16) if self.layout is not None: bits += self.layout # Doesn't exist yet. bits.write(self.variable, CString) if self.text != "": bits.write(self.text, CString) return bits.serialize()