123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openBinary_error_typesletinvalid_int_encoding=letopenEncodinginobj3(req"min"int31)(req"v"int31)(req"max"int31)letinvalid_float_encoding=letopenEncodinginobj3(req"min"float)(req"v"float)(req"max"float)letread_error_encoding:read_errorEncoding.t=letopenEncodinginmatching(function|Not_enough_data->Matched(0,empty,())|Extra_bytes->Matched(1,empty,())|No_case_matched->Matched(2,empty,())|Unexpected_tagtag->Matched(3,int31,tag)|Invalid_int{min;v;max}->Matched(5,invalid_int_encoding,(min,v,max))|Invalid_float{min;v;max}->Matched(6,invalid_float_encoding,(min,v,max))|Trailing_zero->Matched(7,empty,())|Size_limit_exceeded->Matched(8,empty,())|List_too_long->Matched(9,empty,())|Array_too_long->Matched(10,empty,())|Exception_raised_in_user_functionmsg->Matched(11,string,msg)|User_invariant_guardmsg->Matched(12,string,msg))[case(Tag0)~title:"Not enough data"empty(functionNot_enough_data->Some()|_->None)(fun()->Not_enough_data);case(Tag1)~title:"Extra bytes"empty(functionExtra_bytes->Some()|_->None)(fun()->Extra_bytes);case(Tag2)~title:"No case matched"empty(function(No_case_matched:read_error)->Some()|_->None)(fun()->No_case_matched);case(Tag3)~title:"Unexpected tag"int31(functionUnexpected_tagi->Somei|_->None)(funi->Unexpected_tagi);case(Tag5)~title:"Invalid int"invalid_int_encoding(function|(Invalid_int{min;v;max}:read_error)->Some(min,v,max)|_->None)(fun(min,v,max)->Invalid_int{min;v;max});case(Tag6)~title:"Invalid float"invalid_float_encoding(function|(Invalid_float{min;v;max}:read_error)->Some(min,v,max)|_->None)(fun(min,v,max)->Invalid_float{min;v;max});case(Tag7)~title:"Trailing zero"empty(functionTrailing_zero->Some()|_->None)(fun()->Trailing_zero);case(Tag8)~title:"Size limit exceeded"empty(function(Size_limit_exceeded:read_error)->Some()|_->None)(fun()->Size_limit_exceeded);case(Tag9)~title:"List too long"empty(function(List_too_long:read_error)->Some()|_->None)(fun()->List_too_long);case(Tag10)~title:"Array too long"empty(function(Array_too_long:read_error)->Some()|_->None)(fun()->Array_too_long);case(Tag11)~title:"Exception raised in user function"string(function|(Exception_raised_in_user_functions:read_error)->Somes|_->None)(funs->Exception_raised_in_user_functions);case(Tag12)~title:"User invariant guard"string(functionUser_invariant_guards->Somes|_->None)(funs->User_invariant_guards);]letpp_read_errorppf=function|Not_enough_data->Format.fprintfppf"Not enough data"|Extra_bytes->Format.fprintfppf"Extra bytes"|No_case_matched->Format.fprintfppf"No case matched"|Unexpected_tagtag->Format.fprintfppf"Unexpected tag %d"tag|Invalid_int{min;v;max}->Format.fprintfppf"Invalid int (%d <= %d <= %d) "minvmax|Invalid_float{min;v;max}->Format.fprintfppf"Invalid float (%f <= %f <= %f) "minvmax|Trailing_zero->Format.fprintfppf"Trailing zero in Z"|Size_limit_exceeded->Format.fprintfppf"Size limit exceeded"|List_too_long->Format.fprintfppf"List length limit exceeded"|Array_too_long->Format.fprintfppf"Array length limit exceeded"|Exception_raised_in_user_functions->Format.fprintfppf"Exception raised in user function: %s"s|User_invariant_guards->Format.fprintfppf"User-specified invariant not respected in encoded data: %s"sletwrite_error_encoding=letopenEncodinginmatching(function|Size_limit_exceeded->Matched(0,empty,())|No_case_matched->Matched(1,empty,())|Invalid_int{min;v;max}->Matched(2,invalid_int_encoding,(min,v,max))|Invalid_float{min;v;max}->Matched(3,invalid_float_encoding,(min,v,max))|Invalid_bytes_length{expected;found}->Matched(4,obj2(req"expected"int31)(req"found"int31),(expected,found))|Invalid_string_length{expected;found}->Matched(5,obj2(req"expected"int31)(req"found"int31),(expected,found))|Invalid_natural->Matched(6,empty,())|List_invalid_length->Matched(7,empty,())|Array_invalid_length->Matched(8,empty,())|(Exception_raised_in_user_functions:write_error)->Matched(9,string,s))[case(Tag0)~title:"Size limit exceeded"empty(functionSize_limit_exceeded->Some()|_->None)(fun()->Size_limit_exceeded);case(Tag1)~title:"No case matched"empty(functionNo_case_matched->Some()|_->None)(fun()->No_case_matched);case(Tag2)~title:"Invalid int"(obj3(req"min"int31)(req"v"int31)(req"max"int31))(functionInvalid_int{min;v;max}->Some(min,v,max)|_->None)(fun(min,v,max)->Invalid_int{min;v;max});case(Tag3)~title:"Invalid float"(obj3(req"min"float)(req"v"float)(req"max"float))(function|Invalid_float{min;v;max}->Some(min,v,max)|_->None)(fun(min,v,max)->Invalid_float{min;v;max});case(Tag4)~title:"Invalid bytes length"(obj2(req"expected"int31)(req"found"int31))(function|Invalid_bytes_length{expected;found}->Some(expected,found)|_->None)(fun(expected,found)->Invalid_bytes_length{expected;found});case(Tag5)~title:"Invalid string length"(obj2(req"expected"int31)(req"found"int31))(function|Invalid_string_length{expected;found}->Some(expected,found)|_->None)(fun(expected,found)->Invalid_bytes_length{expected;found});case(Tag6)~title:"Invalid natural"empty(functionInvalid_natural->Some()|_->None)(fun()->Invalid_natural);case(Tag7)~title:"List too long or too short"empty(functionList_invalid_length->Some()|_->None)(fun()->List_invalid_length);case(Tag8)~title:"Array too long or too short"empty(functionArray_invalid_length->Some()|_->None)(fun()->Array_invalid_length);case(Tag9)~title:"Exception raised in user function"string(function|(Exception_raised_in_user_functions:write_error)->Somes|_->None)(funs->Exception_raised_in_user_functions);]letpp_write_errorppf=function|Size_limit_exceeded->Format.fprintfppf"Size limit exceeded"|No_case_matched->Format.fprintfppf"No case matched"|Invalid_int{min;v;max}->Format.fprintfppf"Invalid int (%d <= %d <= %d) "minvmax|Invalid_float{min;v;max}->Format.fprintfppf"Invalid float (%f <= %f <= %f) "minvmax|Invalid_bytes_length{expected;found}->Format.fprintfppf"Invalid bytes length (expected: %d ; found %d)"expectedfound|Invalid_string_length{expected;found}->Format.fprintfppf"Invalid string length (expected: %d ; found %d)"expectedfound|Invalid_natural->Format.fprintfppf"Negative natural"|List_invalid_length->Format.fprintfppf"List is too long or too short"|Array_invalid_length->Format.fprintfppf"Array is too long or too short"|Exception_raised_in_user_functions->Format.fprintfppf"Exception raised in user function: %s"s