Proof using.
intros.
unfold deserialize_tree_shape.
now rewrite shape_aux.
Qed.
Fixpoint serialize_tree_elements (t : tree A) : IOStreamWriter.t :=
let fix serialize_tree_elements_list (l : list (tree A)) : IOStreamWriter.t :=
match l with
| [] => IOStreamWriter.empty
| t :: l' => IOStreamWriter.append (fun _ => serialize_tree_elements t)
(fun _ => serialize_tree_elements_list l')
end
in match t with
| atom a => serialize a
| node l => serialize_tree_elements_list l
end.
Definition serialize_tree_elements_list :=
fix serialize_tree_elements_list (l : list (tree A)) : IOStreamWriter.t :=
match l with
| [] => IOStreamWriter.empty
| t :: l' => IOStreamWriter.append (fun _ => serialize_tree_elements t)
(fun _ => serialize_tree_elements_list l')
end.
Fixpoint deserialize_tree_elements (t : tree unit) : ByteListReader.t (tree A) :=
let fix deserialize_tree_elements_list (l : list (tree unit)) :=
match l with
| [] => ByteListReader.ret []
| t :: l' => cons <$> deserialize_tree_elements t
<*> deserialize_tree_elements_list l'
end
in match t with
| atom tt => @atom _ <$> deserialize
| node l => @node _ <$> deserialize_tree_elements_list l
end.
Definition deserialize_tree_elements_list :=
fix deserialize_tree_elements_list (l : list (tree unit)) :=
match l with
| [] => ByteListReader.ret []
| t :: l' => cons <$> deserialize_tree_elements t
<*> deserialize_tree_elements_list l'
end.

(* Specifications: *)
Lemma serialize_deserialize_tree_elements_id :
forall t bytes,
ByteListReader.unwrap (deserialize_tree_elements (shape t))
(IOStreamWriter.unwrap (serialize_tree_elements t) ++ bytes) =
Some (t, bytes).