Source

ocaml-cstruct-codegen / lib / cstruct_codegen.mli

Full commit
(* field definition: *)

type cfielddef;

(* how to define structure: *)

value cstruct : string -> list cfielddef -> unit;

(* how to define structure's fields: *)

(* these are represented as [int]: *)
value int8_t   : ?dump_fmt:string -> string -> cfielddef;
value uint8_t  : ?dump_fmt:string -> string -> cfielddef;
value int16_t  : ?dump_fmt:string -> string -> cfielddef;
value uint16_t : ?dump_fmt:string -> string -> cfielddef;
value int31_t  : ?dump_fmt:string -> string -> cfielddef;

(* .. as [int32]: *)
value int32_t  : ?dump_fmt:string -> string -> cfielddef;

(* .. as [int64]: *)
value int64_t  : ?dump_fmt:string -> string -> cfielddef;


(* how to define enumeration: *)

module Enum
 :
  sig
    type enum_type 'a;
    value uint8_t : enum_type int;

    type enum_elt 'a;
    value elt : ?v : 'a -> string -> enum_elt 'a;

    value enum : ?generate_always:bool ->
                 string -> enum_type 'a -> list (enum_elt 'a) ->
                 (string -> cfielddef)
    ;
  end
;

(* how to write an .ml-file with generated code:
   let () = codegen "filename"
 *)

value codegen : string -> unit;