def encode_comp_header(h_type, cs_id, time, size, msg_type, ms_id): """Serialize any type of chunk header.""" if h_type == 3: # just the "basic header" return _encode_basic_header(h_type, cs_id, time) elif h_type == 0: # delegate return encode_full_header(cs_id, time, size, msg_type, ms_id) else: # check time field overflow write_time = time if time >= 0xffffff: write_time = 0xffffff h4 = _s_ulong_b.pack(time) else: write_time = time h4 = '' if h_type == 2: return (_encode_basic_header(h_type, cs_id) + _s_time.pack((write_time >> 8) & 0xffff, write_time & 0xff) + h4) return (_encode_basic_header(h_type, cs_id) + _s_time_size_type.pack((write_time >> 8) & 0xffff, write_time & 0xff, (size >> 8) & 0xffff, size & 0xff, msg_type) + h4)
def _encode_basic_header(h_type, cs_id, time=None): if cs_id > 0x013f: # 256 + 63 base = _s_ext_csid.pack((h_type << 6) | 1, cs_id - 64) elif cs_id > 0x3f: # 63 base = _s_double_uchar.pack(h_type << 6, cs_id - 64) else: base = _s_uchar.pack((h_type << 6) | cs_id) if time >= 0x00ffffff: # implicit None < int return base + _s_ulong_b.pack(time) return base
def encode_full_header(cs_id, time, size, msg_type, ms_id): """Serialize an absolute (type 0) chunk header.""" h1 = _encode_basic_header(0, cs_id) write_time = time if time >= 0xffffff: write_time = 0xffffff h4 = _s_ulong_b.pack(time) else: write_time = time h4 = '' h2 = _s_time_size_type.pack((write_time >> 8) & 0xffff, write_time & 0xff, (size >> 8) & 0xffff, size & 0xff, msg_type) h3 = _s_ulong_l.pack(ms_id) return h1 + h2 + h3 + h4
def encode_comp_header(h_type, cs_id, time, size, msg_type, ms_id): """Serialize any type of chunk header.""" if h_type == 3: # just the "basic header" return _encode_basic_header(h_type, cs_id, time) elif h_type == 0: # delegate return encode_full_header(cs_id, time, size, msg_type, ms_id) else: # check time field overflow write_time = time if time >= 0xffffff: write_time = 0xffffff if time > 0xffffffff: time -= 0xffffffff try: h4 = _s_ulong_b.pack(time) except Exception, e: print 'BAH', h_type, time h4 = '' else:
def generate_response(self, request): return buffer(request, 0, 4) + (buffer(_s_ulong.pack(ms_time(self.epoch_time()))) + buffer(request, 8))
def generate_response(self, request): return (buffer(request, 0, 4) + (buffer(_s_ulong.pack(ms_time(self.epoch_time()))) + buffer(request, 8)))