Instance Fin_Serializer n : Serializer (Fin.t n).
(* Serializer for StructTact's fin based on converting to nat. *)
Definition fin_serialize {n} (x : fin n) : IOStreamWriter.t :=
serialize (fin_to_nat x).
Definition fin_deserialize {n} : ByteListReader.t (fin n) :=
m <- deserialize ;;
match fin_of_nat m n with
| inleft x => ByteListReader.ret x
| inright _ => ByteListReader.error
end.

(* Specifications: *)
Lemma fin_serialize_deserialize_id n :
serialize_deserialize_id_spec fin_serialize (@fin_deserialize n).