@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1712")
  public static <T> ServerServiceDefinition useMarshalledMessages(
      final ServerServiceDefinition serviceDef,
      final MethodDescriptor.Marshaller<T> marshaller) {
    List<ServerMethodDefinition<?, ?>> wrappedMethods =
        new ArrayList<>();
    List<MethodDescriptor<?, ?>> wrappedDescriptors =
        new ArrayList<>();
    // Wrap the descriptors
    for (final ServerMethodDefinition<?, ?> definition : serviceDef.getMethods()) {
      final MethodDescriptor<?, ?> originalMethodDescriptor = definition.getMethodDescriptor();
      final MethodDescriptor<T, T> wrappedMethodDescriptor =
          originalMethodDescriptor.toBuilder(marshaller, marshaller).build();
      wrappedDescriptors.add(wrappedMethodDescriptor);
      wrappedMethods.add(wrapMethod(definition, wrappedMethodDescriptor));
    }
    // Build the new service descriptor
    final ServerServiceDefinition.Builder serviceBuilder = ServerServiceDefinition
        .builder(new ServiceDescriptor(serviceDef.getServiceDescriptor().getName(),
            wrappedDescriptors));
    // Create the new service definiton.
    for (ServerMethodDefinition<?, ?> definition : wrappedMethods) {
      serviceBuilder.addMethod(definition);
    }
    return serviceBuilder.build();
  }
@ ExperimentalApi ( "https://github.com/grpc/grpc-java/issues/1712" ) public static < T > ServerServiceDefinition useMarshalledMessages ( final ServerServiceDefinition serviceDef , final MethodDescriptor . Marshaller < T > marshaller ) { List < ServerMethodDefinition < ? , ? > > wrappedMethods = new ArrayList < > ( ) ; List < MethodDescriptor < ? , ? > > wrappedDescriptors = new ArrayList < > ( ) ; for ( final ServerMethodDefinition < ? , ? > definition : serviceDef . getMethods ( ) ) { final MethodDescriptor < ? , ? > originalMethodDescriptor = definition . getMethodDescriptor ( ) ; final MethodDescriptor < T , T > wrappedMethodDescriptor = originalMethodDescriptor . toBuilder ( marshaller , marshaller ) . build ( ) ; wrappedDescriptors . add ( wrappedMethodDescriptor ) ; wrappedMethods . add ( wrapMethod ( definition , wrappedMethodDescriptor ) ) ; } final ServerServiceDefinition . Builder serviceBuilder = ServerServiceDefinition . builder ( new ServiceDescriptor ( serviceDef . getServiceDescriptor ( ) . getName ( ) , wrappedDescriptors ) ) ; for ( ServerMethodDefinition < ? , ? > definition : wrappedMethods ) { serviceBuilder . addMethod ( definition ) ; } return serviceBuilder . build ( ) ; }
Create a new {@code ServerServiceDefinition} whose {@link MethodDescriptor} serializes to
and from T for all methods.  The {@code ServerCallHandler} created will automatically
convert back to the original types for request and response before calling the existing
{@code ServerCallHandler}.  Calling this method combined with the intercept methods will
allow the developer to choose whether to intercept messages of T, or the modeled types
of their application.  This can also be chained to allow for interceptors to handle messages
as multiple different T types within the chain if the added cost of serialization is not
a concern.

@param serviceDef the service definition to convert messages to T
@return a wrapped version of {@code serviceDef} with the T conversion applied.