Search Results for

    Show / Hide Table of Contents

    Class Message

    Abstract base class for messages to be sent via the circuit system.

    To use the messaging system, message types must be created as classes that inherit from this base class. Instances of the concrete message types can then be sent and received through partition sets, just like regular beeps.

    Messages use a priority system to solve conflicts: If multiple particles send different messages on a circuit in the same round, only the message with the highest priority is received by the particles on the circuit. Thus, the GreaterThan(Message) and Equals(Message) methods must be implemented such that they define a strict total order on the set of all possible messages.

    To ensure that messages can be saved and loaded correctly, every subclass must provide a parameterless default constructor and may only have simple members of primitive types like int, bool, string, or enums. In particular, no reference types or data structures like lists or arrays are supported as members.

    Inheritance
    object
    Message
    DirectionMessage
    MyMessage
    Namespace: AS2.Sim
    Assembly: .dll
    Syntax
    public abstract class Message

    Methods

    | Edit this page View Source

    Copy()

    Creates a deep copy of this message.

    The main purpose of this method is to prevent particles from sharing instances of messages due to reference semantics. Changing data in a message a particle has received (for example to forward the altered message later) can cause errors if this method does not create a deep copy of the original message.

    Declaration
    public abstract Message Copy()
    Returns
    Type Description
    Message

    A deep copy of this message.

    | Edit this page View Source

    CreateFromSaveData(MessageSaveData)

    Reconstructs a Message subclass instance from the given save data. Fields not stored in the save data will be left at the values set in the default constructor and fields stored in the save data that are not defined by the subclass will produce error messages.

    Declaration
    public static Message CreateFromSaveData(MessageSaveData data)
    Parameters
    Type Name Description
    MessageSaveData data

    The serializable data storing a message's type and members.

    Returns
    Type Description
    Message

    An instance of a Message subclass with the member values stored in data. Will be null if the message subtype cannot be determined or instantiated with a default constructor.

    | Edit this page View Source

    Equals(Message)

    Checks whether this message is equivalent to the given other message.

    This method should only return true if the two compared messages are equivalent in the sense that any particle receiving one of the messages will behave exactly as if it had received the other message. In other words, the messages have to be equivalent with respect to the total order defined on all possible messages.

    Note that this method and GreaterThan(Message) must not both return true when comparing the same instances.

    Declaration
    public abstract bool Equals(Message other)
    Parameters
    Type Name Description
    Message other

    The message that should be compared to this one.

    Returns
    Type Description
    bool

    true if and only if the two messages are equivalent with respect to the total ordering of all messages.

    | Edit this page View Source

    GenerateSaveData()

    Stores this instance's member variables in a serializable object.

    Uses reflection to find the members' names, types and values and stores the non-null values by their string representation.

    Declaration
    public MessageSaveData GenerateSaveData()
    Returns
    Type Description
    MessageSaveData

    A MessageSaveData instance storing the names, types and values of this message as strings.

    | Edit this page View Source

    GreaterThan(Message)

    Checks whether this message has a higher priority than the given other message.

    This is the main comparison operator defining the total order on the set of all possible messages. If the order is not strict, the message that is received in the case that multiple messages are sent on the same circuit in the same round may not be well-defined.

    Note that this method and Equals(Message) must not both return true when comparing the same instances.

    Declaration
    public abstract bool GreaterThan(Message other)
    Parameters
    Type Name Description
    Message other

    The message that should be compared to this one.

    Returns
    Type Description
    bool

    true if and only if this message has a strictly higher priority than the given other message.

    • Edit this page
    • View Source
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX