Proof using.
unfold sum_serialize, sum_deserialize.
destruct a; cheerios_crush.
Qed.
Global Instance sum_Serializer : Serializer (A + B).
Fixpoint list_serialize_rec (l : list A) : IOStreamWriter.t :=
match l with
| [] => IOStreamWriter.empty
| a :: l' => IOStreamWriter.append (fun _ => serialize a)
(fun _ => list_serialize_rec l')
end.
Definition list_serialize (l : list A) : IOStreamWriter.t :=
IOStreamWriter.append (fun _ => serialize (length l))
(fun _ => list_serialize_rec l).
Fixpoint list_deserialize_rec (n : nat) : ByteListReader.t (list A) :=
match n with
| 0 => ByteListReader.ret []
| S n' => cons <$> deserialize <*> list_deserialize_rec n'
end.
Definition list_deserialize : ByteListReader.t (list A) :=
deserialize >>= list_deserialize_rec.

Lemma list_serialize_deserialize_id_rec :
forall l bin, ByteListReader.unwrap (list_deserialize_rec (length l))
(IOStreamWriter.unwrap (list_serialize_rec l) ++ bin)
= Some(l, bin).