Permalink
Browse files

Add `Sexplib` conversion functions to `Cstruct.t` buffers

Closes #27 #22
  • Loading branch information...
1 parent 716855f commit ab204bdb29b1042e2102ea4480fa98ed41748069 @avsm committed Jul 5, 2014
Showing with 38 additions and 14 deletions.
  1. +3 −1 CHANGES
  2. +2 −1 _oasis
  3. +15 −1 _tags
  4. +2 −2 lib/META
  5. +5 −1 lib/cstruct.ml
  6. +3 −3 lib/cstruct.mli
  7. +2 −1 lib_test/basic.ml
  8. +6 −4 setup.ml
View
@@ -2,7 +2,9 @@
* Add bounds checks for `Cstruct.BE/LE` functions that violate a view.
Previously, only bounds errors on the underlying buffers would raise.
Bug #25, reported by Mindy Preston in mirage/mirage-tcpip#56.
-* Add 'Lwt_cstruct.complete' convenience function
+* Add 'Lwt_cstruct.complete' to ensure that `read`/`write` operatiosn
+ run to completion.
+* Add `Sexplib` conversion functions to `Cstruct.t` values (#27 #22).
1.2.0 (2014-06-06):
View
3 _oasis
@@ -22,7 +22,8 @@ Flag unix
Library cstruct
Path: lib/
Modules: Cstruct
- BuildDepends: bigarray, ocplib-endian, ocplib-endian.bigstring
+ BuildDepends: bigarray, ocplib-endian, ocplib-endian.bigstring, sexplib, sexplib.syntax
+ XMETARequires: bigarray, ocplib-endian, ocplib-endian.bigstring, sexplib
CSources: cstruct_stubs.c
CCOpt: -O3 -Wall
View
16 _tags
@@ -1,7 +1,7 @@
true: inline(10)
true: debug
# OASIS_START
-# DO NOT EDIT (digest: cf7382094a64bb443a07a02beeb4573e)
+# DO NOT EDIT (digest: 23fcb4c5868df0e96ba61f6b1ca9719b)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
@@ -23,15 +23,21 @@ true: debug
<lib/*.ml{,i}>: pkg_bigarray
<lib/*.ml{,i}>: pkg_ocplib-endian
<lib/*.ml{,i}>: pkg_ocplib-endian.bigstring
+<lib/*.ml{,i}>: pkg_sexplib
+<lib/*.ml{,i}>: pkg_sexplib.syntax
"lib/cstruct_stubs.c": pkg_bigarray
"lib/cstruct_stubs.c": pkg_ocplib-endian
"lib/cstruct_stubs.c": pkg_ocplib-endian.bigstring
+"lib/cstruct_stubs.c": pkg_sexplib
+"lib/cstruct_stubs.c": pkg_sexplib.syntax
# Library async_cstruct
"async/async_cstruct.cmxs": use_async_cstruct
<async/*.ml{,i}>: pkg_async
<async/*.ml{,i}>: pkg_bigarray
<async/*.ml{,i}>: pkg_ocplib-endian
<async/*.ml{,i}>: pkg_ocplib-endian.bigstring
+<async/*.ml{,i}>: pkg_sexplib
+<async/*.ml{,i}>: pkg_sexplib.syntax
<async/*.ml{,i}>: pkg_threads
<async/*.ml{,i}>: use_cstruct
# Library lwt_cstruct
@@ -40,12 +46,16 @@ true: debug
<lwt/*.ml{,i}>: pkg_lwt.unix
<lwt/*.ml{,i}>: pkg_ocplib-endian
<lwt/*.ml{,i}>: pkg_ocplib-endian.bigstring
+<lwt/*.ml{,i}>: pkg_sexplib
+<lwt/*.ml{,i}>: pkg_sexplib.syntax
<lwt/*.ml{,i}>: use_cstruct
# Library unix_cstruct
"unix/unix_cstruct.cmxs": use_unix_cstruct
<unix/*.ml{,i}>: pkg_bigarray
<unix/*.ml{,i}>: pkg_ocplib-endian
<unix/*.ml{,i}>: pkg_ocplib-endian.bigstring
+<unix/*.ml{,i}>: pkg_sexplib
+<unix/*.ml{,i}>: pkg_sexplib.syntax
<unix/*.ml{,i}>: pkg_unix
<unix/*.ml{,i}>: use_cstruct
# Library cstruct-syntax
@@ -59,12 +69,16 @@ true: debug
"lib_test/bounds.byte": pkg_oUnit
"lib_test/bounds.byte": pkg_ocplib-endian
"lib_test/bounds.byte": pkg_ocplib-endian.bigstring
+"lib_test/bounds.byte": pkg_sexplib
+"lib_test/bounds.byte": pkg_sexplib.syntax
"lib_test/bounds.byte": pkg_unix
"lib_test/bounds.byte": use_cstruct
<lib_test/*.ml{,i}>: pkg_bigarray
<lib_test/*.ml{,i}>: pkg_oUnit
<lib_test/*.ml{,i}>: pkg_ocplib-endian
<lib_test/*.ml{,i}>: pkg_ocplib-endian.bigstring
+<lib_test/*.ml{,i}>: pkg_sexplib
+<lib_test/*.ml{,i}>: pkg_sexplib.syntax
<lib_test/*.ml{,i}>: pkg_unix
<lib_test/*.ml{,i}>: use_cstruct
# OASIS_STOP
View
@@ -1,8 +1,8 @@
# OASIS_START
-# DO NOT EDIT (digest: 91e2fe12c44bab236587481b82e2b504)
+# DO NOT EDIT (digest: 965c5de00a2446b9f485b4466439073e)
version = "1.3.0"
description = "Manipulate external buffers as C-like structs"
-requires = "bigarray ocplib-endian ocplib-endian.bigstring"
+requires = "bigarray ocplib-endian ocplib-endian.bigstring sexplib"
archive(byte) = "cstruct.cma"
archive(byte, plugin) = "cstruct.cma"
archive(native) = "cstruct.cmxa"
View
@@ -15,14 +15,18 @@
*)
open Printf
+open Sexplib.Std
type buffer = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
+let buffer_of_sexp b = Sexplib.Conv.bigstring_of_sexp b
+let sexp_of_buffer b = Sexplib.Conv.sexp_of_bigstring b
+
type t = {
buffer: buffer;
off : int;
len : int;
-}
+} with sexp
let of_bigarray ?(off=0) ?len buffer =
let len =
View
@@ -1,5 +1,5 @@
(*
- * Copyright (c) 2012-2013 Anil Madhavapeddy <anil@recoil.org>
+ * Copyright (c) 2012-2014 Anil Madhavapeddy <anil@recoil.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -128,15 +128,15 @@ val string_to_bar16 : string -> bar16 option
(** {2 Base types } *)
-type buffer = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
+type buffer = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t with sexp
(** Type of a buffer. A cstruct is composed of an underlying buffer
and position/length within this buffer. *)
type t = private {
buffer: buffer;
off : int;
len : int;
-}
+} with sexp
(** Type of a cstruct. *)
type byte = char
View
@@ -86,5 +86,6 @@ let _ =
assert(Cstruct.BE.get_uint32 be 3 = 0xbeef_l);
assert(get_foo_b be = 44);
assert(get_foo_a be = 7);
- hexdump_foo be
+ hexdump_foo be;
+ print_endline (Sexplib.Sexp.to_string_hum (Cstruct.sexp_of_t be))
View
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.3.0 *)
(* OASIS_START *)
-(* DO NOT EDIT (digest: 969933c9023342765e3038626d287b64) *)
+(* DO NOT EDIT (digest: f36ba32dcd4467e09742bf3c67920161) *)
(*
Regenerated by OASIS v0.4.4
Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6930,7 +6930,9 @@ let setup_t =
[
FindlibPackage ("bigarray", None);
FindlibPackage ("ocplib-endian", None);
- FindlibPackage ("ocplib-endian.bigstring", None)
+ FindlibPackage ("ocplib-endian.bigstring", None);
+ FindlibPackage ("sexplib", None);
+ FindlibPackage ("sexplib.syntax", None)
];
bs_build_tools = [ExternalTool "ocamlbuild"];
bs_c_sources = ["cstruct_stubs.c"];
@@ -7190,14 +7192,14 @@ let setup_t =
};
oasis_fn = Some "_oasis";
oasis_version = "0.4.4";
- oasis_digest = Some "òÊCB8BݲöÙk¢'\133?\149";
+ oasis_digest = Some "hѾI\128RºR¾É)¨ã0©\143";
oasis_exec = None;
oasis_setup_args = [];
setup_update = false
};;
let setup () = BaseSetup.setup setup_t;;
-# 7202 "setup.ml"
+# 7204 "setup.ml"
(* OASIS_STOP *)
let () = setup ();;

0 comments on commit ab204bd

Please sign in to comment.