val parse_u16_spec
  (b: bytes)
: Lemma
  (requires (Seq.length b >= 2))
  (ensures (
    let pp = parse parse_u16 b in
    Some? pp /\ (
    let (Some (v, consumed)) = pp in
    U16.v v == E.be_to_n (Seq.slice b 0 2)
  )))
let parse_u16_spec
  b
=
  E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
val parse_u16_spec
  (b: bytes)
: Lemma
  (requires (Seq.length b >= 2))
  (ensures (
    let pp = parse parse_u16 b in
    Some? pp /\ (
    let (Some (v, consumed)) = pp in
    U16.v v == E.be_to_n (Seq.slice b 0 2)
  )))
let parse_u16_spec b =
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
LowParse.Spec.Int.fst.checked
prims.fst.checked LowParse.Spec.Seq.fst.checked LowParse.Spec.Combinators.fsti.checked FStar.Pervasives.fsti.checked FStar.Classical.fsti.checked
LowParse.Spec.Int.fst
LowParse.Bytes.bytes FStar.Endianness.lemma_be_to_n_is_bounded FStar.Seq.Base.slice LowParse.Bytes.byte Prims.unit
module LowParse.Spec.Int
open LowParse.Spec.Combinators

let decode_u8
  (b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0

let decode_u8_injective () : Lemma
  (make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()

let tot_parse_u8 =
  decode_u8_injective ();
  tot_make_total_constant_size_parser 1 U8.t decode_u8

let parse_u8_spec
  b
=
  Seq.lemma_index_slice b 0 1 0;
  E.reveal_be_to_n (Seq.slice b 0 1);
  E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)

let parse_u8_spec' b = ()

let serialize_u8 =
  Seq.create 1

let serialize_u8_spec x = ()

let decode_u16
  (b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
  U16.uint_to_t (E.be_to_n b)

let decode_u16_injective'
  (b1: bytes { Seq.length b1 == 2 } )
  (b2: bytes { Seq.length b2 == 2 } )
: Lemma
  (decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
  then begin
    E.lemma_be_to_n_is_bounded b1;
    E.lemma_be_to_n_is_bounded b2;
    assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
    assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
    assert (E.be_to_n b1 == E.be_to_n b2);
    E.be_to_n_inj b1 b2
  end else ()

let decode_u16_injective
  ()
: Lemma
  (make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'

let parse_u16 =
  decode_u16_injective ();
  make_total_constant_size_parser 2 U16.t decode_u16

let parse_u16_spec
  b
val parse_u16_spec
  (b: bytes)
: Lemma
  (requires (Seq.length b >= 2))
  (ensures (
    let pp = parse parse_u16 b in
    Some? pp /\ (
    let (Some (v, consumed)) = pp in
    U16.v v == E.be_to_n (Seq.slice b 0 2)
  )))
b: LowParse.Bytes.bytes
  -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b >= 2)
      (ensures
        (let pp = LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u16 b in
          Some? pp /\
          (let _ = pp in
            (let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v _) = _ in
              FStar.UInt16.v v == FStar.Endianness.be_to_n (FStar.Seq.Base.slice b 0 2))
            <:
            Prims.logical)))