Page
Library
Module
Module type
Parameter
Class
Class type
Source
Bitpack_serializer.Buffer
SourceThe Buffer defines the methods for serializers & deserializers in a buffer. The compression algorithm used by the library works by writing bits after bits instead of bytes.
A dictionary type. It is used as an argument for initialzing writers and readers.
A writer is a Bytes buffer where is written the data. It also contains an optional dictionary for string storage. It also holds statistics on the repartition of bits for each datatype (unsigned int, signed int and string).
Initializes a new buffer as a writer. If with_dict
is set to NoDictionary
, strings will be written in the buffer. If with_dict
is set to Dictionary None
(by default), strings will be replaced by an unknown size integers; a disctionary will be saved and concatenated at the beginning of the buffer after finalization. If with_dict
is set to Dictionary (Some size)
, it does the same than Dictionary None
but it is assumed there will be no more than size
words to save. registered in a dictionary (useful when the same string apprears at different places) and replaced by integers in the buffer. Variable init_size
is the initial size of the writing bytes buffer (by default: 4096)
Returns the bytes representation of the buffer. If there is a dictionary, it is written at the beginning of the buffer.
write buff v size
Writes v
on buff
using size
bits. Value must be positive. Fails with Invalid_argument
if size
is not in [0, 63]
or if v
is negative or greater than 2^size
.
Write unsigned ints
write_bytes_known_size ~len w b
Writes the first len
bytes of b
in argument.
Write a string representation. If the buffer is associated to a dictionary, writes the its associated integer instead.
A reader buffer.
Initializes a buffer as a reader. The with_dict
argument must be the same as the argument used for initializing the writer.
Reads unsigned integers
Reads len
bytes and returns it as a bytes buffer.
Reads a integer representing the number of bytes to read, then reads and return these bytes.
Prints statistics of bits repartition of a buffer.