val value_lserializer: LL.serializer32 value_serializer
val value_lserializer: LL.serializer32 value_serializer
let value_lserializer =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  LL.serialize32_sum value_sum value_kind_repr_serializer lserialize_value_kind_key serialize_value_cases lserialize_value_cases (_ by (LP.dep_enum_destr_tac ()))
module Zeta.Formats.Aux.Value

(* This file has been automatically generated by EverParse. *)
open FStar.Bytes
module U8 = FStar.UInt8
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module LP = LowParse.Spec
module LT = LowParse.TacLib
module LSZ = LowParse.SLow
module LPI = LowParse.Spec.AllIntegers
module LL = LowParse.Low
module L = FStar.List.Tot
module B = LowStar.Buffer
module BY = FStar.Bytes
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST

#reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection' --z3rlimit 16 --z3cliopt smt.arith.nl=false --max_fuel 2 --max_ifuel 2"

friend Zeta.Formats.Aux.Value_kind

// Need high Z3 limits for large sum types
#set-options "--z3rlimit 180"

inline_for_extraction unfold let value_kind_as_enum_key (x:value_kind) : Pure (LP.enum_key value_kind_enum)
  (requires norm [delta; zeta; iota; primops] (LP.list_mem x (LP.list_map fst value_kind_enum)) == true) (ensures fun _ -> True) =
  [@inline_let] let _ = norm_spec [delta; zeta; iota; primops] (LP.list_mem x (LP.list_map fst value_kind_enum)) in x

inline_for_extraction let key_of_value (x:value) : LP.enum_key value_kind_enum =
  match x with
  | Value_payload_MV _ -> value_kind_as_enum_key MV
  | Value_payload_DVNone _ -> value_kind_as_enum_key DVNone
  | Value_payload_DVSome _ -> value_kind_as_enum_key DVSome

inline_for_extraction let value_case_of_value_kind (x:value_kind) : Type0 =
  match x with
  | MV -> mval_value
  | DVNone -> unit
  | DVSome -> application_value

