资 源 简 介
The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml.
(This project was formerly known as "bitmatch").
You can use this module to both parse and generate binary formats, files and protocols.
Bitstring handling is added as primitives to the language, making it exceptionally simple to use and very powerful.
Here is how to parse the header from a GIF image:
let bits = Bitstring.bitstring_of_file "image.gif" in bitmatch bits with | { ("GIF87a"|"GIF89a") : 6*8 : string; (* GIF magic. *) width : 16 : littleendian; height : 16 : littleendian } -> printf "%s: GIF image is %d x %d pixels" filename width height | { _ } -> eprintf "%s: Not a GIF image
" filename
This example shows how to parse the first few fields in a Linux ELF binary (see ):
文 件 列 表
ocaml-bitstring-2.0.4
MANIFEST
config.h.in
bitmatch.ml
byteswap.in.h
bitstring.mli
create_test_pattern.ml
examples
bitstring_persistent.mli
benchmarks
configure
CHANGES
bitstring.ml
COPYING
pa_bitstring.ml
tests
README
configure.ac
COPYING.LIB
aclocal.m4
cil-tools
bitstring_types.ml
bitstring_objinfo.ml
bootstrap
.depend
Makefile.in
coverage-report
TODO
install-sh
bitstring_c.c
META.in
bitstring_config.ml.in
bitstring_persistent.ml