All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.protobuf.duration.Duration.scala Maven / Gradle / Ivy

// Generated by the Scala Plugin for the Protocol Buffer Compiler.
// Do not edit!
//
// Protofile syntax: PROTO3

package com.google.protobuf.duration

import scala.collection.JavaConversions._

/** A Duration represents a signed, fixed-length span of time represented
  * as a count of seconds and fractions of seconds at nanosecond
  * resolution. It is independent of any calendar and concepts like "day"
  * or "month". It is related to Timestamp in that the difference between
  * two Timestamp values is a Duration and it can be added or subtracted
  * from a Timestamp. Range is approximately +-10,000 years.
  *
  * Example 1: Compute Duration from two Timestamps in pseudo code.
  *
  *     Timestamp start = ...;
  *     Timestamp end = ...;
  *     Duration duration = ...;
  *
  *     duration.seconds = end.seconds - start.seconds;
  *     duration.nanos = end.nanos - start.nanos;
  *
  *     if (duration.seconds < 0 && duration.nanos > 0) {
  *       duration.seconds += 1;
  *       duration.nanos -= 1000000000;
  *     } else if (durations.seconds > 0 && duration.nanos < 0) {
  *       duration.seconds -= 1;
  *       duration.nanos += 1000000000;
  *     }
  *
  * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
  *
  *     Timestamp start = ...;
  *     Duration duration = ...;
  *     Timestamp end = ...;
  *
  *     end.seconds = start.seconds + duration.seconds;
  *     end.nanos = start.nanos + duration.nanos;
  *
  *     if (end.nanos < 0) {
  *       end.seconds -= 1;
  *       end.nanos += 1000000000;
  *     } else if (end.nanos >= 1000000000) {
  *       end.seconds += 1;
  *       end.nanos -= 1000000000;
  *     }
  *
  * @param seconds
  *   Signed seconds of the span of time. Must be from -315,576,000,000
  *   to +315,576,000,000 inclusive.
  * @param nanos
  *   Signed fractions of a second at nanosecond resolution of the span
  *   of time. Durations less than one second are represented with a 0
  *   `seconds` field and a positive or negative `nanos` field. For durations
  *   of one second or more, a non-zero value for the `nanos` field must be
  *   of the same sign as the `seconds` field. Must be from -999,999,999
  *   to +999,999,999 inclusive.
  */
@SerialVersionUID(0L)
final case class Duration(
    seconds: Long = 0L,
    nanos: Int = 0
    ) extends com.trueaccord.scalapb.GeneratedMessage with com.trueaccord.scalapb.Message[Duration] with com.trueaccord.lenses.Updatable[Duration] {
    @transient
    private[this] var __serializedSizeCachedValue: Int = 0
    private[this] def __computeSerializedValue(): Int = {
      var __size = 0
      if (seconds != 0L) { __size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, seconds) }
      if (nanos != 0) { __size += com.google.protobuf.CodedOutputStream.computeInt32Size(2, nanos) }
      __size
    }
    final override def serializedSize: Int = {
      var read = __serializedSizeCachedValue
      if (read == 0) {
        read = __computeSerializedValue()
        __serializedSizeCachedValue = read
      }
      read
    }
    def writeTo(`_output__`: com.google.protobuf.CodedOutputStream): Unit = {
      {
        val __v = seconds
        if (__v != 0L) {
          _output__.writeInt64(1, __v)
        }
      };
      {
        val __v = nanos
        if (__v != 0) {
          _output__.writeInt32(2, __v)
        }
      };
    }
    def mergeFrom(`_input__`: com.google.protobuf.CodedInputStream): com.google.protobuf.duration.Duration = {
      var __seconds = this.seconds
      var __nanos = this.nanos
      var _done__ = false
      while (!_done__) {
        val _tag__ = _input__.readTag()
        _tag__ match {
          case 0 => _done__ = true
          case 8 =>
            __seconds = _input__.readInt64()
          case 16 =>
            __nanos = _input__.readInt32()
          case tag => _input__.skipField(tag)
        }
      }
      com.google.protobuf.duration.Duration(
          seconds = __seconds,
          nanos = __nanos
      )
    }
    def withSeconds(__v: Long): Duration = copy(seconds = __v)
    def withNanos(__v: Int): Duration = copy(nanos = __v)
    def getField(__field: com.google.protobuf.Descriptors.FieldDescriptor): scala.Any = {
      __field.getNumber match {
        case 1 => {
          val __t = seconds
          if (__t != 0L) __t else null
        }
        case 2 => {
          val __t = nanos
          if (__t != 0) __t else null
        }
      }
    }
    override def toString: String = com.trueaccord.scalapb.TextFormat.printToUnicodeString(this)
    def companion = com.google.protobuf.duration.Duration
}

