1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(*
* Copyright (c) 2012-2019 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2019 Romain Calascibetta <romain.calascibetta@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)include(Cstruct:moduletypeofCstructwithtypet:=Cstruct.t)type'ard=<rd:unit;..>as'atype'awr=<wr:unit;..>as'atype'at=Cstruct.ttyperdwr=<rd:unit;wr:unit;>typero=<rd:unit;>typewo=<wr:unit;>externalro:'ardt->rot="%identity"externalwo:'awrt->wot="%identity"letof_string?off?lenx=Cstruct.of_string?off?lenxletof_bytes?off?lenx=Cstruct.of_bytes?off?lenxletto_string?(off=0)?lent=letlen=matchlenwith|Somelen->len|None->Cstruct.lent-offinCstruct.copytofflenletto_bytes?(off=0)?lent=letlen=matchlenwith|Somelen->len|None->Cstruct.lent-offin(* XXX(dinosaure): this is safe when [copy] allocates itself [bytes]
and uses [Bytes.unsafe_to_string]. *)Bytes.unsafe_of_string(Cstruct.copytofflen)letppppft=Cstruct.hexdump_ppppftletlength=Cstruct.lenletblitsrc~src_offdst~dst_off~len=Cstruct.blitsrcsrc_offdstdst_offlen[@@inline]letblit_from_stringsrc~src_offdst~dst_off~len=Cstruct.blit_from_stringsrcsrc_offdstdst_offlen[@@inline]letblit_from_bytessrc~src_offdst~dst_off~len=Cstruct.blit_from_bytessrcsrc_offdstdst_offlen[@@inline]letblit_to_bytessrc~src_offdst~dst_off~len=Cstruct.blit_to_bytessrcsrc_offdstdst_offlen[@@inline]letsubt~off~len=Cstruct.subtofflen[@@inline]letconcatvss=letres=create_unsafe(Cstruct.sum_lengths~caller:"Cstruct.Cap.concat"vss)inletgooffv=letlen=Cstruct.lenvinCstruct.blitv0resofflen;off+leninletlen=List.fold_leftgo0vssinassert(len=Cstruct.lenres);res