All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jrtps.message.InfoSource Maven / Gradle / Ivy

package net.sf.jrtps.message;

import net.sf.jrtps.transport.RTPSByteBuffer;
import net.sf.jrtps.types.GuidPrefix;
import net.sf.jrtps.types.ProtocolVersion_t;
import net.sf.jrtps.types.VendorId_t;

/**
 * This message modifies the logical source of the Submessages that follow.
 * 
 * see 9.4.5.10 InfoSource Submessage, 8.3.7.9 InfoSource
 * 
 * @author mcr70
 * 
 */
public class InfoSource extends SubMessage {
    public static final int KIND = 0x0c;

    private ProtocolVersion_t protocolVersion;
    private VendorId_t vendorId;
    private GuidPrefix guidPrefix;    
    
    public InfoSource(GuidPrefix guidPrefix) {
        super(new SubMessageHeader(KIND));

        this.protocolVersion = ProtocolVersion_t.PROTOCOLVERSION_2_1;
        this.vendorId = VendorId_t.VENDORID_JRTPS;
        this.guidPrefix = guidPrefix;
    }

    InfoSource(SubMessageHeader smh, RTPSByteBuffer bb) {
        super(smh);

        readMessage(bb);
    }

    /**
     * Indicates the protocol used to encapsulate subsequent Submessages.
     */
    public ProtocolVersion_t getProtocolVersion() {
        return protocolVersion;
    }

    /**
     * Indicates the VendorId of the vendor that encapsulated subsequent
     * Submessages.
     */
    public VendorId_t getVendorId() {
        return vendorId;
    }

    /**
     * Identifies the Participant that is the container of the RTPS Writer
     * entities that are the source of the Submessages that follow.
     */
    public GuidPrefix getGuidPrefix() {
        return guidPrefix;
    }

    private void readMessage(RTPSByteBuffer bb) {
        bb.read_long(); // unused

        protocolVersion = new ProtocolVersion_t(bb);
        vendorId = new VendorId_t(bb);
        guidPrefix = new GuidPrefix(bb);
    }

    @Override
    public void writeTo(RTPSByteBuffer bb) {
        bb.write_long(0);
        protocolVersion.writeTo(bb);
        vendorId.writeTo(bb);
        guidPrefix.writeTo(bb);
    }

    public String toString() {
        return super.toString() + ", " + guidPrefix;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy