Message

class Message(content: RecordDict, dst_node_id: int, message_type: str, *, ttl: float | None = None, group_id: str | None = None)[소스]
class Message(content: RecordDict, *, reply_to: Message, ttl: float | None = None)
class Message(error: Error, *, reply_to: Message, ttl: float | None = None)

기반 클래스: InflatableObject

Represents a message exchanged between ClientApp and ServerApp.

This class encapsulates the payload and metadata necessary for communication between a ClientApp and a ServerApp.

매개변수:
  • content (Optional[RecordDict] (default: None)) – 다른 엔터티(예: 서버 측 로직이 클라이언트로 전송하거나 그 반대로 전송하는 등)가 전송했거나 전송할 레코드를 보유합니다.

  • error (Optional[Error] (default: None)) – 다른 메시지를 처리할 때 발생한 오류에 대한 정보를 캡처하는 데이터 클래스입니다.

  • dst_node_id (Optional[int] (default: None)) – 이 메시지를 수신하는 노드의 식별자입니다.

  • message_type (Optional[str] (default: None)) – 수신 측에서 실행할 작업을 인코딩하는 문자열입니다.

  • ttl (Optional[float] (default: None)) – Time-to-live (TTL) for this message in seconds. If None (default), the TTL is set to 43,200 seconds (12 hours).

  • group_id (Optional[str] (default: None)) – 메시지를 그룹화하기 위한 식별자입니다. 일부 설정에서는 FL 라운드로 사용됩니다.

  • reply_to (Optional[Message] (default: None)) – The instruction message to which this message is a reply. This message does not retain the original message’s content but derives its metadata from it.

메소드

create_error_reply(error[, ttl])

오류가 발생했음을 나타내는 답장 메시지를 작성합니다.

create_reply(content[, ttl])

지정된 콘텐츠와 TTL을 사용하여 이 메시지에 대한 답글을 작성합니다.

deflate()

Deflate message.

has_content()

메시지에 콘텐츠가 있으면 True을 반환하고, 그렇지 않으면 False을 반환합니다.

has_error()

메시지에 오류가 있으면 True을 반환하고, 그렇지 않으면 False을 반환합니다.

inflate(object_content[, children])

Inflate an Message from bytes.

속성

children

Return a dictionary of a single RecordDict with its Object IDs as key.

content

이 메시지의 내용입니다.

error

이 메시지가 캡처한 오류입니다.

is_dirty

Check if the object is dirty after the last deflation.

metadata

실행할 메시지에 대한 정보를 포함한 데이터 클래스입니다.

object_id

Get object_id.

property children: dict[str, InflatableObject] | None

Return a dictionary of a single RecordDict with its Object IDs as key.

property content: RecordDict

이 메시지의 내용입니다.

create_error_reply(error: Error, ttl: float | None = None) Message[소스]

오류가 발생했음을 나타내는 답장 메시지를 작성합니다.

매개변수:
  • error (Error) – 오류가 발생했습니다.

  • ttl (Optional[float] (default: None)) – 이 메시지의 남은 시간(초)입니다. 설정하지 않으면 수신된 메시지가 만료되기 전까지 남은 시간을 기준으로 설정됩니다. 이는 다음과 같은 공식을 따릅니다: ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)

반환:

message – A Message containing only the relevant error and metadata.

반환 형식:

Message

create_reply(content: RecordDict, ttl: float | None = None) Message[소스]

지정된 콘텐츠와 TTL을 사용하여 이 메시지에 대한 답글을 작성합니다.

The method generates a new Message as a reply to this message. It inherits ‘run_id’, ‘src_node_id’, ‘dst_node_id’, and ‘message_type’ from this message and sets ‘reply_to_message_id’ to the ID of this message.

매개변수:
  • content (RecordDict) – 답장 메시지의 콘텐츠입니다.

  • ttl (Optional[float] (default: None)) – 이 메시지의 남은 시간(초)입니다. 설정하지 않으면 수신된 메시지가 만료되기 전까지 남은 시간을 기준으로 설정됩니다. 이는 다음과 같은 공식을 따릅니다: ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)

반환:

답장을 나타내는 새로운 메시지 인스턴스입니다.

반환 형식:

Message

deflate() bytes[소스]

Deflate message.

property error: Error

이 메시지가 캡처한 오류입니다.

has_content() bool[소스]

메시지에 콘텐츠가 있으면 True을 반환하고, 그렇지 않으면 False을 반환합니다.

has_error() bool[소스]

메시지에 오류가 있으면 True을 반환하고, 그렇지 않으면 False을 반환합니다.

classmethod inflate(object_content: bytes, children: dict[str, InflatableObject] | None = None) Message[소스]

Inflate an Message from bytes.

매개변수:
  • object_content (bytes) – The deflated object content of the Message.

  • children (Optional[dict[str, InflatableObject]] (default: None)) – Dictionary of children InflatableObjects mapped to their Object IDs. These children enable the full inflation of the Message.

반환:

The inflated Message.

반환 형식:

Message

property is_dirty: bool

Check if the object is dirty after the last deflation.

An object is considered dirty if its content has changed since the last its object ID was computed.

property metadata: Metadata

실행할 메시지에 대한 정보를 포함한 데이터 클래스입니다.

property object_id: str

Get object_id.