123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990letinvalid_argfmt=Format.ksprintf(funs->invalid_args)fmtincludeBytesexternalget_unsafe_16:t->int->int="%caml_string_get16u"[@@noalloc]externalget_unsafe_32:t->int->int32="%caml_string_get32u"externalget_unsafe_64:t->int->int64="%caml_string_get64u"(* specialization: polymorphic compiler primitives can't be aliases as this
does not play well with inlining - if aliased without a type annotation, the
compiler would implement them using the generic code doing a C call, and
it's this code that would be inlined - as a result we have to copy the
declaration here. *)external(<):'a->'a->bool="%lessthan"external(>):'a->'a->bool="%greaterthan"let(>)(x:int)y=x>ylet(<)(x:int)y=x<yletget_16ti=ifi<0||i>lengtht-2theninvalid_arg"Bytes.get_16"elseget_unsafe_16tiletget_32ti=ifi<0||i>lengtht-4theninvalid_arg"Bytes.get_32"else(* allocation *)get_unsafe_32tiletget_64ti=ifi<0||i>lengtht-8theninvalid_arg"Bytes.get_64"else(* allocation *)get_unsafe_64tiexternalset_unsafe_16:t->int->int->unit="%caml_string_set16u"[@@noalloc]externalset_unsafe_32:t->int->int32->unit="%caml_string_set32u"[@@noalloc]externalset_unsafe_64:t->int->int64->unit="%caml_string_set64u"[@@noalloc]letset_16tiv=ifi<0||i>lengtht-2theninvalid_arg"Bytes.set_16"elseset_unsafe_16tivletset_32tiv=ifi<0||i>lengtht-4theninvalid_arg"Bytes.set_32"elseset_unsafe_32tivletset_64tiv=ifi<0||i>lengtht-8theninvalid_arg"Bytes.set_64"elseset_unsafe_64tivletunsafe_blitsrcsrc_offdstdst_offlen=fori=0tolen-1dounsafe_setdst(dst_off+i)(unsafe_getsrc(src_off+i))doneletblitsrcsrc_offdstdst_offlen=iflen<0||src_off<0||src_off>lengthsrc-len||dst_off<0||dst_off>lengthdst-lentheninvalid_arg"Bytes.blit (src: %d:%d, dst: %d:%d, len: %d)"src_off(lengthsrc)dst_off(lengthdst)lenelseunsafe_blitsrcsrc_offdstdst_offlenletblit2srcsrc_offdst0dst_off0dst1dst_off1len=iflen<0||src_off<0||src_off>lengthsrc-len||dst_off0<0||dst_off0>lengthdst0-len||dst_off1<0||dst_off1>lengthdst1-lentheninvalid_arg"Bytes.blit2 (src: %d:%d, dst0: %d:%d, dst1: %d:%d, len: %d)"src_off(lengthsrc)dst_off0(lengthdst0)dst_off1(lengthdst1)lenelsefori=0tolen-1dounsafe_setdst0(dst_off0+i)(unsafe_getsrc(src_off+i));unsafe_setdst1(dst_off1+i)(unsafe_getsrc(src_off+i))doneletppppfa=fori=0tolengtha-1doFormat.fprintfppf"%02X"(Char.code(unsafe_getai))done