Skip to content

Commit

Permalink
Add pipe docstring (#2868)
Browse files Browse the repository at this point in the history
Co-authored-by: Chester Chen <[email protected]>
  • Loading branch information
YuanTingHsieh and chesterxgchen authored Aug 29, 2024
1 parent 2bb6e27 commit 7a843fb
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion nvflare/fuel/utils/pipe/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Message:
def __init__(self, msg_type: str, topic: str, data: Any, msg_id=None, req_id=None):
check_str("msg_type", msg_type)
if msg_type not in [Message.REPLY, Message.REQUEST]:
raise ValueError(f"invalid note_type '{msg_type}': must be one of {[Message.REPLY, Message.REQUEST]}")
raise ValueError(f"invalid msg_type '{msg_type}': must be one of {[Message.REPLY, Message.REQUEST]}")
self.msg_type = msg_type

check_str("topic", topic)
Expand All @@ -61,10 +61,46 @@ def __init__(self, msg_type: str, topic: str, data: Any, msg_id=None, req_id=Non

@staticmethod
def new_request(topic: str, data: Any, msg_id=None):
"""Creates a new request message.
This static method creates a new `Message` object representing a request.
Args:
topic (str): The topic of the request message.
This is a string that identifies the subject or category of the request.
data (Any): The data associated with the request message.
This can be any type of data that is relevant to the request.
msg_id (Optional[Any]): An optional identifier for the message.
If provided, this ID is used to uniquely identify the message.
If not provided, a UUID will be generated to uniquely identify the message.
Returns:
Message: A `Message` object with the type set to `Message.REQUEST`,
and the provided `topic`, `data`, and `msg_id`.
"""
return Message(Message.REQUEST, topic, data, msg_id)

@staticmethod
def new_reply(topic: str, data: Any, req_msg_id, msg_id=None):
"""Creates a new reply message in response to a request.
This static method creates a new `Message` object representing a reply to a previous request.
Args:
topic (str): The topic of the reply message.
This is a string that identifies the subject or category of the reply.
data (Any): The data associated with the reply message. This can be any type of data relevant to the reply.
req_msg_id (int): The identifier of the request message that this reply is responding to.
This ID links the reply to the original request.
msg_id (Optional[int]): An optional identifier for the reply message.
If provided, this ID is used to uniquely identify the message.
If not provided, a UUID will be generated to uniquely identify the message.
Returns:
Message: A `Message` object with the type set to `Message.REPLY`,
and the provided `topic`, `data`, `msg_id`, and `req_msg_id`.
"""
return Message(Message.REPLY, topic, data, msg_id, req_id=req_msg_id)

def __str__(self):
Expand Down

0 comments on commit 7a843fb

Please sign in to comment.