summaryrefslogtreecommitdiff
path: root/libbio/geti.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-13 00:46:24 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-13 00:46:24 -0700
commit20bb032dc16ab0a0a20e9a5705738c797ac4b3da (patch)
tree015f8be7a1d1d99e09e682c35956538ebb57cf50 /libbio/geti.myr
parentac02d84497997778d2c9680f5c7fc26b9814f62c (diff)
downloadmc-20bb032dc16ab0a0a20e9a5705738c797ac4b3da.tar.gz
Add code to subdir in preparation for merging with mc.
Diffstat (limited to 'libbio/geti.myr')
-rw-r--r--libbio/geti.myr63
1 files changed, 63 insertions, 0 deletions
diff --git a/libbio/geti.myr b/libbio/geti.myr
new file mode 100644
index 0000000..48de2bc
--- /dev/null
+++ b/libbio/geti.myr
@@ -0,0 +1,63 @@
+use std
+
+use "bio.use"
+
+pkg bio =
+ /* unsigned big endian */
+ generic getbe8 : (f : file# -> std.option(@a::(numeric,integral)))
+ generic getbe16 : (f : file# -> std.option(@a::(numeric,integral)))
+ generic getbe32 : (f : file# -> std.option(@a::(numeric,integral)))
+ generic getbe64 : (f : file# -> std.option(@a::(numeric,integral)))
+
+ /* signed big endian */
+ generic getle8 : (f : file# -> std.option(@a::(numeric,integral)))
+ generic getle16 : (f : file# -> std.option(@a::(numeric,integral)))
+ generic getle32 : (f : file# -> std.option(@a::(numeric,integral)))
+ generic getle64 : (f : file# -> std.option(@a::(numeric,integral)))
+;;
+
+/*
+ reads a single integer-like value to the output stream, in
+ little endian format
+*/
+generic getle = {f, n -> std.option(@a::(numeric,integral))
+ var v, i
+
+ v = 0
+ if !ensureread(f, n)
+ -> `std.None
+ ;;
+ for i = 0; i < n; i++
+ v |= (f.rbuf[f.rstart++] castto(uint64)) << (8*(i castto(uint64)))
+ ;;
+ -> `std.Some v castto(@a::(numeric,integral))
+}
+
+/*
+ reads a single integer-like value to the output stream, in
+ big endian format
+*/
+generic getbe = {f, n -> std.option(@a::(numeric,integral))
+ var v, i
+
+ v = 0
+ if !ensureread(f,n)
+ -> `std.None
+ ;;
+ for i = 0; i < n; i++
+ v <<= 8
+ v |= (f.rbuf[f.rstart++] castto(uint64))
+ ;;
+ -> `std.Some v castto(@a::(numeric,integral))
+}
+
+generic getbe8 = {f; -> getbe(f, 1)}
+generic getbe16 = {f; -> getbe(f, 2)}
+generic getbe32 = {f; -> getbe(f, 4)}
+generic getbe64 = {f; -> getbe(f, 8)}
+
+generic getle8 = {f; -> getle(f, 1)}
+generic getle16 = {f; -> getle(f, 2)}
+generic getle32 = {f; -> getle(f, 4)}
+generic getle64 = {f; -> getle(f, 8)}
+