| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| When I've read in some bytes from a binary file using: let fd = Unix.openfile "some.bin" mode 0o644;; let str = String.create 53;; let n = Unix.read fd str 0 53;; how do I map the content (binary) of 'str' into a data structure of e.g. the following type: type entry = { a : int; b : int; c : int; d : int list; } thank you jonathan heusser -- Key fingerprint = 2A55 EB7C B7EA 6336 7767 4A47 910A 307B 1333 BD6C |
|
#2
| |||
| |||
| On Mon, 14 Jul 2003, Jonathan Heusser wrote: > how do I map the content (binary) of 'str' into a data structure of > e.g. the following type: The problem is severely underconstrained as you state it... Since the code doesn't look like standard ML to me I guess it must be OCaml. Do you know how to get a character at a specific index in a string? Do you know how to get the ordinal value of a character (i.e. turn a character into an integer)? If you know how to do that the rest becomes a small matter of programming -- and of finding out what the problem /really/ is: - how many characters per integer? - what is the byte order? - is there a count of the number of integers in d? - or is there a fixed number? - or are they terminated by a sentinel? .... there are /many/ other variants if you really want to be perverse. -Peter |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.