From 6019f23767863d963368fd82c0adc3b05e2fb0e5 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 7 May 2008 14:56:53 +0000 Subject: [PATCH] Missing exception arg to construct_bit, and added construct_int32_be_unsigned. --- bitmatch.ml | 15 +++++++++++++-- bitmatch.mli | 6 ++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bitmatch.ml b/bitmatch.ml index ff537bf..a087734 100644 --- a/bitmatch.ml +++ b/bitmatch.ml @@ -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.ml,v 1.11 2008-05-07 14:37:00 rjones Exp $ + * $Id: bitmatch.ml,v 1.12 2008-05-07 14:56:53 rjones Exp $ *) open Printf @@ -624,7 +624,7 @@ module Buffer = struct end (* Construct a single bit. *) -let construct_bit buf b _ = +let construct_bit buf b _ _ = Buffer.add_bit buf b (* Construct a field, flen = [2..8]. *) @@ -643,6 +643,17 @@ let construct_int_be_unsigned buf v flen exn = (* Add the bytes. *) I.map_bytes_be (Buffer._add_bits buf) (Buffer.add_byte buf) v flen +(* Construct a field of exactly 32 bits. *) +let construct_int32_be_unsigned buf v flen _ = + Buffer.add_byte buf + (Int32.to_int (Int32.shift_right_logical v 24)); + Buffer.add_byte buf + (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 16) 0xff_l))); + Buffer.add_byte buf + (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 8) 0xff_l))); + Buffer.add_byte buf + (Int32.to_int (Int32.logand v 0xff_l)) + (* Construct a field of up to 64 bits. *) let construct_int64_be_unsigned buf v flen exn = (* Check value is within range. *) diff --git a/bitmatch.mli b/bitmatch.mli index e237ca7..0b7acb9 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.18 2008-05-07 14:37:00 rjones Exp $ + * $Id: bitmatch.mli,v 1.19 2008-05-07 14:56:53 rjones Exp $ *) (** @@ -685,12 +685,14 @@ val extract_int32_le_unsigned : string -> int -> int -> int -> int32 * int * int val extract_int64_be_unsigned : string -> int -> int -> int -> int64 * int * int -val construct_bit : Buffer.t -> bool -> int -> unit +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_int32_be_unsigned : Buffer.t -> int32 -> int -> exn -> unit + val construct_int64_be_unsigned : Buffer.t -> int64 -> int -> exn -> unit val construct_string : Buffer.t -> string -> unit -- 1.8.3.1