ServerSentEventReader.smali

.class public final Lokhttp3/internal/sse/ServerSentEventReader;
.super Ljava/lang/Object;
.source "SourceFile"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lokhttp3/internal/sse/ServerSentEventReader$Callback;
    }
.end annotation


# static fields
.field private static final CRLF:Lokio/e;

.field private static final DATA:Lokio/e;

.field private static final EVENT:Lokio/e;

.field private static final ID:Lokio/e;

.field private static final RETRY:Lokio/e;


# instance fields
.field private final callback:Lokhttp3/internal/sse/ServerSentEventReader$Callback;

.field private lastId:Ljava/lang/String;

.field private final source:Lokio/d;


# direct methods
.method public static constructor <clinit>()V
    .registers 1

    const-string v0, "\r\n"

    .line 1
    invoke-static {v0}, Lokio/e;->g(Ljava/lang/String;)Lokio/e;

    move-result-object v0

    sput-object v0, Lokhttp3/internal/sse/ServerSentEventReader;->CRLF:Lokio/e;

    const-string v0, "data"

    .line 2
    invoke-static {v0}, Lokio/e;->g(Ljava/lang/String;)Lokio/e;

    move-result-object v0

    sput-object v0, Lokhttp3/internal/sse/ServerSentEventReader;->DATA:Lokio/e;

    const-string v0, "id"

    .line 3
    invoke-static {v0}, Lokio/e;->g(Ljava/lang/String;)Lokio/e;

    move-result-object v0

    sput-object v0, Lokhttp3/internal/sse/ServerSentEventReader;->ID:Lokio/e;

    const-string v0, "event"

    .line 4
    invoke-static {v0}, Lokio/e;->g(Ljava/lang/String;)Lokio/e;

    move-result-object v0

    sput-object v0, Lokhttp3/internal/sse/ServerSentEventReader;->EVENT:Lokio/e;

    const-string v0, "retry"

    .line 5
    invoke-static {v0}, Lokio/e;->g(Ljava/lang/String;)Lokio/e;

    move-result-object v0

    sput-object v0, Lokhttp3/internal/sse/ServerSentEventReader;->RETRY:Lokio/e;

    return-void
.end method

.method public constructor <init>(Lokio/d;Lokhttp3/internal/sse/ServerSentEventReader$Callback;)V
    .registers 4

    .line 1
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const/4 v0, 0x0

    .line 2
    iput-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->lastId:Ljava/lang/String;

    const-string v0, "source == null"

    .line 3
    invoke-static {p1, v0}, Ljava/util/Objects;->requireNonNull(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;

    const-string v0, "callback == null"

    .line 4
    invoke-static {p2, v0}, Ljava/util/Objects;->requireNonNull(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;

    .line 5
    iput-object p1, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    .line 6
    iput-object p2, p0, Lokhttp3/internal/sse/ServerSentEventReader;->callback:Lokhttp3/internal/sse/ServerSentEventReader$Callback;

    return-void
.end method

.method private completeEvent(Ljava/lang/String;Ljava/lang/String;Lokio/b;)V
    .registers 9
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .line 1
    invoke-direct {p0}, Lokhttp3/internal/sse/ServerSentEventReader;->skipCrAndOrLf()V

    .line 2
    iget-wide v0, p3, Lokio/b;->b:J

    const-wide/16 v2, 0x0

    cmp-long v4, v0, v2

    if-eqz v4, :cond_1b

    .line 3
    iput-object p1, p0, Lokhttp3/internal/sse/ServerSentEventReader;->lastId:Ljava/lang/String;

    const-wide/16 v0, 0x1

    .line 4
    invoke-virtual {p3, v0, v1}, Lokio/b;->skip(J)V

    .line 5
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->callback:Lokhttp3/internal/sse/ServerSentEventReader$Callback;

    invoke-virtual {p3}, Lokio/b;->M()Ljava/lang/String;

    move-result-object p3

    invoke-interface {v0, p1, p2, p3}, Lokhttp3/internal/sse/ServerSentEventReader$Callback;->onEvent(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

    :cond_1b
    return-void
.end method

.method private isKey(Lokio/e;)Z
    .registers 5
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .line 1
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, p1}, Lokio/d;->Q(Lokio/e;)Z

    move-result v0

    if-eqz v0, :cond_25

    .line 2
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0}, Lokio/d;->c()Lokio/b;

    move-result-object v0

    invoke-virtual {p1}, Lokio/e;->r()I

    move-result p1

    int-to-long v1, p1

    invoke-virtual {v0, v1, v2}, Lokio/b;->u(J)B

    move-result p1

    const/16 v0, 0x3a

    if-eq p1, v0, :cond_23

    const/16 v0, 0xd

    if-eq p1, v0, :cond_23

    const/16 v0, 0xa

    if-ne p1, v0, :cond_25

    :cond_23
    const/4 p1, 0x1

    goto :goto_26

    :cond_25
    const/4 p1, 0x0

    :goto_26
    return p1
.end method

.method private parseData(Lokio/b;J)V
    .registers 6
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const/16 v0, 0xa

    .line 1
    invoke-virtual {p1, v0}, Lokio/b;->c0(I)Lokio/b;

    const-wide/16 v0, 0x4

    .line 2
    invoke-direct {p0, v0, v1}, Lokhttp3/internal/sse/ServerSentEventReader;->skipNameAndDivider(J)J

    move-result-wide v0

    sub-long/2addr p2, v0

    .line 3
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, p1, p2, p3}, Lokio/d;->g0(Lokio/b;J)V

    .line 4
    invoke-direct {p0}, Lokhttp3/internal/sse/ServerSentEventReader;->skipCrAndOrLf()V

    return-void
