Fix encode to match type and decode method
Fix warnings by explicitly casting enum types