I am aware of the implodePadded and explodePadded functions. However, CRM_Event_BAO_Participant does not conform to the format they use of having a delimiter at the start and end of the string. If you look in the following functions, you'll see they use a simple explode rather than explodePadded:
* CRM_Event_BAO_Participant::create
* CRM_Event_Form_Participant::setDefaultValues
* CRM_Event_Form_ParticipantView::preProcess
* CRM_Event_Selector_Search::getRows

I tested and found that if the role_id string is supplied with delimiters at the start and end (as returned by implodePadded), then when you view the participant record on the contact's event tab or on the view participant page, the list of role names starts and ends with a comma because the outer delimiters have not been trimmed. There may be other errors caused by having a delimiter at the start and end of the string.

My fix in this pull request works with the Participant code as it is. If you want to use implodePadded for the role_id field, then the above functions (and possibly others) would need to be changed to use explodePadded instead of explode.