// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
// 
//     public IncorrectFrameException(final String msg) {
//         super(msg);
//     }
// 
// }
// 
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();


import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.types.*;
/*
 * The Dragonite Project
 * -------------------------
 * See the LICENSE file in the root directory for license information.
 */


package com.vecsight.dragonite.mux.frame;



public class FrameParser {

    private final FrameBuffer frameBuffer;

    private boolean needMore = false;

    private int expectedLength = 0;

    public FrameParser(final int maxFrameSize) {
        frameBuffer = new FrameBuffer(maxFrameSize);
    }

    public Frame feed(final byte[] rawBytes) {

        frameBuffer.add(rawBytes);

        if (!needMore || frameBuffer.getSize() >= expectedLength) {

            try {
                final Frame frame = parseFrameRaw(frameBuffer.get());

                if (frame.getExpectedLength() == 0) {
                    frameBuffer.reset();
                    needMore = false;
                    return frame;

                } else {
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
// 
//     public IncorrectFrameException(final String msg) {
//         super(msg);
//     }
// 
// }
// 
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();


// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.types.*;

/*
 * The Dragonite Project
 * -------------------------
 * See the LICENSE file in the root directory for license information.
 */


package com.vecsight.dragonite.mux.frame;



public class FrameParser {

    private final FrameBuffer frameBuffer;

    private boolean needMore = false;

    private int expectedLength = 0;

    public FrameParser(final int maxFrameSize) {
        frameBuffer = new FrameBuffer(maxFrameSize);
    }

    public Frame feed(final byte[] rawBytes) {

        frameBuffer.add(rawBytes);

        if (!needMore || frameBuffer.getSize() >= expectedLength) {

            try {
                final Frame frame = parseFrameRaw(frameBuffer.get());

                if (frame.getExpectedLength() == 0) {
                    frameBuffer.reset();
                    needMore = false;
                    return frame;

                } else {
                    expectedLength = frame.getExpectedLength();