Instance nat_Serializer : Serializer nat :=
{| serialize := nat_serialize;
deserialize := nat_deserialize;
serialize_deserialize_id := nat_serialize_deserialize_id
|}.
(* Serializer for the standard library's Fin.t based on converting to nat. *)
Definition Fin_serialize {n} (x : Fin.t n) : IOStreamWriter.t :=
serialize (proj1_sig (Fin.to_nat x)).
Definition Fin_deserialize {n} : ByteListReader.t (Fin.t n) :=
m <- deserialize ;;
match Fin.of_nat m n with
| inleft x => ByteListReader.ret x
| inright _ => ByteListReader.error
end.

Lemma Fin_serialize_deserialize_id n :
serialize_deserialize_id_spec Fin_serialize (@Fin_deserialize n).