Apply the before serialize hook.

def _hooks_apply_before_serialize(
        hooks,  # type: Optional[Hooks]
        state,  # type: _ProcessorState
        value  # type: Any
):
    # type: (...) -> Any
    """Apply the before serialize hook."""
    if hooks and hooks.before_serialize:
        return hooks.before_serialize(ProcessorStateView(state), value)

    return value