Skip to content
Commits on Source (14)
*~
*.cm[ioxat]
*.[oa]
*.cmx[as]
*.cmti
*.annot
META
bdump
test-stream.dat
test2.bin
*.byte
*.native
*.exe
test_biniou
_build
.merlin
*.install
name = "biniou"
version = "@@VERSION@@"
description = "Extensible binary serialization format"
requires = "easy-format"
archive(byte) = "biniou.cma"
archive(native) = "biniou.cmxa"
archive(native,plugin) = "biniou.cmxs"
VERSION = 1.0.12
all:
@jbuilder build
FLAGS = -g -annot -bin-annot
PACKS = easy-format
test:
@jbuilder runtest
ifeq "$(shell ocamlfind ocamlc -config |grep os_type)" "os_type: Win32"
EXE=.exe
else
EXE=
endif
check: test
BEST = $(shell \
if ocamlfind ocamlopt 2>/dev/null; then \
echo .native; \
else \
echo .byte; \
fi \
)
NATDYNLINK = $(shell \
if [ -f `ocamlfind ocamlc -where`/dynlink.cmxa ]; then \
echo YES; \
else \
echo NO; \
fi \
)
ifeq "${NATDYNLINK}" "YES"
CMXS=biniou.cmxs
endif
.PHONY: default all byte opt install doc test
default: all test_biniou$(EXE)
ifeq "$(BEST)" ".native"
all: byte opt doc META
else
all: byte doc META
endif
byte: biniou.cma bdump.byte
opt: biniou.cmxa $(CMXS) bdump.native
test: test_biniou$(EXE)
./$<
ifndef PREFIX
PREFIX = $(shell dirname $$(dirname $$(which ocamlfind)))
export PREFIX
endif
ifndef BINDIR
BINDIR = $(PREFIX)/bin
export BINDIR
endif
META: META.in Makefile
sed -e 's:@@VERSION@@:$(VERSION):' META.in > META
SOURCES = bi_util.mli bi_util.ml \
bi_share.mli bi_share.ml \
bi_outbuf.mli bi_outbuf.ml bi_inbuf.mli bi_inbuf.ml \
bi_vint.mli bi_vint.ml bi_io.mli bi_io.ml \
bi_dump.ml bi_stream.mli bi_stream.ml
MLI = $(filter %.mli, $(SOURCES))
ML = $(filter %.ml, $(SOURCES))
CMI = $(MLI:.mli=.cmi)
CMT = $(MLI:.mli=.cmt)
ANNOT = $(MLI:.mli=.annot)
CMO = $(ML:.ml=.cmo)
CMX = $(ML:.ml=.cmx)
O = $(ML:.ml=.o)
biniou.cma: $(SOURCES) Makefile
ocamlfind ocamlc -a $(FLAGS) -o biniou.cma \
-package "$(PACKS)" $(SOURCES)
biniou.cmxa: $(SOURCES) Makefile
ocamlfind ocamlopt -a $(FLAGS) \
-o biniou.cmxa -package "$(PACKS)" $(SOURCES)
biniou.cmxs: biniou.cmxa
ocamlfind ocamlopt -shared -linkall -I . -o $@ $^
bdump.byte: biniou.cma bdump.ml
ocamlfind ocamlc -o $@ $(FLAGS) \
-package $(PACKS) -linkpkg $^
bdump.native: biniou.cmxa bdump.ml
ocamlfind ocamlopt -o $@ $(FLAGS) \
-package $(PACKS) -linkpkg $^
test_biniou.byte: biniou.cma test_biniou.ml
ocamlfind ocamlc -o $@ $(FLAGS) \
-package "$(PACKS) unix" -linkpkg $^
test_biniou.native: biniou.cmxa test_biniou.ml
ocamlfind ocamlopt -o $@ $(FLAGS) \
-package "$(PACKS) unix" -linkpkg $^
%$(EXE): %$(BEST)
cp $< $@
doc: doc/index.html
doc/index.html: $(MLI)
mkdir -p doc
ocamlfind ocamldoc -d doc -html -package easy-format $(MLI)
install: META byte
if [ -f bdump.native ]; then \
cp bdump.native $(BINDIR)/bdump$(EXE); \
else \
cp bdump.byte $(BINDIR)/bdump$(EXE); \
fi
ocamlfind install biniou META \
$(MLI) $(CMI) $(CMT) $(ANNOT) $(CMO) biniou.cma \
-optional $(CMX) $(O) biniou.cmxa biniou.a biniou.cmxs
uninstall:
rm -f $(BINDIR)/bdump{.exe,}
ocamlfind remove biniou
.PHONY: clean
.PHONY: clean all check test
clean:
rm -f *.o *.a *.cm[ioxa] *.cmxa *~ *.annot META
rm -f {bdump,test_biniou}{.exe,.byte,.native,}
rm -rf doc
rm -f test.bin test_channels.bin
SUBDIRS =
SVNURL = svn://svn.forge.ocamlcore.org/svnroot/biniou/trunk/biniou
.PHONY: archive
archive:
@echo "Making archive for version $(VERSION)"
@if [ -z "$$WWW" ]; then \
echo '*** Environment variable WWW is undefined ***' >&2; \
exit 1; \
fi
@if [ -n "$$(svn status -q)" ]; then \
echo "*** There are uncommitted changes, aborting. ***" >&2; \
exit 1; \
fi
$(MAKE) && ./bdump -help > $$WWW/bdump-help.txt
mkdir -p $$WWW/biniou-doc
$(MAKE) doc && cp doc/* $$WWW/biniou-doc/
rm -rf /tmp/biniou /tmp/biniou-$(VERSION) && \
cd /tmp && \
svn co "$(SVNURL)" && \
for x in "." $(SUBDIRS); do \
rm -rf /tmp/biniou/$$x/.svn; \
done && \
cd /tmp && cp -r biniou biniou-$(VERSION) && \
tar czf biniou.tar.gz biniou && \
tar cjf biniou.tar.bz2 biniou && \
tar czf biniou-$(VERSION).tar.gz biniou-$(VERSION) && \
tar cjf biniou-$(VERSION).tar.bz2 biniou-$(VERSION)
mv /tmp/biniou.tar.gz /tmp/biniou.tar.bz2 ../releases
mv /tmp/biniou-$(VERSION).tar.gz \
/tmp/biniou-$(VERSION).tar.bz2 ../releases
cp ../releases/biniou.tar.gz $$WWW/
cp ../releases/biniou.tar.bz2 $$WWW/
cp ../releases/biniou-$(VERSION).tar.gz $$WWW/
cp ../releases/biniou-$(VERSION).tar.bz2 $$WWW/
cd ../releases && \
svn add biniou.tar.gz biniou.tar.bz2 \
biniou-$(VERSION).tar.gz biniou-$(VERSION).tar.bz2 && \
svn commit -m "biniou version $(VERSION)"
cp LICENSE $$WWW/biniou-license.txt
cp Changes $$WWW/biniou-changes.txt
cp biniou-format.txt $$WWW/biniou-format.txt
echo 'let biniou_version = "$(VERSION)"' \
> $$WWW/biniou-version.ml
jbuilder clean
1.2.0
\ No newline at end of file
(jbuild_version 1)
(executable
((name bdump)
(public_name bdump)
(package biniou)
(flags (-safe-string))
(libraries (biniou))))
opam-version: "1.2"
maintainer: "martin@mjambon.com"
authors: ["Martin Jambon"]
homepage: "https://github.com/mjambon/biniou"
bug-reports: "https://github.com/mjambon/biniou/issues"
dev-repo: "https://github.com/mjambon/biniou.git"
license: "BSD-3-Clause"
build: [
["jbuilder" "build" "-p" name "-j" jobs]
]
build-test: [
["jbuilder" "runtest" "-p" name]
]
depends: [
"conf-which" {build}
"jbuilder" {build}
"easy-format"
]
available: [ocaml-version >= "4.02.3"]
\ No newline at end of file
biniou (1.2.0-1) unstable; urgency=medium
* Team upload
* New upstream release
* Update Homepage and debian/watch
* Bump debhelper compat level to 12
* Bump Standards-Version to 4.4.0
* Remove Hendrik from Uploaders
* Update Vcs-*
-- Stéphane Glondu <glondu@debian.org> Mon, 12 Aug 2019 07:09:19 +0200
biniou (1.0.12-2) unstable; urgency=medium
* Team upload
......
......@@ -2,16 +2,16 @@ Source: biniou
Section: ocaml
Priority: optional
Maintainer: Debian OCaml Maintainers <debian-ocaml-maint@lists.debian.org>
Uploaders: Hendrik Tews <hendrik@askra.de>
Build-Depends:
ocaml-nox (>= 3.11.1-3~),
ocaml-best-compilers,
ocaml-findlib,
dh-ocaml (>= 0.9~),
debhelper (>= 9),
debhelper (>= 12),
jbuilder,
libeasy-format-ocaml-dev
Standards-Version: 3.9.8
Homepage: https://github.com/mjambon/biniou
Standards-Version: 4.4.0
Homepage: https://github.com/ocaml-community/biniou
Vcs-Git: https://salsa.debian.org/ocaml-team/biniou.git
Vcs-Browser: https://salsa.debian.org/ocaml-team/biniou
......
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Biniou
Upstream-Contact: Martin Jambon <martin@mjambon.com>
......
@OCamlStdlibDir@/biniou/*.annot
@OCamlStdlibDir@/biniou/*dune*
@OCamlStdlibDir@/biniou/*opam*
@OCamlStdlibDir@/biniou/*.cmt
@OCamlStdlibDir@/biniou/*.cmo
@OCamlStdlibDir@/biniou/*.cmti
@OCamlStdlibDir@/biniou/*.cmi
@OCamlStdlibDir@/biniou/*.ml*
OPT: @OCamlStdlibDir@/biniou/*.o
OPT: @OCamlStdlibDir@/biniou/*.cmxa
OPT: @OCamlStdlibDir@/biniou/*.a
OPT: @OCamlStdlibDir@/biniou/*.cmx
......
......@@ -9,39 +9,15 @@ DESTDIR=$(CURDIR)/debian/tmp
include /usr/share/ocaml/ocamlvars.mk
OCAMLFIND_DESTDIR=$(DESTDIR)/$(OCAML_STDLIB_DIR)
export OCAMLFIND_DESTDIR
OCAMLFIND_LDCONF=ignore
export OCAMLFIND_LDCONF
%:
dh $@ --with ocaml
.PHONY: override_dh_auto_build
override_dh_auto_build:
ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
$(MAKE)
else
$(MAKE) all bdump.byte
endif
$(MAKE) doc
jbuilder build -p biniou
.PHONY: override_dh_auto_install
override_dh_auto_install:
mkdir -p '$(OCAMLFIND_DESTDIR)'
mkdir -p '$(DESTDIR)/usr/bin'
make install 'BINDIR=$(DESTDIR)/usr/bin'
.PHONY: override_dh_install
override_dh_install:
dh_install --fail-missing
jbuilder install --destdir=$(DESTDIR) --prefix=/usr --libdir=..$(OCAML_STDLIB_DIR)
rm -f $(DESTDIR)/usr/doc/biniou/LICENSE
.PHONY: override_dh_installdocs
override_dh_installdocs:
mkdir api
mv doc api/html
dh_installdocs
override_dh_missing:
dh_missing --fail-missing
version=3
https://github.com/mjambon/biniou/tags .*/v([\d\.]+)\.tar\.gz
https://github.com/ocaml-community/biniou/tags .*/v([\d\.]+)\.tar\.gz
type t = {
mutable i_s : string;
mutable i_s : bytes;
mutable i_pos : int;
mutable i_len : int;
mutable i_offs : int;
......@@ -35,14 +35,14 @@ let read ib n =
let read_char ib =
let pos = ib.i_pos in
if ib.i_len - pos > 0 then (
let c = String.unsafe_get ib.i_s pos in
let c = Bytes.unsafe_get ib.i_s pos in
ib.i_pos <- pos + 1;
c
)
else
if try_preread ib 1 > 0 then
let pos = ib.i_pos in
let c = String.unsafe_get ib.i_s pos in
let c = Bytes.unsafe_get ib.i_s pos in
ib.i_pos <- pos + 1;
c
else
......@@ -51,24 +51,26 @@ let read_char ib =
let peek ib =
let pos = ib.i_pos in
if ib.i_len - pos > 0 then (
String.unsafe_get ib.i_s pos
Bytes.unsafe_get ib.i_s pos
)
else
if try_preread ib 1 > 0 then
String.unsafe_get ib.i_s ib.i_pos
Bytes.unsafe_get ib.i_s ib.i_pos
else
raise End_of_input
let from_string ?(pos = 0) ?(shrlen = 16) s = {
let from_bytes ?(pos = 0) ?(shrlen = 16) s = {
i_s = s;
i_pos = pos;
i_len = String.length s;
i_len = Bytes.length s;
i_offs = -pos;
i_max_len = String.length s;
i_max_len = Bytes.length s;
i_refill = (fun ib n -> ());
i_shared = Bi_share.Rd.create shrlen;
}
let from_string ?pos ?shrlen s = from_bytes ?pos ?shrlen (Bytes.of_string s)
(*
Like Pervasives.really_input but returns the number of bytes
read instead of raising End_of_file when the end of file is reached.
......@@ -87,7 +89,7 @@ let refill_from_channel ic ib n =
let rem_len = ib.i_len - ib.i_pos in
if rem_len < n then
let s = ib.i_s in
String.blit s ib.i_pos s 0 rem_len;
Bytes.blit s ib.i_pos s 0 rem_len;
let to_read = n - rem_len in
let really_read = not_really_input ic s rem_len to_read 0 in
ib.i_offs <- ib.i_offs + ib.i_pos;
......@@ -96,7 +98,7 @@ let refill_from_channel ic ib n =
)
let from_channel ?(len = 4096) ?(shrlen = 16) ic = {
i_s = String.create len;
i_s = Bytes.create len;
i_pos = 0;
i_len = 0;
i_offs = 0;
......
(** Input buffer *)
type t = {
mutable i_s : string;
mutable i_s : bytes;
(** This is the buffer string.
It can be accessed for reading but should normally only
be written to or replaced only by the [i_refill] function.
......@@ -99,6 +99,14 @@ val from_string : ?pos:int -> ?shrlen:int -> string -> t
@param shrlen initial length of the table used to store shared values.
*)
val from_bytes : ?pos:int -> ?shrlen:int -> bytes -> t
(**
Create an input buffer from bytes.
@param pos position to start from. Default: 0.
@param shrlen initial length of the table used to store shared values.
@since 1.2.0
*)
val from_channel : ?len:int -> ?shrlen:int -> in_channel -> t
(**
Create an input buffer from an in_channel.
......
......@@ -79,17 +79,23 @@ let hash_name s =
record fields.
*)
let mask_31bit =
let n = Bi_util.int_size - 31 in
assert (n >= 0);
fun x -> (x lsl n) lsr n
let write_hashtag ob h has_arg =
let h = h land 0x7fffffff in
let h = mask_31bit h in
let pos = Bi_outbuf.alloc ob 4 in
let s = ob.o_s in
String.unsafe_set s (pos+3) (Char.chr (h land 0xff));
Bytes.unsafe_set s (pos+3) (Char.chr (h land 0xff));
let h = h lsr 8 in
String.unsafe_set s (pos+2) (Char.chr (h land 0xff));
Bytes.unsafe_set s (pos+2) (Char.chr (h land 0xff));
let h = h lsr 8 in
String.unsafe_set s (pos+1) (Char.chr (h land 0xff));
Bytes.unsafe_set s (pos+1) (Char.chr (h land 0xff));
let h = h lsr 8 in
String.unsafe_set s pos (
Bytes.unsafe_set s pos (
Char.chr (
if has_arg then h lor 0x80
else h
......@@ -104,12 +110,12 @@ let string_of_hashtag h has_arg =
let read_hashtag ib cont =
let i = Bi_inbuf.read ib 4 in
let s = ib.i_s in
let x0 = Char.code s.[i] in
let x0 = Char.code (Bytes.get s i) in
let has_arg = x0 >= 0x80 in
let x1 = (x0 land 0x7f) lsl 24 in
let x2 = (Char.code s.[i+1]) lsl 16 in
let x3 = (Char.code s.[i+2]) lsl 8 in
let x4 = Char.code s.[i+3] in
let x2 = (Char.code (Bytes.get s (i+1))) lsl 16 in
let x3 = (Char.code (Bytes.get s (i+2))) lsl 8 in
let x4 = Char.code (Bytes.get s (i+3)) in
let h = make_signed (x1 lor x2 lor x3 lor x4) in
cont ib h has_arg
......@@ -118,13 +124,13 @@ let read_hashtag ib cont =
let read_field_hashtag ib =
let i = Bi_inbuf.read ib 4 in
let s = ib.i_s in
let x0 = Char.code (String.unsafe_get s i) in
let x0 = Char.code (Bytes.unsafe_get s i) in
if x0 < 0x80 then
Bi_util.error "Corrupted data (invalid field hashtag)";
let x1 = (x0 land 0x7f) lsl 24 in
let x2 = (Char.code (String.unsafe_get s (i+1))) lsl 16 in
let x3 = (Char.code (String.unsafe_get s (i+2))) lsl 8 in
let x4 = Char.code (String.unsafe_get s (i+3)) in
let x2 = (Char.code (Bytes.unsafe_get s (i+1))) lsl 16 in
let x3 = (Char.code (Bytes.unsafe_get s (i+2))) lsl 8 in
let x4 = Char.code (Bytes.unsafe_get s (i+3)) in
make_signed (x1 lor x2 lor x3 lor x4)
......@@ -141,7 +147,7 @@ let write_numtag ob i has_arg =
let read_numtag ib cont =
let i = Bi_inbuf.read ib 1 in
let x = Char.code ib.i_s.[i] in
let x = Char.code (Bytes.get ib.i_s i) in
let has_arg = x >= 0x80 in
cont ib (x land 0x7f) has_arg
......@@ -213,11 +219,11 @@ let read_untagged_float64 ib =
(match Lazy.force float_endianness with
`Little ->
for j = 0 to 7 do
String.unsafe_set (Obj.obj x) (7-j) (String.unsafe_get s (i+j))
Bytes.unsafe_set (Obj.obj x) (7-j) (Bytes.unsafe_get s (i+j))
done
| `Big ->
for j = 0 to 7 do
String.unsafe_set (Obj.obj x) j (String.unsafe_get s (i+j))
Bytes.unsafe_set (Obj.obj x) j (Bytes.unsafe_get s (i+j))
done
);
(Obj.obj x : float)
......@@ -228,11 +234,11 @@ let write_untagged_float64 ob x =
(match Lazy.force float_endianness with
`Little ->
for j = 0 to 7 do
String.unsafe_set s (i+j) (String.unsafe_get (Obj.magic x) (7-j))
Bytes.unsafe_set s (i+j) (String.unsafe_get (Obj.magic x) (7-j))
done
| `Big ->
for j = 0 to 7 do
String.unsafe_set s (i+j) (String.unsafe_get (Obj.magic x) j)
Bytes.unsafe_set s (i+j) (String.unsafe_get (Obj.magic x) j)
done
)
......@@ -520,16 +526,17 @@ let read_untagged_int8 ib =
let read_untagged_int16 ib =
let i = Bi_inbuf.read ib 2 in
let s = ib.i_s in
((Char.code s.[i]) lsl 8) lor (Char.code s.[i+1])
((Char.code (Bytes.get s i)) lsl 8) lor (Char.code (Bytes.get s (i+1)))
let read_untagged_int32 ib =
let i = Bi_inbuf.read ib 4 in
let s = ib.i_s in
let get_code s i = Char.code (Bytes.get s i) in
let x1 =
Int32.of_int (((Char.code s.[i ]) lsl 8) lor (Char.code s.[i+1])) in
Int32.of_int (((get_code s (i )) lsl 8) lor (get_code s (i+1))) in
let x2 =
Int32.of_int (((Char.code s.[i+2]) lsl 8) lor (Char.code s.[i+3])) in
Int32.of_int (((get_code s (i+2)) lsl 8) lor (get_code s (i+3))) in
Int32.logor (Int32.shift_left x1 16) x2
let read_untagged_float32 ib =
......@@ -559,7 +566,7 @@ let read_untagged_int64 ib =
let read_untagged_string ib =
let len = Bi_vint.read_uvint ib in
let str = String.create len in
let str = Bytes.create len in
let pos = ref 0 in
let rem = ref len in
while !rem > 0 do
......@@ -567,13 +574,13 @@ let read_untagged_string ib =
if bytes_read = 0 then
Bi_util.error "Corrupted data (string)"
else (
String.blit ib.i_s ib.i_pos str !pos bytes_read;
Bytes.blit ib.i_s ib.i_pos str !pos bytes_read;
ib.i_pos <- ib.i_pos + bytes_read;
pos := !pos + bytes_read;
rem := !rem - bytes_read
)
done;
str
Bytes.to_string str
let read_untagged_uvint = Bi_vint.read_uvint
let read_untagged_svint = Bi_vint.read_svint
......