package com.seewo.remote.e.j;

import com.seewo.remote.g.w;
import java.util.LinkedList;

/* JADX INFO: compiled from: ClientCmdParser.java */
/* JADX INFO: loaded from: classes.dex */
public class b implements c {
    private final byte[] a;
    private final byte[] b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final f.a.r.a<byte[]> f263c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final LinkedList<Byte> f264d;

    /* JADX INFO: renamed from: com.seewo.remote.e.j.b$b, reason: collision with other inner class name */
    /* JADX INFO: compiled from: ClientCmdParser.java */
    public static class C0011b {
        byte[] a = new byte[0];
        byte[] b = new byte[0];

        public b a() {
            if (this.b.length != 0) {
                return new b(this);
            }
            throw new e();
        }

        public C0011b b(byte[] bArr) {
            this.a = bArr;
            return this;
        }

        public C0011b c(byte[] bArr) {
            this.b = bArr;
            return this;
        }
    }

    private void c() {
        this.f264d.clear();
    }

    private boolean d() {
        int size = this.f264d.size();
        if (this.f264d.size() < this.b.length) {
            return false;
        }
        int i2 = 0;
        while (true) {
            byte[] bArr = this.b;
            if (i2 >= bArr.length) {
                return true;
            }
            if (this.f264d.get((size - bArr.length) + i2).byteValue() != this.b[i2]) {
                return false;
            }
            i2++;
        }
    }

    @Override // com.seewo.remote.e.j.c
    public f.a.d<byte[]> a() {
        return this.f263c;
    }

    @Override // com.seewo.remote.e.j.c
    public void b(byte b) {
        int i2;
        this.f264d.add(Byte.valueOf(b));
        if (d()) {
            int size = this.f264d.size();
            if (size < this.b.length + this.a.length) {
                c();
                return;
            }
            for (int i3 = 0; i3 < this.a.length; i3++) {
                if (this.f264d.get(i3).byteValue() != this.a[i3]) {
                    c();
                    return;
                }
            }
            byte[] bArr = new byte[size];
            for (int i4 = 0; i4 < size; i4++) {
                bArr[i4] = this.f264d.get(i4).byteValue();
            }
            if (bArr[0] == 0 || bArr[0] == 10) {
                i2 = 0;
                for (int i5 = 0; i5 < size && (bArr[0] == 10 || bArr[i5] == 0); i5++) {
                    i2++;
                }
            } else {
                i2 = 0;
            }
            int i6 = size - i2;
            byte[] bArr2 = new byte[i6];
            System.arraycopy(bArr, i2, bArr2, 0, i6);
            c();
            e.c.e.f.e.g("CommonCommandParser", "next: " + w.a(bArr2));
            this.f263c.d(bArr2);
        }
    }

    private b(C0011b c0011b) {
        this.f263c = f.a.r.a.x();
        this.f264d = new LinkedList<>();
        this.a = c0011b.a;
        this.b = c0011b.b;
    }
}