.end method

.method private parseEvent(J)Ljava/lang/String;
    .registers 6
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const-wide/16 v0, 0x5

    .line 1
    invoke-direct {p0, v0, v1}, Lokhttp3/internal/sse/ServerSentEventReader;->skipNameAndDivider(J)J

    move-result-wide v0

    sub-long/2addr p1, v0

    const-wide/16 v0, 0x0

    cmp-long v2, p1, v0

    if-eqz v2, :cond_14

    .line 2
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, p1, p2}, Lokio/d;->t(J)Ljava/lang/String;

    move-result-object p1

    goto :goto_15

    :cond_14
    const/4 p1, 0x0

    .line 3
    :goto_15
    invoke-direct {p0}, Lokhttp3/internal/sse/ServerSentEventReader;->skipCrAndOrLf()V

    return-object p1
.end method

.method private parseId(J)Ljava/lang/String;
    .registers 6
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const-wide/16 v0, 0x2

    .line 1
    invoke-direct {p0, v0, v1}, Lokhttp3/internal/sse/ServerSentEventReader;->skipNameAndDivider(J)J

    move-result-wide v0

    sub-long/2addr p1, v0

    const-wide/16 v0, 0x0

    cmp-long v2, p1, v0

    if-eqz v2, :cond_14

    .line 2
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, p1, p2}, Lokio/d;->t(J)Ljava/lang/String;

    move-result-object p1

    goto :goto_15

    :cond_14
    const/4 p1, 0x0

    .line 3
    :goto_15
    invoke-direct {p0}, Lokhttp3/internal/sse/ServerSentEventReader;->skipCrAndOrLf()V

    return-object p1
.end method

.method private parseRetry(J)V
    .registers 6
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const-wide/16 v0, 0x5

    .line 1
    invoke-direct {p0, v0, v1}, Lokhttp3/internal/sse/ServerSentEventReader;->skipNameAndDivider(J)J

    move-result-wide v0

    sub-long/2addr p1, v0

    .line 2
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, p1, p2}, Lokio/d;->t(J)Ljava/lang/String;

    move-result-object p1

    const-wide/16 v0, -0x1

    .line 3
    :try_start_f
    invoke-static {p1}, Ljava/lang/Long;->parseLong(Ljava/lang/String;)J

    move-result-wide p1
    :try_end_13
    .catch Ljava/lang/NumberFormatException; {:try_start_f .. :try_end_13} :catch_14

    goto :goto_15

    :catch_14
    move-wide p1, v0

    :goto_15
    cmp-long v2, p1, v0

    if-eqz v2, :cond_1e

    .line 4
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->callback:Lokhttp3/internal/sse/ServerSentEventReader$Callback;

    invoke-interface {v0, p1, p2}, Lokhttp3/internal/sse/ServerSentEventReader$Callback;->onRetryChange(J)V

    .line 5
    :cond_1e
    invoke-direct {p0}, Lokhttp3/internal/sse/ServerSentEventReader;->skipCrAndOrLf()V

    return-void
.end method

.method private skipCrAndOrLf()V
    .registers 6
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .line 1
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0}, Lokio/d;->readByte()B

    move-result v0

    and-int/lit16 v0, v0, 0xff

    const/16 v1, 0xd

    if-ne v0, v1, :cond_2b

    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    const-wide/16 v1, 0x1

    .line 2
    invoke-interface {v0, v1, v2}, Lokio/d;->request(J)Z

    move-result v0

    if-eqz v0, :cond_2b

    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    .line 3
    invoke-interface {v0}, Lokio/d;->c()Lokio/b;

    move-result-object v0

    const-wide/16 v3, 0x0

    invoke-virtual {v0, v3, v4}, Lokio/b;->u(J)B

    move-result v0

    const/16 v3, 0xa

    if-ne v0, v3, :cond_2b

    .line 4
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, v1, v2}, Lokio/d;->skip(J)V

    :cond_2b
    return-void
.end method