unfold inline_for_extraction let to_value_case_of_value_kind (x:value_kind) (#x':value_kind) (y:value_case_of_value_kind x')  : Pure (norm [delta_only [(`%value_case_of_value_kind)]; iota] (value_case_of_value_kind x))
  (requires (x == x')) (ensures (fun y' -> y' == y)) =
  [@inline_let] let _ = norm_spec [delta_only [(`%value_case_of_value_kind)] ; iota] (value_case_of_value_kind x) in y

unfold inline_for_extraction let value_refine (k:LP.enum_key value_kind_enum) (x:value)
  : Pure (LP.refine_with_tag key_of_value k)  (requires norm [delta; iota; zeta] (key_of_value x) == k) (ensures (fun y -> y == x)) =
  [@inline_let] let _ = norm_spec [delta; iota; zeta] (key_of_value x) in x

inline_for_extraction let synth_value_cases (x:LP.enum_key value_kind_enum) (y:value_case_of_value_kind x)
  : LP.refine_with_tag key_of_value x =
  match x with
  | MV -> value_refine x (Value_payload_MV (to_value_case_of_value_kind MV y))
  | DVNone -> value_refine x (Value_payload_DVNone (to_value_case_of_value_kind DVNone y))
  | DVSome -> value_refine x (Value_payload_DVSome (to_value_case_of_value_kind DVSome y))

unfold inline_for_extraction let from_value_case_of_value_kind (#x':value_kind) (x:value_kind)
  (y: norm [delta_only [(`%value_case_of_value_kind)]; iota] (value_case_of_value_kind x))
  : Pure (value_case_of_value_kind x') (requires (x == x')) (ensures (fun y' -> y' == y)) =
  [@inline_let] let _ = norm_spec [delta_only [(`%value_case_of_value_kind)] ; iota] (value_case_of_value_kind x) in y

let synth_value_cases_recip_pre (k:LP.enum_key value_kind_enum)
  (x:LP.refine_with_tag key_of_value k) : GTot bool =
  match k with
  | MV -> Value_payload_MV? x
  | DVNone -> Value_payload_DVNone? x
  | DVSome -> Value_payload_DVSome? x

let synth_value_cases_recip_pre_intro (k:LP.enum_key value_kind_enum) (x:LP.refine_with_tag key_of_value k)
  : Lemma (synth_value_cases_recip_pre k x == true) =
  norm_spec [delta; iota] (synth_value_cases_recip_pre k x)

inline_for_extraction let synth_value_cases_recip (k:LP.enum_key value_kind_enum)
  (x:LP.refine_with_tag key_of_value k) : (value_case_of_value_kind k) =
  match k with
  | MV -> [@inline_let] let _ = synth_value_cases_recip_pre_intro MV x in
    (match x with Value_payload_MV y -> (from_value_case_of_value_kind MV y))
  | DVNone -> [@inline_let] let _ = synth_value_cases_recip_pre_intro DVNone x in
    (match x with Value_payload_DVNone y -> (from_value_case_of_value_kind DVNone y))
  | DVSome -> [@inline_let] let _ = synth_value_cases_recip_pre_intro DVSome x in
    (match x with Value_payload_DVSome y -> (from_value_case_of_value_kind DVSome y))

inline_for_extraction let value_sum = LP.make_sum' value_kind_enum key_of_value
  value_case_of_value_kind synth_value_cases synth_value_cases_recip
  (_ by (LP.make_sum_synth_case_recip_synth_case_tac ()))
  (_ by (LP.synth_case_synth_case_recip_tac ()))

noextract let parse_value_cases (x:LP.sum_key value_sum)
  : k:LP.parser_kind & LP.parser k (value_case_of_value_kind x) =
  match x with
  | MV -> [@inline_let] let u : (k: LP.parser_kind & LP.parser k (value_case_of_value_kind MV)) = (| _, mval_value_parser |) in u
  | DVNone -> [@inline_let] let u : (k: LP.parser_kind & LP.parser k (value_case_of_value_kind DVNone)) = (| _, LP.parse_empty |) in u
  | DVSome -> [@inline_let] let u : (k: LP.parser_kind & LP.parser k (value_case_of_value_kind DVSome)) = (| _, application_value_parser |) in u
  | _ -> (| _, LP.parse_false |)

noextract let serialize_value_cases (x:LP.sum_key value_sum)
  : LP.serializer (dsnd (parse_value_cases x)) =
  match x with
  | MV -> [@inline_let] let u : LP.serializer (dsnd (parse_value_cases MV)) = mval_value_serializer in u
  | DVNone -> [@inline_let] let u : LP.serializer (dsnd (parse_value_cases DVNone)) = LP.serialize_empty in u
  | DVSome -> [@inline_let] let u : LP.serializer (dsnd (parse_value_cases DVSome)) = application_value_serializer in u
  | _ -> LP.serialize_false

inline_for_extraction noextract let size32_value_cases (x:LP.sum_key value_sum)
  : LSZ.size32 (serialize_value_cases x) =
  match x with
  | MV -> [@inline_let] let u : LSZ.size32 (serialize_value_cases MV) = mval_value_size32 in u
  | DVNone -> [@inline_let] let u : LSZ.size32 (serialize_value_cases DVNone) = LSZ.size32_empty in u
  | DVSome -> [@inline_let] let u : LSZ.size32 (serialize_value_cases DVSome) = application_value_size32 in u
  | _ -> LSZ.size32_false

inline_for_extraction noextract let validate_value_cases (x:LP.sum_key value_sum)
  : LL.validator (dsnd (parse_value_cases x)) =
  match x with
  | MV -> [@inline_let] let u : LL.validator (dsnd (parse_value_cases MV)) = mval_value_validator in u
  | DVNone -> [@inline_let] let u : LL.validator (dsnd (parse_value_cases DVNone)) = (LL.validate_empty ()) in u
  | DVSome -> [@inline_let] let u : LL.validator (dsnd (parse_value_cases DVSome)) = application_value_validator in u
  | _ -> LL.validate_false ()

inline_for_extraction noextract let jump_value_cases (x:LP.sum_key value_sum)
  : LL.jumper (dsnd (parse_value_cases x)) =
  match x with
  | MV -> [@inline_let] let u : LL.jumper (dsnd (parse_value_cases MV)) = mval_value_jumper in u
  | DVNone -> [@inline_let] let u : LL.jumper (dsnd (parse_value_cases DVNone)) = LL.jump_empty in u
  | DVSome -> [@inline_let] let u : LL.jumper (dsnd (parse_value_cases DVSome)) = application_value_jumper in u
  | _ -> LL.jump_false

inline_for_extraction noextract let read_value_cases (x:LP.sum_key value_sum)
  : LL.leaf_reader (dsnd (parse_value_cases x)) =
  match x with
  | MV -> [@inline_let] let u : LL.leaf_reader (dsnd (parse_value_cases MV)) = mval_value_reader in u
  | DVNone -> [@inline_let] let u : LL.leaf_reader (dsnd (parse_value_cases DVNone)) = LL.read_empty in u
  | DVSome -> [@inline_let] let u : LL.leaf_reader (dsnd (parse_value_cases DVSome)) = application_value_reader in u
  | _ -> LL.read_false

inline_for_extraction noextract let lserialize_value_cases (x:LP.sum_key value_sum)
  : LL.serializer32 (serialize_value_cases x) =
  match x with
  | MV -> [@inline_let] let u : LL.serializer32 (serialize_value_cases MV) = mval_value_lserializer in u
  | DVNone -> [@inline_let] let u : LL.serializer32 (serialize_value_cases DVNone) = LL.serialize32_empty in u
  | DVSome -> [@inline_let] let u : LL.serializer32 (serialize_value_cases DVSome) = application_value_lserializer in u
  | _ -> LL.serialize32_false

let value_parser =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  LP.parse_sum value_sum value_kind_repr_parser parse_value_cases

let value_serializer =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  LP.serialize_sum value_sum value_kind_repr_serializer serialize_value_cases

let value_bytesize (x:value) : GTot nat = Seq.length (value_serializer x)

let value_bytesize_eq x = ()

let value_size32 =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  assert_norm (LSZ.size32_sum_gen_precond (LP.get_parser_kind value_kind_repr_parser) (LP.weaken_parse_cases_kind value_sum parse_value_cases));
  LSZ.size32_sum2 value_sum value_kind_repr_serializer value_kind_repr_size32 serialize_value_cases size32_value_cases (_ by (LP.dep_enum_destr_tac ())) (_ by (LP.enum_repr_of_key_tac value_kind_enum)) ()

let value_validator =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  LL.validate_sum value_sum value_kind_repr_validator value_kind_repr_reader parse_value_cases validate_value_cases (_ by (LP.dep_maybe_enum_destr_t_tac ()))

let value_jumper =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  LL.jump_sum value_sum value_kind_repr_jumper value_kind_repr_reader parse_value_cases jump_value_cases (_ by (LP.dep_maybe_enum_destr_t_tac ()))

let value_reader =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser) value_sum parse_value_cases == value_parser_kind);
  LL.read_sum value_sum value_kind_repr_parser read_value_kind_key value_kind_repr_jumper parse_value_cases read_value_cases (_ by (LP.dep_enum_destr_tac ()))
/
Zeta.Formats.Aux.Value_kind.fst.checked prims.fst.checked LowStar.Buffer.fst.checked LowParse.TacLib.fst.checked LowParse.Spec.AllIntegers.fst.checked LowParse.Spec.fst.checked LowParse.SLow.fst.checked LowParse.Low.fst.checked FStar.UInt8.fsti.checked FStar.UInt64.fsti.checked FStar.UInt32.fsti.checked FStar.UInt16.fsti.checked FStar.Tactics.Effect.fsti.checked FStar.Seq.fst.checked FStar.Pervasives.fsti.checked FStar.List.Tot.fst.checked FStar.HyperStack.ST.fsti.checked FStar.HyperStack.fst.checked FStar.Bytes.fsti.checked
Zeta.Formats.Aux.Value.fst
LowParse.Low.Base.serializer32 Zeta.Formats.Aux.Value.value_serializer
LowParse.Low.Sum.serialize32_sum LowParse.Spec.Int.parse_u8_kind Zeta.Formats.Aux.Value.value_sum LowParse.Spec.Int.parse_u8 Zeta.Formats.Aux.Value_kind.value_kind_repr_serializer Zeta.Formats.Aux.Value_kind.lserialize_value_kind_key Zeta.Formats.Aux.Value.parse_value_cases Zeta.Formats.Aux.Value.serialize_value_cases Zeta.Formats.Aux.Value.lserialize_value_cases LowParse.Spec.Enum.dep_enum_destr_cons LowParse.Spec.Sum.sum_key_type LowParse.Spec.Sum.sum_repr_type LowParse.Spec.Sum.sum_enum LowParse.Low.Sum.serialize32_sum_cases_t LowParse.Spec.Enum.enum_tail LowParse.Spec.Enum.enum_key LowParse.Spec.Enum.dep_enum_destr_cons_nil Prims.unit FStar.Pervasives.assert_norm Prims.eq2 LowParse.Spec.Base.parser_kind LowParse.Spec.Sum.parse_sum_kind LowParse.Spec.Base.get_parser_kind FStar.UInt8.t Zeta.Formats.Aux.Value_kind.value_kind_repr_parser Zeta.Formats.Aux.Value.value_parser_kind
let value_lserializer =
  
assert_norm (LP.parse_sum_kind (LP.get_parser_kind value_kind_repr_parser)
      value_sum
      parse_value_cases ==
    value_parser_kind);
LL.serialize32_sum value_sum
  value_kind_repr_serializer
  lserialize_value_kind_key
  serialize_value_cases
  lserialize_value_cases
  (FStar.Tactics.Effect.synth_by_tactic (fun _ -> (LP.dep_enum_destr_tac ())))