@ Override public final EventData convert ( final CommonEvent commonEvent ) { // User's data final String dataType = commonEvent . getDataType ( ) . asBaseType ( ) ; final SerializedDataType serUserDataType = new SerializedDataType ( dataType ) ; final Serializer userDataSerializer = serRegistry . getSerializer ( serUserDataType ) ; final byte [ ] serUserData = userDataSerializer . marshal ( commonEvent . getData ( ) , serUserDataType ) ; final byte [ ] serData ; if ( userDataSerializer . getMimeType ( ) . matchEncoding ( targetContentType ) ) { serData = serUserData ; } else { final Base64Data base64data = new Base64Data ( serUserData ) ; final Serializer base64Serializer = serRegistry . getSerializer ( Base64Data . SER_TYPE ) ; serData = base64Serializer . marshal ( base64data , Base64Data . SER_TYPE ) ; } // EscMeta final EscMeta escMeta = EscSpiUtils . createEscMeta ( serRegistry , targetContentType , commonEvent ) ; final SerializedDataType escMetaType = new SerializedDataType ( EscMeta . TYPE . asBaseType ( ) ) ; final Serializer escMetaSerializer = getSerializer ( escMetaType ) ; final byte [ ] escSerMeta = escMetaSerializer . marshal ( escMeta , escMetaType ) ; // Create event data final EventData . Builder builder = EventData . newBuilder ( ) . eventId ( commonEvent . getId ( ) . asBaseType ( ) ) . type ( dataType ) ; if ( targetContentType . isJson ( ) ) { builder . jsonData ( serData ) ; builder . jsonMetadata ( escSerMeta ) ; } else { builder . data ( serData ) ; builder . metadata ( escSerMeta ) ; } return builder . build ( ) ; }
Converts a common event into event data .