Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testPack1(self):
s = bitstring.pack('uint:6, bin, hex, int:6, se, ue, oct', 10, '0b110', 'ff', -1, -6, 6, '54')
t = BitString('uint:6=10, 0b110, 0xff, int:6=-1, se=-6, ue=6, oct=54')
self.assertEqual(s, t)
self.assertRaises(ValueError, pack, 'tomato', '0')
self.assertRaises(ValueError, pack, 'uint', 12)
self.assertRaises(ValueError, pack, 'hex', 'penguin')
self.assertRaises(ValueError, pack, 'hex12', '0x12')
def testStructTokens2(self):
s = pack('>hhl', 1, 2, 3)
a, b, c = s.unpack('>hhl')
self.assertEqual((a, b, c), (1, 2, 3))
s = pack('Q \tL', 1001, 43, 21, 9999)
self.assertEqual(s.unpack('QL'), [1001, 43, 21, 9999])
def pack( self, s, m ):
m._validate()
beginPos = len(s)
# Code Version 1 to the message type (1<<10)
s.append( bitstring.pack('uintbe:16, uintbe:32, uintbe:32', (1<<10) | m.Type, 0, m._MessageID) )
for name, format in self.SpecifiedFields:
_WriteField( s, format, m, name )
for p in m.Parameters:
p.pack( s )
# Fix the length field.
endPos = len(s)
m._Length = (endPos - beginPos) >> 3
s.overwrite( bitstring.pack('uintbe:32', m._Length), beginPos + 16 )
s.pos = endPos
return s
if vp.vui_timing_info_present_flag :
new_bs += pack ('uint:32',vp.vui_num_units_in_tick)
new_bs += pack ('uint:32',vp.vui_time_scale)
new_bs += pack ('uint:1',vp.vui_poc_proportional_to_timing_flag)
if vp.vui_poc_proportional_to_timing_flag :
new_bs += pack ('ue',vp.vui_num_ticks_poc_diff_one_minus1)
new_bs += pack ('uint:1',vp.vui_hrd_parameters_present_flag)
"""
if( vui_hrd_parameters_present_flag )
hrd_parameters( 1, sps_max_sub_layers_minus1 )
"""
new_bs += pack ('uint:1',vp.bitstream_restriction_flag)
if vp. bitstream_restriction_flag :
new_bs += pack ('uint:1',vp.tiles_fixed_structure_flag)
new_bs += pack ('uint:1',vp.motion_vectors_over_pic_boundaries_flag)
new_bs += pack ('uint:1',vp.restricted_ref_pic_lists_flag)
new_bs += pack ('ue',vp.min_spatial_segmentation_idc)
new_bs += pack ('ue',vp.max_bytes_per_pic_denom)
new_bs += pack ('ue',vp.max_bits_per_min_cu_denom)
new_bs += pack ('ue',vp.log2_max_mv_length_horizontal)
new_bs += pack ('ue',vp.log2_max_mv_length_vertical)
new_bs += pack ('uint:1',sps_extension_present_flag)
if sps_extension_present_flag :
new_bs += pack ('uint:1',sps_range_extension_flag)
new_bs += pack ('uint:1',sps_multilayer_extension_flag)
new_bs += pack ('uint:1',sps_3d_extension_flag)
new_bs += pack ('uint:1',sps_extension_5bits)
new_bs += pack ('uint:1',tb.rbsp_stop_one_bit)
while len(new_bs) < t.pos :
new_bs += pack ('uint:1',tb.rbsp_alignment_zero_bit)
def _make_payload(self):
"""
Build the payload from its constituent parts.
"""
b = []
b.append(pack('uint:16', self.packet_identifier).bytes)
return b"".join(b)
def _make_payload(self):
"""
Build the payload from its constituent parts.
"""
b = []
# Protocol name (MQTT)
b.append(build_string("MQTT"))
# Protocol Level (4 == 3.1.1)
b.append(pack('uint:8', 4).bytes)
# CONNECT flags
b.append(self.flags.serialise())
# Keep Alive time
b.append(pack('uint:16', self.keep_alive).bytes)
# Client ID
b.append(build_string(self.client_id))
if self.flags.will:
b.append(build_string(self.will_topic))
# Will message is a uint16 prefixed bytestring
b.append(pack('uint:16', len(self.will_message)).bytes)
b.append(self.will_message)
def get_payload(self):
self.payload_fields.append(("Start Index", self.start_index))
self.payload_fields.append(("Total Count", self.total_count))
self.payload_fields.append(("Tile Devices", self.tile_devices))
start_idex = little_endian(bitstring.pack("uint:8", self.start_index))
payload = start_idex
for tile in self.tile_devices:
reserved1 = little_endian(bitstring.pack("int:16", tile['reserved1']))
reserved2 = little_endian(bitstring.pack("int:16", tile['reserved2']))
reserved3 = little_endian(bitstring.pack("int:16", tile['reserved3']))
reserved4 = little_endian(bitstring.pack("int:16", tile['reserved4']))
user_x = little_endian(bitstring.pack("float:32", tile['user_x']))
user_y = little_endian(bitstring.pack("float:32", tile['user_y']))
width = little_endian(bitstring.pack("uint:8", tile['width']))
height = little_endian(bitstring.pack("uint:8", tile['height']))
reserved5 = little_endian(bitstring.pack("uint:8", tile['reserved5']))
device_version_vendor = little_endian(bitstring.pack("uint:32", tile['device_version_vendor']))
device_version_product = little_endian(bitstring.pack("uint:32", tile['device_version_product']))
device_version_version = little_endian(bitstring.pack("uint:32", tile['device_version_version']))
firmware_build = little_endian(bitstring.pack("uint:64", tile['firmware_build']))
reserved6 = little_endian(bitstring.pack("uint:64", tile['reserved6']))
firmware_version = little_endian(bitstring.pack("uint:32", tile['firmware_version']))
reserved7 = little_endian(bitstring.pack("uint:32", tile['reserved7']))
payload += reserved1 + reserved2 + reserved3 + reserved4 + user_x + user_y + width + height + reserved5 + device_version_vendor + device_version_product + device_version_version + firmware_build + reserved6 + firmware_version + reserved7
total_count = little_endian(bitstring.pack("uint:8", self.total_count))
payload += total_count
return payload