object Duration extends com.trueaccord.scalapb.GeneratedMessageCompanion[com.google.protobuf.duration.Duration] with com.trueaccord.scalapb.JavaProtoSupport[com.google.protobuf.duration.Duration, com.google.protobuf.Duration] {
  implicit def messageCompanion: com.trueaccord.scalapb.GeneratedMessageCompanion[com.google.protobuf.duration.Duration] with com.trueaccord.scalapb.JavaProtoSupport[com.google.protobuf.duration.Duration, com.google.protobuf.Duration] = this
  def toJavaProto(scalaPbSource: com.google.protobuf.duration.Duration): com.google.protobuf.Duration = {
    val javaPbOut = com.google.protobuf.Duration.newBuilder
    javaPbOut.setSeconds(scalaPbSource.seconds)
    javaPbOut.setNanos(scalaPbSource.nanos)
    javaPbOut.build
  }
  def fromJavaProto(javaPbSource: com.google.protobuf.Duration): com.google.protobuf.duration.Duration = com.google.protobuf.duration.Duration(
    seconds = javaPbSource.getSeconds.longValue,
    nanos = javaPbSource.getNanos.intValue
  )
  def fromFieldsMap(__fieldsMap: scala.collection.immutable.Map[com.google.protobuf.Descriptors.FieldDescriptor, scala.Any]): com.google.protobuf.duration.Duration = {
    require(__fieldsMap.keys.forall(_.getContainingType() == descriptor), "FieldDescriptor does not match message type.")
    val __fields = descriptor.getFields
    com.google.protobuf.duration.Duration(
      __fieldsMap.getOrElse(__fields.get(0), 0L).asInstanceOf[Long],
      __fieldsMap.getOrElse(__fields.get(1), 0).asInstanceOf[Int]
    )
  }
  def descriptor: com.google.protobuf.Descriptors.Descriptor = DurationProto.descriptor.getMessageTypes.get(0)
  def messageCompanionForField(__field: com.google.protobuf.Descriptors.FieldDescriptor): com.trueaccord.scalapb.GeneratedMessageCompanion[_] = throw new MatchError(__field)
  def enumCompanionForField(__field: com.google.protobuf.Descriptors.FieldDescriptor): com.trueaccord.scalapb.GeneratedEnumCompanion[_] = throw new MatchError(__field)
  lazy val defaultInstance = com.google.protobuf.duration.Duration(
  )
  implicit class DurationLens[UpperPB](_l: com.trueaccord.lenses.Lens[UpperPB, com.google.protobuf.duration.Duration]) extends com.trueaccord.lenses.ObjectLens[UpperPB, com.google.protobuf.duration.Duration](_l) {
    def seconds: com.trueaccord.lenses.Lens[UpperPB, Long] = field(_.seconds)((c_, f_) => c_.copy(seconds = f_))
    def nanos: com.trueaccord.lenses.Lens[UpperPB, Int] = field(_.nanos)((c_, f_) => c_.copy(nanos = f_))
  }
  final val SECONDS_FIELD_NUMBER = 1
  final val NANOS_FIELD_NUMBER = 2
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy