def to_bytes(self): isinlined = self.is_inlined() # Encode the lengths as 0-255 values minlength = ( 0 if self._minlength is None else length_to_byte(self._minlength) ) maxlength = length_to_byte(self._maxlength) # Convert None values to the out-of-band NO_ID constant so they can be # stored as unsigned ints minid = 0xFFFFFFFF if self._minid is None else self._minid maxid = 0xFFFFFFFF if self._maxid is None else self._maxid # Pack the term info into bytes st = self._struct.pack( isinlined, self._weight, self._df, minlength, maxlength, self._maxweight, minid, maxid, ) if isinlined: # Postings are inlined - dump them using the pickle protocol postbytes = dumps(self._inlined, 2) else: postbytes = pack_long(self._offset) + pack_int(self._length) st += postbytes return st
def to_bytes(self): isinlined = self.is_inlined() # Encode the lengths as 0-255 values minlength = (0 if self._minlength is None else length_to_byte(self._minlength)) maxlength = length_to_byte(self._maxlength) # Convert None values to the out-of-band NO_ID constant so they can be # stored as unsigned ints minid = 0xffffffff if self._minid is None else self._minid maxid = 0xffffffff if self._maxid is None else self._maxid # Pack the term info into bytes st = self._struct.pack(isinlined, self._weight, self._df, minlength, maxlength, self._maxweight, minid, maxid) if isinlined: # Postings are inlined - dump them using the pickle protocol postbytes = dumps(self._inlined, -1) else: postbytes = pack_long(self._offset) + pack_int(self._length) st += postbytes return st
def write_int(self, n): self.file.write(pack_int(n))
def write_string4(self, s): self.write(pack_int(len(s)) + s)
def to_bytes(v): return pack_int(v)