X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=bitmatch.mli;h=c4aacc56a61661bbd44d1dbbaa8c6a2e4e1aa53c;hb=00f782f26fa89fa07dabb7155707b1415f50572b;hp=90f6acccdfd664602b443e43ba780a8fc18e3819;hpb=e87f0879fef8e32e7ae7f7103f420c1612f3863f;p=ocaml-bitstring.git diff --git a/bitmatch.mli b/bitmatch.mli index 90f6acc..c4aacc5 100644 --- a/bitmatch.mli +++ b/bitmatch.mli @@ -15,7 +15,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * $Id: bitmatch.mli,v 1.20 2008-05-08 21:28:28 rjones Exp $ + * $Id$ *) (** @@ -526,6 +526,11 @@ Bitmatch.hexdump_bitstring stdout bits ;; {3 Types} *) +type endian = BigEndian | LittleEndian | NativeEndian + +val string_of_endian : endian -> string +(** Endianness. *) + type bitstring = string * int * int (** [bitstring] is the basic type used to store bitstrings. @@ -629,7 +634,35 @@ val string_of_bitstring : bitstring -> string This function is inefficient. In the best case when the bitstring is nicely byte-aligned we do a [String.sub] operation. If the bitstring isn't aligned then this involves a lot of bit twiddling - and is particularly inefficient. *) + and is particularly inefficient. + + If the bitstring is not a multiple of 8 bits wide then the + final byte of the string contains the high bits set to the + remaining bits and the low bits set to 0. *) + +val bitstring_to_file : bitstring -> string -> unit +(** [bitstring_to_file bits filename] writes the bitstring [bits] + to the file [filename]. It overwrites the output file. + + Some restrictions apply, see {!bitstring_to_chan}. *) + +val bitstring_to_chan : bitstring -> out_channel -> unit +(** [bitstring_to_file bits filename] writes the bitstring [bits] + to the channel [chan]. + + Channels are made up of bytes, bitstrings can be any bit length + including fractions of bytes. So this function only works + if the length of the bitstring is an exact multiple of 8 bits + (otherwise it raises [Invalid_argument "bitstring_to_chan"]). + + Furthermore the function is efficient only in the case where + the bitstring is stored fully aligned, otherwise it has to + do inefficient bit twiddling like {!string_of_bitstring}. + + In the common case where the bitstring was generated by the + [BITSTRING] operator and is an exact multiple of 8 bits wide, + then this function will always work efficiently. +*) (** {3 Printing bitstrings} *) @@ -654,6 +687,12 @@ end (** {3 Miscellaneous} *) +val package : string +(** The package name, always ["ocaml-bitmatch"] *) + +val version : string +(** The package version as a string. *) + val debug : bool ref (** Set this variable to true to enable extended debugging. This only works if debugging was also enabled in the @@ -678,22 +717,34 @@ val extract_int_be_unsigned : string -> int -> int -> int -> int * int * int val extract_int_le_unsigned : string -> int -> int -> int -> int * int * int +val extract_int_ne_unsigned : string -> int -> int -> int -> int * int * int + val extract_int32_be_unsigned : string -> int -> int -> int -> int32 * int * int val extract_int32_le_unsigned : string -> int -> int -> int -> int32 * int * int +val extract_int32_ne_unsigned : string -> int -> int -> int -> int32 * int * int + val extract_int64_be_unsigned : string -> int -> int -> int -> int64 * int * int val extract_int64_le_unsigned : string -> int -> int -> int -> int64 * int * int +val extract_int64_ne_unsigned : string -> int -> int -> int -> int64 * int * int + val construct_bit : Buffer.t -> bool -> int -> exn -> unit val construct_char_unsigned : Buffer.t -> int -> int -> exn -> unit val construct_int_be_unsigned : Buffer.t -> int -> int -> exn -> unit +val construct_int_ne_unsigned : Buffer.t -> int -> int -> exn -> unit + val construct_int32_be_unsigned : Buffer.t -> int32 -> int -> exn -> unit +val construct_int32_ne_unsigned : Buffer.t -> int32 -> int -> exn -> unit + val construct_int64_be_unsigned : Buffer.t -> int64 -> int -> exn -> unit +val construct_int64_ne_unsigned : Buffer.t -> int64 -> int -> exn -> unit + val construct_string : Buffer.t -> string -> unit