}
@Override
public List<OFMessage> parseMessages(ByteBuffer data, int limit) {
List<OFMessage> results = new ArrayList<OFMessage>();
OFMessage demux = new OFMessage();
OFMessage ofm;
while (limit == 0 || results.size() <= limit) {
if (data.remaining() < OFMessage.MINIMUM_LENGTH)
return results;
data.mark();
demux.readFrom(data);
data.reset();
if (demux.getLengthU() > data.remaining())
return results;
ofm = getMessage(demux.getType());
if (ofm instanceof OFActionFactoryAware) {
((OFActionFactoryAware)ofm).setActionFactory(this);
}
if (ofm instanceof OFMessageFactoryAware) {
((OFMessageFactoryAware)ofm).setMessageFactory(this);
}
if (ofm instanceof OFQueuePropertyFactoryAware) {
((OFQueuePropertyFactoryAware)ofm).setQueuePropertyFactory(this);
}
if (ofm instanceof OFStatisticsFactoryAware) {
((OFStatisticsFactoryAware)ofm).setStatisticsFactory(this);
}
ofm.readFrom(data);
if (OFMessage.class.equals(ofm.getClass())) {
// advance the position for un-implemented messages
data.position(data.position()+(ofm.getLengthU() -
OFMessage.MINIMUM_LENGTH));
}
results.add(ofm);
}