Permalink
Browse files

better README

  • Loading branch information...
1 parent 2db5146 commit 8ee5d9d578f1b5dcc6005322958570a87775d8a3 @avsm committed Dec 13, 2012
Showing with 54 additions and 5 deletions.
  1. +54 −5 README.md
View
@@ -1,6 +1,55 @@
-WIP: see
-https://github.com/avsm/mirage/issues/94
+Cstruct is a library and syntax extension to make it easier to access C-like
+structures directly from OCaml. It supports both reading and writing to these
+structures, and they are accessed via the `Bigarray` module.
-The `unix` directory contains a standard OCaml version,
-and the `xen` directory bundles a custom `Bigarray` module
-with no dependency on UNIX (no `map_file` function).
+An example pcap description is:
+
+```
+cstruct pcap_header {
+ uint32_t magic_number; (* magic number *)
+ uint16_t version_major; (* major version number *)
+ uint16_t version_minor; (* minor version number *)
+ uint32_t thiszone; (* GMT to local correction *)
+ uint32_t sigfigs; (* accuracy of timestamps *)
+ uint32_t snaplen; (* max length of captured packets, in octets *)
+ uint32_t network (* data link type *)
+} as little_endian
+
+cstruct pcap_packet {
+ uint32_t ts_sec; (* timestamp seconds *)
+ uint32_t ts_usec; (* timestamp microseconds *)
+ uint32_t incl_len; (* number of octets of packet saved in file *)
+ uint32_t orig_len (* actual length of packet *)
+} as little_endian
+
+cstruct ethernet {
+ uint8_t dst[6];
+ uint8_t src[6];
+ uint16_t ethertype
+} as big_endian
+
+cstruct ipv4 {
+ uint8_t hlen_version;
+ uint8_t tos;
+ uint16_t len;
+ uint16_t id;
+ uint16_t off;
+ uint8_t ttl;
+ uint8_t proto;
+ uint16_t csum;
+ uint8_t src[4];
+ uint8_t dst[4]
+} as big_endian
+```
+
+You can also declare C-like enums:
+
+```
+cenum foo64 {
+ ONE64;
+ TWO64;
+ THREE64
+} as uint64_t
+```
+
+Please see the `lib_test/` directory for more in-depth examples.

0 comments on commit 8ee5d9d

Please sign in to comment.