parseDataSeeds static method

List<Seed> parseDataSeeds(
  1. List<int>? response
)

Parses Seeds from the response string obtained from the NodeRequest.getNodeList.

This method takes a response, represented as a list of integers, and parses it into a list of Seeds. The response string is expected to contain seed information separated by spaces. Each seed is assumed to be in the format "ip;port:address". The method handles errors gracefully and returns an empty list if the response is null or empty, or if parsing encounters any issues.

Example:

List<int> response = [105, 112, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58, 56, 48, 56, 48, 32, ...];
List<Seed> parsedSeeds = parseSeeds(response);
print(parsedSeeds.length);  // Output: Number of parsed seeds

Parameters:

  • response A list of integers representing the response string.

Returns: A list of Seed instances parsed from the response string.

Implementation

static List<Seed> parseDataSeeds(List<int>? response) {
  if (response == null || response.isEmpty) {
    return [];
  }
  List<String> seeds = String.fromCharCodes(response).split(" ");
  List<Seed> seedsList = [];

  try {
    for (String value in seeds) {
      if (value != seeds[0]) {
        var seed = value.split(":");
        var ipAndPort = seed[0].split(";");

        seedsList.add(Seed(
          ip: ipAndPort[0],
          port: int.parse(ipAndPort[1]),
          address: seed[1],
        ));
      }
    }
    return seedsList;
  } catch (e) {
    return [];
  }
}