package com.seewo.remote.e.j;

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

/* JADX INFO: compiled from: BenqCommandParser.java */
/* JADX INFO: loaded from: classes.dex */
public class a 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[]> f261c;

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

    /* JADX INFO: compiled from: BenqCommandParser.java */
    public static class b {
        byte[] a = new byte[0];
        byte[] b = new byte[0];

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

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

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

    private boolean d() {
        int size = this.f262d.size();
        if (this.f262d.size() < this.b.length) {
            return false;
        }
        int i2 = 0;
        while (true) {
            byte[] bArr = this.b;
            if (i2 >= bArr.length) {
                return true;
            }
            if (this.f262d.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.f261c;
    }

    @Override // com.seewo.remote.e.j.c
    public void b(byte b2) {
        this.f262d.add(Byte.valueOf(b2));
        if (d()) {
            int size = this.f262d.size();
            if (size < this.b.length + this.a.length) {
                c();
                return;
            }
            for (int i2 = 0; i2 < this.a.length; i2++) {
                if (this.f262d.get(i2).byteValue() != this.a[i2]) {
                    c();
                    return;
                }
            }
            byte[] bArr = new byte[size];
            for (int i3 = 0; i3 < size; i3++) {
                bArr[i3] = this.f262d.get(i3).byteValue();
            }
            if (bArr[3] != 115 || bArr[4] != -32) {
                c();
                e.c.e.f.e.g("BenqCommandParser", "next: " + w.a(bArr));
                this.f261c.d(bArr);
                return;
            }
            if (size < 15) {
                e.c.e.f.e.g("BenqCommandParser", "on off " + w.a(bArr));
                return;
            }
            c();
            e.c.e.f.e.g("BenqCommandParser", "1 next: " + w.a(bArr));
            this.f261c.d(bArr);
        }
    }

    private a(b bVar) {
        this.f261c = f.a.r.a.x();
        this.f262d = new LinkedList<>();
        this.a = bVar.a;
        this.b = bVar.b;
    }
}
