Add utility function for cpp objects serialization

Change-Id: Idcfd3ae491c9bfa942d8e1b41b2d3af172b81652