Heartbeat and acknack message use the sequence number to distinguish messages, but if I use multiple instances of a datatype, the same sequence number would characterize different instances. In this situation how does the reader (that receive hertbeat) understands the instance associated?
Each RTPS Writer maintains its own sequence number. Each change of such a Writer gets a consecutive sequence number. This means that the combination of the SequenceNumber and the writerId uniquely identifies a change. The SequenceNumber has no relation with an instance.
AckNack messages contain a writerId that identifies the Writer entity that is the target of the AckNack message and a SequenceNumberSet that identifies the messages that have been received and/or are missing.
Heartbeat messages contain a writerId that identifies the sender and besides that a firstSN with lastSN SequenceNumber that respectively identify the first and the last sequence number that is available in the Writer.