macula_rpc_service_interests (macula v0.20.5)

View Source

RPC Service Interests Module (Pull-based Discovery)

Handles pull-based service discovery configuration: - Normalizes service interest lists (atoms, binaries, strings) - Validates service interest inputs - Prepares DHT lookup messages for prefetching

Extracted from macula_rpc_handler.erl (Dec 2025) to improve testability and separation of concerns.

Summary

Functions

Create a FIND_VALUE message for a service. Returns the service key and encoded message ready to send.

Log configured service interests during init.

Merge new interests with existing ones (removes duplicates).

Normalize service interests to list of binaries. Accepts various input formats: list of binaries/atoms/strings, or single value.

Normalize a single service interest to binary. Returns {true, Binary} for valid inputs, false for invalid.

Functions

create_find_value_message(ServiceName)

-spec create_find_value_message(binary()) -> {binary(), map()}.

Create a FIND_VALUE message for a service. Returns the service key and encoded message ready to send.

log_interests(Interests)

-spec log_interests([binary()]) -> ok.

Log configured service interests during init.

merge_interests(Existing, New)

-spec merge_interests([binary()], [binary()]) -> [binary()].

Merge new interests with existing ones (removes duplicates).

normalize(Interests)

-spec normalize(term()) -> [binary()].

Normalize service interests to list of binaries. Accepts various input formats: list of binaries/atoms/strings, or single value.

normalize_single(Interest)

-spec normalize_single(term()) -> {true, binary()} | false.

Normalize a single service interest to binary. Returns {true, Binary} for valid inputs, false for invalid.