Package org.hxzon.netprotocol.parse

Source Code of org.hxzon.netprotocol.parse.CotpPacketGroup

package org.hxzon.netprotocol.parse;

import org.hxzon.netprotocol.common.IPacketPayload;
import org.hxzon.netprotocol.common.PacketGroup;
import org.hxzon.netprotocol.packet.CotpPacket;
import org.hxzon.netprotocol.packet.Packet;

public class CotpPacketGroup extends PacketGroup<CotpPacket> {

    protected CotpPacketGroup(int key) {
        super(key);
    }

    public void addPacket(CotpPacket packet) {
        super.addPacket(packet);
        packet.setGroup(this);
        if (packet.isLastUnit()) {
            _reachLast = true;
        }
    }

    public IPacketPayload parsePayload() {
        int reassemblyLen = 0;
        for (CotpPacket packet : _packets) {
            reassemblyLen += packet.getPayloadLength();
        }
        byte[] reassembly = new byte[reassemblyLen];
        int i = 0;
        int len = 0;
        for (CotpPacket packet : _packets) {
            len = packet.getPayloadLength();
            System.arraycopy(packet.getSrcData(), packet.getPayloadOffset(), reassembly, i, len);
            i += len;
        }
        _reassemblyData = reassembly;
        IPacketPayload payload = ProtocolBindingList.findBinding(_packets.get(0));
        if (payload != null) {
            if (payload instanceof Packet) {
                ((Packet) payload).init(reassembly, 0);
            }
        }
        return payload;
    }

}
TOP

Related Classes of org.hxzon.netprotocol.parse.CotpPacketGroup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.