def MakeOperations(self, headers, group_id): """ Computes the entire set of operations necessary to encode the 'headers' for header-group 'group_id' """ instructions = {'toggl': [], 'clone': [], 'kvsto': [], 'eref': []} incremented_keys = [] self.storage.PinLRU() self.FindOrMakeHeaderGroup(group_id) # make the header group if necessary for k in headers.iterkeys(): ke = self.storage.FindKeyEntry(k) if ke: self.storage.IncrementRefCnt(ke) incremented_keys.append(ke) for k,v in headers.iteritems(): if k == 'cookie': splitvals = [x.lstrip(' ') for x in v.split(';')] splitvals.sort() for splitval in splitvals: self.ProcessKV(k, bohe.encode(k,splitval), group_id, instructions) else: self.ProcessKV(k, bohe.encode(k,v), group_id, instructions) turn_offs = self.DiscoverTurnOffs(group_id, instructions) instructions['toggl'].extend(turn_offs) self.ExecuteInstructionsExceptERefs(group_id, instructions) for ke in incremented_keys: self.storage.DecrementRefCnt(ke) # SerializeInstructions() self.storage.UnPinLRU() self.header_groups[group_id].IncrementGeneration() self.AdjustHeaderGroupEntries(group_id) #FormatOps(instructions, 'MO\t') return instructions
def MakeOperations(self, headers, group_id): """ Computes the entire set of operations necessary to encode the 'headers' for header-group 'group_id' """ instructions = {'toggl': [], 'clone': [], 'kvsto': [], 'eref': []} incremented_keys = [] #self.storage.PinLRU() self.FindOrMakeHeaderGroup(group_id) # make the header group if necessary #print '#' * 80 #print '\n'.join(["%s: %s"%(k,v) for k,v in headers.iteritems()]) #print "LRU(after Make+Execute) ", self.storage.lru_storage.ring #print "HG:", self.header_groups[group_id] for k,v in headers.iteritems(): if k == 'cookie': splitvals = [x.lstrip(' ') for x in v.split(';')] splitvals.sort() for splitval in splitvals: self.ProcessKV(k, bohe.encode(k,splitval,self.is_request), group_id, instructions) else: self.ProcessKV(k, bohe.encode(k,v,self.is_request), group_id, instructions) #print "EXECUTING NON-TURNOFFS" self.ExecuteInstructionsExceptERefs(group_id, instructions) #print "COMPUTING TURNOFFS" turn_offs = self.DiscoverTurnOffs(group_id, instructions) for op in turn_offs: self.ExecuteOp(group_id, op) instructions['toggl'].extend(turn_offs) #print "DONE COMPUTING INSTRUCTIONS" #print FormatOps(instructions) #print "LRU(after Make+Execute) ", self.storage.lru_storage #self.storage.UnPinLRU() self.header_groups[group_id].IncrementGeneration() self.AdjustHeaderGroupEntries(group_id) #FormatOps(instructions, 'MO\t') return instructions
def compress(self, inp_headers, host): data = BitBucket() res = '' for k, v in inp_headers.items(): if k in bohe.ID_TABLE: zz = data.NumBits() # encode as registered header data.StoreBits8(bohe.ID_TABLE.index(k) + 1) l = 0 dohuff = True # Set the binary flag if k in bohe.ENCODERS: data.StoreBit(1) dohuff = False # Set the multiple values flag... if '\u00' in v: data.StoreBit(1) else: data.StoreBit(0) val = bohe.encode(k, v) if dohuff: val_as_list, len_in_bits = self.do_huff(self.huff, val) else: val_as_list = common_utils.StrToList(val) len_in_bits = len(val_as_list) * 8 data.StoreBits22(len(val_as_list)) data.StoreBits((val_as_list, len_in_bits)) else: data.StoreBits8(128 | len(k)) data.StoreBits((common_utils.StrToList(k), len(k) * 8)) data.StoreBit(0) # assume not binary value for now if '\u00' in v: data.StoreBit(1) else: data.StoreBit(0) val_as_list, len_in_bits = self.do_huff(self.huff, v) data.StoreBits22(len(val_as_list)) data.StoreBits((val_as_list, len_in_bits)) return ''.join(common_utils.ListToStr(data.GetAllBits()[0]))
def compress(self, inp_headers, host): data = BitBucket() res = '' for k,v in inp_headers.items(): if k in bohe.ID_TABLE: zz = data.NumBits() # encode as registered header data.StoreBits8(bohe.ID_TABLE.index(k) + 1) l = 0 dohuff = True # Set the binary flag if k in bohe.ENCODERS: data.StoreBit(1) dohuff = False # Set the multiple values flag... if '\u00' in v: data.StoreBit(1) else: data.StoreBit(0) val = bohe.encode(k,v) if dohuff: val_as_list, len_in_bits = self.do_huff(self.huff, val) else: val_as_list = common_utils.StrToList(val) len_in_bits = len(val_as_list) *8 data.StoreBits22(len(val_as_list)) data.StoreBits( (val_as_list, len_in_bits) ) else: data.StoreBits8(128 | len(k)) data.StoreBits((common_utils.StrToList(k), len(k)*8)) data.StoreBit(0) # assume not binary value for now if '\u00' in v: data.StoreBit(1) else: data.StoreBit(0) val_as_list, len_in_bits = self.do_huff(self.huff, v) data.StoreBits22(len(val_as_list)) data.StoreBits((val_as_list, len_in_bits)) return ''.join(common_utils.ListToStr(data.GetAllBits()[0]))