// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: service.proto
package com.squareup.digester.protos.service;

import com.squareup.wire.FieldEncoding;
import com.squareup.wire.Message;
import com.squareup.wire.ProtoAdapter;
import com.squareup.wire.ProtoReader;
import com.squareup.wire.ProtoWriter;
import com.squareup.wire.WireField;
import com.squareup.wire.internal.Internal;
import java.io.IOException;
import java.lang.Double;
import java.lang.Long;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import okio.ByteString;

/**
 * Representation of internals of a t-digest implementation.
 */
public final class DigestData extends Message<DigestData, DigestData.Builder> {
  public static final ProtoAdapter<DigestData> ADAPTER = new ProtoAdapter_DigestData();

  private static final long serialVersionUID = 0L;

  public static final Long DEFAULT_COUNT = 0L;

  public static final Double DEFAULT_SUM = 0.0d;

  public static final ByteString DEFAULT_VENEUR_DIGEST = ByteString.EMPTY;

  /**
   * Count of values observed.
   */
  @WireField(
      tag = 1,
      adapter = "com.squareup.wire.ProtoAdapter#INT64"
  )
  public final Long count;

  /**
   * Sum of observed values.
   */
  @WireField(
      tag = 2,
      adapter = "com.squareup.wire.ProtoAdapter#DOUBLE"
  )
  public final Double sum;

  /**
   * Serialized Veneur t-digest proto bytes.
   * github.com/stripe/veneur/tdigest
   */
  @WireField(
      tag = 3,
      adapter = "com.squareup.wire.ProtoAdapter#BYTES"
  )
  public final ByteString veneur_digest;

  public DigestData(Long count, Double sum, ByteString veneur_digest) {
    this(count, sum, veneur_digest, ByteString.EMPTY);
  }

  public DigestData(Long count, Double sum, ByteString veneur_digest, ByteString unknownFields) {
    super(ADAPTER, unknownFields);
    this.count = count;
    this.sum = sum;
    this.veneur_digest = veneur_digest;
  }

  @Override
  public Builder newBuilder() {
    Builder builder = new Builder();
    builder.count = count;
    builder.sum = sum;
    builder.veneur_digest = veneur_digest;
    builder.addUnknownFields(unknownFields());
    return builder;
  }

  @Override
  public boolean equals(Object other) {
    if (other == this) return true;
    if (!(other instanceof DigestData)) return false;
    DigestData o = (DigestData) other;
    return unknownFields().equals(o.unknownFields())
        && Internal.equals(count, o.count)
        && Internal.equals(sum, o.sum)
        && Internal.equals(veneur_digest, o.veneur_digest);
  }

  @Override
  public int hashCode() {
    int result = super.hashCode;
    if (result == 0) {
      result = unknownFields().hashCode();
      result = result * 37 + (count != null ? count.hashCode() : 0);
      result = result * 37 + (sum != null ? sum.hashCode() : 0);
      result = result * 37 + (veneur_digest != null ? veneur_digest.hashCode() : 0);
      super.hashCode = result;
    }
    return result;
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    if (count != null) builder.append(", count=").append(count);
    if (sum != null) builder.append(", sum=").append(sum);
    if (veneur_digest != null) builder.append(", veneur_digest=").append(veneur_digest);
    return builder.replace(0, 2, "DigestData{").append('}').toString();
  }

  public static final class Builder extends Message.Builder<DigestData, Builder> {
    public Long count;

    public Double sum;

    public ByteString veneur_digest;

    public Builder() {
    }

    /**
     * Count of values observed.
     */
    public Builder count(Long count) {
      this.count = count;
      return this;
    }

    /**
     * Sum of observed values.
     */
    public Builder sum(Double sum) {
      this.sum = sum;
      return this;
    }

    /**
     * Serialized Veneur t-digest proto bytes.
     * github.com/stripe/veneur/tdigest
     */
    public Builder veneur_digest(ByteString veneur_digest) {
      this.veneur_digest = veneur_digest;
      return this;
    }

    @Override
    public DigestData build() {
      return new DigestData(count, sum, veneur_digest, super.buildUnknownFields());
    }
  }

  private static final class ProtoAdapter_DigestData extends ProtoAdapter<DigestData> {
    public ProtoAdapter_DigestData() {
      super(FieldEncoding.LENGTH_DELIMITED, DigestData.class);
    }

    @Override
    public int encodedSize(DigestData value) {
      return ProtoAdapter.INT64.encodedSizeWithTag(1, value.count)
          + ProtoAdapter.DOUBLE.encodedSizeWithTag(2, value.sum)
          + ProtoAdapter.BYTES.encodedSizeWithTag(3, value.veneur_digest)
          + value.unknownFields().size();
    }

    @Override
    public void encode(ProtoWriter writer, DigestData value) throws IOException {
      ProtoAdapter.INT64.encodeWithTag(writer, 1, value.count);
      ProtoAdapter.DOUBLE.encodeWithTag(writer, 2, value.sum);
      ProtoAdapter.BYTES.encodeWithTag(writer, 3, value.veneur_digest);
      writer.writeBytes(value.unknownFields());
    }

    @Override
    public DigestData decode(ProtoReader reader) throws IOException {
      Builder builder = new Builder();
      long token = reader.beginMessage();
      for (int tag; (tag = reader.nextTag()) != -1;) {
        switch (tag) {
          case 1: builder.count(ProtoAdapter.INT64.decode(reader)); break;
          case 2: builder.sum(ProtoAdapter.DOUBLE.decode(reader)); break;
          case 3: builder.veneur_digest(ProtoAdapter.BYTES.decode(reader)); break;
          default: {
            FieldEncoding fieldEncoding = reader.peekFieldEncoding();
            Object value = fieldEncoding.rawProtoAdapter().decode(reader);
            builder.addUnknownField(tag, fieldEncoding, value);
          }
        }
      }
      reader.endMessage(token);
      return builder.build();
    }

    @Override
    public DigestData redact(DigestData value) {
      Builder builder = value.newBuilder();
      builder.clearUnknownFields();
      return builder.build();
    }
  }
}
