extractServiceMethods function

List<Map<String, Object?>> extractServiceMethods(
  1. Map<String, Object?> serviceDescriptor
)

Extract service method descriptors from a FileDescriptorProto-like map.

serviceDescriptor should have a methods key containing a list of maps, each with name, inputType, outputType, and optionally clientStreaming and serverStreaming boolean flags.

Returns a list of maps, each with:

  • name (String): the method name.
  • inputType (String): the fully-qualified input message type.
  • outputType (String): the fully-qualified output message type.
  • clientStreaming (bool): whether the client streams requests.
  • serverStreaming (bool): whether the server streams responses.

Implementation

List<Map<String, Object?>> extractServiceMethods(
  Map<String, Object?> serviceDescriptor,
) {
  var methods = serviceDescriptor['methods'];
  if (methods == null || methods is! List) {
    return [];
  }
  var result = <Map<String, Object?>>[];
  for (var method in methods) {
    if (method is! Map<String, Object?>) continue;
    result.add({
      'name': method['name'] ?? '',
      'inputType': method['inputType'] ?? '',
      'outputType': method['outputType'] ?? '',
      'clientStreaming': method['clientStreaming'] == true,
      'serverStreaming': method['serverStreaming'] == true,
    });
  }
  return result;
}