public final class Duration extends GeneratedMessageLite<Duration,Duration.Builder> implements DurationOrBuilder
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; }Protobuf type
google.protobuf.Duration
Modifier and Type | Class and Description |
---|---|
static class |
Duration.Builder
A Duration represents a signed, fixed-length span of time represented
as a count of seconds and fractions of seconds at nanosecond
resolution.
|
GeneratedMessageLite.DefaultInstanceBasedParser<T extends GeneratedMessageLite<T,?>>, GeneratedMessageLite.ExtendableBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>, GeneratedMessageLite.ExtendableMessage<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>, GeneratedMessageLite.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>, GeneratedMessageLite.GeneratedExtension<ContainingType extends MessageLite,Type>, GeneratedMessageLite.MergeFromVisitor, GeneratedMessageLite.MethodToInvoke, GeneratedMessageLite.SerializedForm, GeneratedMessageLite.Visitor
Modifier and Type | Field and Description |
---|---|
static int |
NANOS_FIELD_NUMBER |
static int |
SECONDS_FIELD_NUMBER |
memoizedSerializedSize, unknownFields
memoizedHashCode
Modifier and Type | Method and Description |
---|---|
protected Object |
dynamicMethod(GeneratedMessageLite.MethodToInvoke method,
Object arg0,
Object arg1)
A method that implements different types of operations described in
GeneratedMessageLite.MethodToInvoke . |
static Duration |
getDefaultInstance() |
int |
getNanos()
Signed fractions of a second at nanosecond resolution of the span
of time.
|
long |
getSeconds()
Signed seconds of the span of time.
|
int |
getSerializedSize()
Get the number of bytes required to encode this message.
|
static Duration.Builder |
newBuilder() |
static Duration.Builder |
newBuilder(Duration prototype) |
static Duration |
parseDelimitedFrom(InputStream input) |
static Duration |
parseDelimitedFrom(InputStream input,
ExtensionRegistryLite extensionRegistry) |
static Duration |
parseFrom(byte[] data) |
static Duration |
parseFrom(byte[] data,
ExtensionRegistryLite extensionRegistry) |
static Duration |
parseFrom(ByteString data) |
static Duration |
parseFrom(ByteString data,
ExtensionRegistryLite extensionRegistry) |
static Duration |
parseFrom(CodedInputStream input) |
static Duration |
parseFrom(CodedInputStream input,
ExtensionRegistryLite extensionRegistry) |
static Duration |
parseFrom(InputStream input) |
static Duration |
parseFrom(InputStream input,
ExtensionRegistryLite extensionRegistry) |
static Parser<Duration> |
parser() |
void |
writeTo(CodedOutputStream output)
Serializes the message and writes it to
output . |
dynamicMethod, dynamicMethod, emptyBooleanList, emptyDoubleList, emptyFloatList, emptyIntList, emptyLongList, emptyProtobufList, equals, getDefaultInstanceForType, getParserForType, hashCode, isInitialized, isInitialized, makeImmutable, makeImmutable, mergeLengthDelimitedField, mergeUnknownFields, mergeVarintField, mutableCopy, mutableCopy, mutableCopy, mutableCopy, mutableCopy, mutableCopy, newBuilderForType, newRepeatedGeneratedExtension, newSingularGeneratedExtension, parseDelimitedFrom, parseDelimitedFrom, parseFrom, parseFrom, parseFrom, parseFrom, parseFrom, parseFrom, parseFrom, parseFrom, parsePartialFrom, parseUnknownField, toBuilder, toString
addAll, checkByteStringIsUtf8, toByteArray, toByteString, writeDelimitedTo, writeTo
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getDefaultInstanceForType, isInitialized
public static final int SECONDS_FIELD_NUMBER
public static final int NANOS_FIELD_NUMBER
public long getSeconds()
Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive.
optional int64 seconds = 1;
getSeconds
in interface DurationOrBuilder
public int getNanos()
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.
optional int32 nanos = 2;
getNanos
in interface DurationOrBuilder
public void writeTo(CodedOutputStream output) throws IOException
MessageLite
output
. This does not
flush or close the stream.writeTo
in interface MessageLite
IOException
public int getSerializedSize()
MessageLite
getSerializedSize
in interface MessageLite
public static Duration parseFrom(ByteString data) throws InvalidProtocolBufferException
InvalidProtocolBufferException
public static Duration parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException
InvalidProtocolBufferException
public static Duration parseFrom(byte[] data) throws InvalidProtocolBufferException
InvalidProtocolBufferException
public static Duration parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException
InvalidProtocolBufferException
public static Duration parseFrom(InputStream input) throws IOException
IOException
public static Duration parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException
IOException
public static Duration parseDelimitedFrom(InputStream input) throws IOException
IOException
public static Duration parseDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException
IOException
public static Duration parseFrom(CodedInputStream input) throws IOException
IOException
public static Duration parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException
IOException
public static Duration.Builder newBuilder()
public static Duration.Builder newBuilder(Duration prototype)
protected final Object dynamicMethod(GeneratedMessageLite.MethodToInvoke method, Object arg0, Object arg1)
GeneratedMessageLite
GeneratedMessageLite.MethodToInvoke
.
Theses different kinds of operations are required to implement message-level operations for
builders in the runtime. This method bundles those operations to reduce the generated methods
count.
MERGE_FROM_STREAM
is parameterized with an CodedInputStream
and
ExtensionRegistryLite
. It consumes the input stream, parsing the contents into the
returned protocol buffer. If parsing throws an InvalidProtocolBufferException
, the
implementation wraps it in a RuntimeException.
NEW_INSTANCE
returns a new instance of the protocol buffer that has not yet been
made immutable. See MAKE_IMMUTABLE
.
IS_INITIALIZED
is parameterized with a Boolean
detailing whether to
memoize. It returns null
for false and the default instance for true. We optionally
memoize to support the Builder case, where memoization is not desired.
NEW_BUILDER
returns a BuilderType
instance.
VISIT
is parameterized with a Visitor
and a MessageType
and
recursively iterates through the fields side by side between this and the instance.
MAKE_IMMUTABLE
sets all internal fields to an immutable state.
For use by generated code only.
dynamicMethod
in class GeneratedMessageLite<Duration,Duration.Builder>
public static Duration getDefaultInstance()
Copyright © 2008–2016 Google. All rights reserved.