Search in sources :

Example 1 with InstancePacket

use of me.retrodaredevil.solarthing.packets.instance.InstancePacket in project solarthing by wildmountainfarms.

the class PacketGroups method parseToTargetPacketGroup.

public static TargetPacketGroup parseToTargetPacketGroup(PacketGroup packetGroup) {
    if (packetGroup instanceof TargetPacketGroup) {
        return (TargetPacketGroup) packetGroup;
    }
    List<Packet> packets = new ArrayList<>();
    InstanceSourcePacket sourcePacket = null;
    InstanceTargetPacket targetPacket = null;
    for (Packet packet : packetGroup.getPackets()) {
        if (packet instanceof InstancePacket) {
            InstancePacket instancePacket = (InstancePacket) packet;
            switch(instancePacket.getPacketType()) {
                case SOURCE:
                    sourcePacket = (InstanceSourcePacket) packet;
                    break;
                case TARGET:
                    targetPacket = (InstanceTargetPacket) packet;
                    break;
            }
        } else {
            packets.add(packet);
        }
    }
    return createTargetPacketGroup(packets, packetGroup.getDateMillis(), sourcePacket == null ? InstanceSourcePacket.UNUSED_SOURCE_ID : sourcePacket.getSourceId(), targetPacket == null ? Collections.emptyList() : targetPacket.getTargetFragmentIds());
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) InstanceFragmentIndicatorPacket(me.retrodaredevil.solarthing.packets.instance.InstanceFragmentIndicatorPacket) InstancePacket(me.retrodaredevil.solarthing.packets.instance.InstancePacket) InstanceSourcePacket(me.retrodaredevil.solarthing.packets.instance.InstanceSourcePacket) InstanceTargetPacket(me.retrodaredevil.solarthing.packets.instance.InstanceTargetPacket) InstancePacket(me.retrodaredevil.solarthing.packets.instance.InstancePacket) InstanceSourcePacket(me.retrodaredevil.solarthing.packets.instance.InstanceSourcePacket) InstanceTargetPacket(me.retrodaredevil.solarthing.packets.instance.InstanceTargetPacket)

Example 2 with InstancePacket

use of me.retrodaredevil.solarthing.packets.instance.InstancePacket in project solarthing by wildmountainfarms.

the class PacketGroups method parseToInstancePacketGroup.

public static InstancePacketGroup parseToInstancePacketGroup(PacketGroup group, DefaultInstanceOptions defaultInstanceOptions) {
    if (group instanceof InstancePacketGroup) {
        return (InstancePacketGroup) group;
    }
    List<Packet> packets = new ArrayList<>();
    String sourceId = defaultInstanceOptions.getDefaultSourceId();
    int fragmentId = defaultInstanceOptions.getDefaultFragmentId();
    for (Packet packet : group.getPackets()) {
        if (packet instanceof InstancePacket) {
            InstancePacket instancePacket = (InstancePacket) packet;
            switch(instancePacket.getPacketType()) {
                case SOURCE:
                    sourceId = ((InstanceSourcePacket) instancePacket).getSourceId();
                    break;
                case FRAGMENT_INDICATOR:
                    fragmentId = ((InstanceFragmentIndicatorPacket) instancePacket).getFragmentId();
                    break;
                default:
                    break;
            }
        } else {
            packets.add(packet);
        }
    }
    return createInstancePacketGroup(packets, group.getDateMillis(), sourceId, fragmentId);
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) InstanceFragmentIndicatorPacket(me.retrodaredevil.solarthing.packets.instance.InstanceFragmentIndicatorPacket) InstancePacket(me.retrodaredevil.solarthing.packets.instance.InstancePacket) InstanceSourcePacket(me.retrodaredevil.solarthing.packets.instance.InstanceSourcePacket) InstanceTargetPacket(me.retrodaredevil.solarthing.packets.instance.InstanceTargetPacket) InstancePacket(me.retrodaredevil.solarthing.packets.instance.InstancePacket)

Aggregations

Packet (me.retrodaredevil.solarthing.packets.Packet)2 InstanceFragmentIndicatorPacket (me.retrodaredevil.solarthing.packets.instance.InstanceFragmentIndicatorPacket)2 InstancePacket (me.retrodaredevil.solarthing.packets.instance.InstancePacket)2 InstanceSourcePacket (me.retrodaredevil.solarthing.packets.instance.InstanceSourcePacket)2 InstanceTargetPacket (me.retrodaredevil.solarthing.packets.instance.InstanceTargetPacket)2