.method private skipNameAndDivider(J)J
    .registers 8
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .line 1
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, p1, p2}, Lokio/d;->skip(J)V

    .line 2
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0}, Lokio/d;->c()Lokio/b;

    move-result-object v0

    const-wide/16 v1, 0x0

    invoke-virtual {v0, v1, v2}, Lokio/b;->u(J)B

    move-result v0

    const/16 v3, 0x3a

    if-ne v0, v3, :cond_31

    .line 3
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    const-wide/16 v3, 0x1

    invoke-interface {v0, v3, v4}, Lokio/d;->skip(J)V

    add-long/2addr p1, v3

    .line 4
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0}, Lokio/d;->c()Lokio/b;

    move-result-object v0

    invoke-virtual {v0, v1, v2}, Lokio/b;->u(J)B

    move-result v0

    const/16 v1, 0x20

    if-ne v0, v1, :cond_31

    .line 5
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v0, v3, v4}, Lokio/d;->skip(J)V

    add-long/2addr p1, v3

    :cond_31
    return-wide p1
.end method


# virtual methods
.method public processNextEvent()Z
    .registers 9
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .line 1
    iget-object v0, p0, Lokhttp3/internal/sse/ServerSentEventReader;->lastId:Ljava/lang/String;

    .line 2
    new-instance v1, Lokio/b;

    invoke-direct {v1}, Lokio/b;-><init>()V

    const/4 v2, 0x0

    .line 3
    :goto_8
    iget-object v3, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    sget-object v4, Lokhttp3/internal/sse/ServerSentEventReader;->CRLF:Lokio/e;

    invoke-interface {v3, v4}, Lokio/d;->k(Lokio/e;)J

    move-result-wide v3

    const-wide/16 v5, -0x1

    cmp-long v7, v3, v5

    if-nez v7, :cond_18

    const/4 v0, 0x0

    return v0

    .line 4
    :cond_18
    iget-object v5, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v5}, Lokio/d;->c()Lokio/b;

    move-result-object v5

    const-wide/16 v6, 0x0

    invoke-virtual {v5, v6, v7}, Lokio/b;->u(J)B

    move-result v5

    const/16 v6, 0xa

    if-eq v5, v6, :cond_78

    const/16 v6, 0xd

    if-eq v5, v6, :cond_78

    const/16 v6, 0x69

    if-eq v5, v6, :cond_62

    const/16 v6, 0x72

    if-eq v5, v6, :cond_56

    const/16 v6, 0x64

    if-eq v5, v6, :cond_4a

    const/16 v6, 0x65

    if-eq v5, v6, :cond_3d

    goto :goto_6f

    .line 5
    :cond_3d
    sget-object v5, Lokhttp3/internal/sse/ServerSentEventReader;->EVENT:Lokio/e;

    invoke-direct {p0, v5}, Lokhttp3/internal/sse/ServerSentEventReader;->isKey(Lokio/e;)Z

    move-result v5

    if-eqz v5, :cond_6f

    .line 6
    invoke-direct {p0, v3, v4}, Lokhttp3/internal/sse/ServerSentEventReader;->parseEvent(J)Ljava/lang/String;

    move-result-object v2

    goto :goto_8

    .line 7
    :cond_4a
    sget-object v5, Lokhttp3/internal/sse/ServerSentEventReader;->DATA:Lokio/e;

    invoke-direct {p0, v5}, Lokhttp3/internal/sse/ServerSentEventReader;->isKey(Lokio/e;)Z

    move-result v5

    if-eqz v5, :cond_6f

    .line 8
    invoke-direct {p0, v1, v3, v4}, Lokhttp3/internal/sse/ServerSentEventReader;->parseData(Lokio/b;J)V

    goto :goto_8

    .line 9
    :cond_56
    sget-object v5, Lokhttp3/internal/sse/ServerSentEventReader;->RETRY:Lokio/e;

    invoke-direct {p0, v5}, Lokhttp3/internal/sse/ServerSentEventReader;->isKey(Lokio/e;)Z

    move-result v5

    if-eqz v5, :cond_6f

    .line 10
    invoke-direct {p0, v3, v4}, Lokhttp3/internal/sse/ServerSentEventReader;->parseRetry(J)V

    goto :goto_8

    .line 11
    :cond_62
    sget-object v5, Lokhttp3/internal/sse/ServerSentEventReader;->ID:Lokio/e;

    invoke-direct {p0, v5}, Lokhttp3/internal/sse/ServerSentEventReader;->isKey(Lokio/e;)Z

    move-result v5

    if-eqz v5, :cond_6f

    .line 12
    invoke-direct {p0, v3, v4}, Lokhttp3/internal/sse/ServerSentEventReader;->parseId(J)Ljava/lang/String;

    move-result-object v0

    goto :goto_8

    .line 13
    :cond_6f
    :goto_6f
    iget-object v5, p0, Lokhttp3/internal/sse/ServerSentEventReader;->source:Lokio/d;

    invoke-interface {v5, v3, v4}, Lokio/d;->skip(J)V

    .line 14
    invoke-direct {p0}, Lokhttp3/internal/sse/ServerSentEventReader;->skipCrAndOrLf()V

    goto :goto_8

    .line 15
    :cond_78
    invoke-direct {p0, v0, v2, v1}, Lokhttp3/internal/sse/ServerSentEventReader;->completeEvent(Ljava/lang/String;Ljava/lang/String;Lokio/b;)V

    const/4 v0, 0x1

    return v0
.end method