package bitpack_serializer

  1. Overview
  2. Docs

Module Bitpack_serializer.BufferSource

The 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.

Sourcetype 'dict dictionary =
  1. | NoDictionary
  2. | Dictionary of 'dict

A dictionary type. It is used as an argument for initialzing writers and readers.

Writer

Sourcetype writer

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).

Sourceval initialize_writer : ?with_dict:int option dictionary -> ?init_size:int -> unit -> writer

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)

Sourceval finalize : writer -> Bytes.t

Returns the bytes representation of the buffer. If there is a dictionary, it is written at the beginning of the buffer.

Sourceval write : writer -> int64 -> int -> unit

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.

Sourceval write_bool : writer -> bool -> unit

Writes a boolean on 1 bit: 0 if false, 1 if true.

Write unsigned ints

Sourceval write_uint8 : writer -> int -> unit

Equivalent to write w v 8

Sourceval write_uint16 : writer -> int -> unit

Equivalent to write w v 16

Sourceval write_uint32 : writer -> int -> unit

Equivalent to write w v 32

Sourceval write_uint63 : writer -> int64 -> unit

Equivalent to write w v 63

Sourceval write_z : writer -> Z.t -> unit

Writes an unbounded integer.

Sourceval write_signed_int : writer -> int -> unit

Same as write_z w (Z.of_int i)

Sourceval write_bytes_known_length : len:int -> writer -> Bytes.t -> unit

write_bytes_known_size ~len w b Writes the first len bytes of b in argument.

Sourceval write_bytes : writer -> Bytes.t -> unit

Writes a bytes buffer of any size.

Sourceval write_str_repr : writer -> string -> unit

Write a string representation. If the buffer is associated to a dictionary, writes the its associated integer instead.

Reader

Sourcetype reader

A reader buffer.

Sourceval initialize_reader : ?with_dict:int option dictionary -> Bytes.t -> reader

Initializes a buffer as a reader. The with_dict argument must be the same as the argument used for initializing the writer.

Sourceval read : reader -> int -> int64

read buff n reads n bits on the buffer as an unsigned value

Sourceval read_bool : reader -> bool

Reads 1 bit, returns true if 1, false otherwise

Reads unsigned integers

Sourceval read_uint8 : reader -> int

Reads 8 bits

Sourceval read_uint16 : reader -> int

Reads 16 bits

Sourceval read_uint32 : reader -> int

Reads 32 bits

Sourceval read_uint63 : reader -> int64

Reads 63 bits

Sourceval read_signed_int : reader -> int

Reads an unsigned int prefixed by its size.

Sourceval read_z : reader -> Z.t

Reads an unbounded integer

Sourceval read_bytes_known_length : len:int -> reader -> bytes

Reads len bytes and returns it as a bytes buffer.

Sourceval read_bytes : reader -> Bytes.t

Reads a integer representing the number of bytes to read, then reads and return these bytes.

Sourceval read_str_repr : reader -> string

Reads a string representation

Statistics

Sourceval print_stats : Format.formatter -> writer -> unit

Prints statistics of bits repartition of a buffer.

OCaml

Innovation. Community. Security.