1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(*
* Copyright (c) 2018-2022 Tarides <contact@tarides.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.
*)(* For every new version, update the [version] type and [versions]
headers. *)typet=[`V1|`V2|`V3|`V4|`V5][@@derivingirmin]letlatest=`V5letenum=[(`V1,"00000001");(`V2,"00000002");(`V3,"00000003");(`V4,"00000004");(`V5,"00000005");]letpp=Fmt.of_to_string(function|`V1->"v1"|`V2->"v2"|`V3->"v3"|`V4->"v4"|`V5->"v5")letto_binv=List.assocvenumletto_int=function`V1->1|`V2->2|`V3->3|`V4->4|`V5->5letcompareab=Int.compare(to_inta)(to_intb)letencode_bintf=to_bint|>fletdecode_binsoffref=letsub=String.subs!offref(!offref+8)inletres=matchsubwith|"00000001"->`V1|"00000002"->`V2|"00000003"->`V3|"00000004"->`V4|"00000005"->`V5|_->failwith"Couldn't decode pack version"inoffref:=!offref+8;resletsize_of=Irmin.Type.Size.custom_static8letbin=(encode_bin,decode_bin,size_of)lett=Irmin.Type.like~bin~unboxed_bin:bin~compare~pptletinvalid_argv=letpp_full_versionppfv=Fmt.pfppf"%a (%S)"ppv(to_binv)inFmt.invalid_arg"invalid version: got %S, expecting %a"vFmt.(Dump.listpp_full_version)(List.mapfstenum)letof_binb=trySome(decode_binb(ref0))withFailure_->NoneexceptionInvalidof{expected:t;found:t}let()=Printexc.register_printer(function|Invalid{expected;found}->Some(Fmt.str"%s.Invalid { expected = %a; found = %a }"__MODULE__ppexpectedppfound)|_->None)