Extract EventSource serialization into a library

Signed-off-by: chatgris <chatgri@gmail.com>