Require Fin Ascii.
Hint Rewrite byte_unwrap : cheerios.
Definition bool_serialize (b : bool) : IOStreamWriter.t :=
if b then serialize x01 else serialize x00.
Definition bool_deserialize :=
b <- deserialize ;;
match b with
| x00 => ByteListReader.ret false
| x01 => ByteListReader.ret true
| _ => ByteListReader.error
end.
Instance bool_Serializer : Serializer bool.

Lemma fold_append_unwrap' :
forall {S A : Type}
(f : byte -> S -> fold_state S A) (s : S)
(b : byte) (tail : IOStreamWriter.t) (bin : list byte),
ByteListReader.unwrap (ByteListReader.fold f s)
(IOStreamWriter.unwrap (IOStreamWriter.append
(fun _ => IOStreamWriter.putByte b)
(fun _ => tail)) ++ bin) =
match f b s with
| Done a => Some(a, IOStreamWriter.unwrap tail ++ bin)
| More s => ByteListReader.unwrap (ByteListReader.fold f s)
(IOStreamWriter.unwrap tail ++ bin)
| Error => None
end.