Standard protocol buffer types including timestamps, durations, Any messages, and wrapper types for primitives. These are commonly used types that provide standard solutions for common data representation needs in the shaded akka.protobufv3.internal package.
Represents a point in time independent of time zones or calendars. Useful for recording when events occurred.
/**
* Represents a point in time independent of any time zone or calendar.
* Precision is in nanoseconds with seconds since Unix epoch.
*/
class Timestamp implements Message {
/** Get seconds since Unix epoch */
long getSeconds();
/** Get nanoseconds adjustment (0-999,999,999) */
int getNanos();
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing timestamp */
static Builder newBuilder(Timestamp prototype);
/** Parse from byte array */
static Timestamp parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Parse from ByteString */
static Timestamp parseFrom(ByteString data) throws InvalidProtocolBufferException;
/** Parse from CodedInputStream */
static Timestamp parseFrom(CodedInputStream input) throws IOException;
/** Get default instance */
static Timestamp getDefaultInstance();
/** Create builder for this message */
Builder newBuilderForType();
/** Create builder with this message's contents */
Builder toBuilder();
/** Timestamp builder */
static class Builder implements Message.Builder {
/** Get seconds value */
long getSeconds();
/** Set seconds value */
Builder setSeconds(long value);
/** Clear seconds field */
Builder clearSeconds();
/** Get nanos value */
int getNanos();
/** Set nanos value */
Builder setNanos(int value);
/** Clear nanos field */
Builder clearNanos();
/** Build the timestamp */
Timestamp build();
/** Build partial timestamp */
Timestamp buildPartial();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another timestamp */
Builder mergeFrom(Timestamp other);
}
}Represents a span of time with seconds and nanoseconds precision. Useful for timeouts, delays, and elapsed time measurements.
/**
* Represents a signed span of time between two timestamps.
* Can be negative to represent time going backwards.
*/
class Duration implements Message {
/** Get seconds component */
long getSeconds();
/** Get nanoseconds component (can be negative) */
int getNanos();
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing duration */
static Builder newBuilder(Duration prototype);
/** Parse from byte array */
static Duration parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Parse from ByteString */
static Duration parseFrom(ByteString data) throws InvalidProtocolBufferException;
/** Parse from CodedInputStream */
static Duration parseFrom(CodedInputStream input) throws IOException;
/** Get default instance */
static Duration getDefaultInstance();
/** Create builder for this message */
Builder newBuilderForType();
/** Create builder with this message's contents */
Builder toBuilder();
/** Duration builder */
static class Builder implements Message.Builder {
/** Get seconds value */
long getSeconds();
/** Set seconds value */
Builder setSeconds(long value);
/** Clear seconds field */
Builder clearSeconds();
/** Get nanos value */
int getNanos();
/** Set nanos value */
Builder setNanos(int value);
/** Clear nanos field */
Builder clearNanos();
/** Build the duration */
Duration build();
/** Build partial duration */
Duration buildPartial();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another duration */
Builder mergeFrom(Duration other);
}
}Contains an arbitrary serialized protocol buffer message along with a URL that describes the type. Enables polymorphic message handling.
/**
* Contains an arbitrary serialized protocol buffer message along with a URL
* that describes the type of the serialized message.
*/
class Any implements Message {
/** Get type URL identifying the message type */
String getTypeUrl();
/** Get serialized message bytes */
ByteString getValue();
/** Check if this Any contains a message of the given type */
static <T extends Message> boolean is(Any any, Class<T> clazz);
/** Unpack the Any to the specified message type */
<T extends Message> T unpack(Class<T> clazz)
throws InvalidProtocolBufferException;
/** Pack a message into an Any */
static Any pack(Message message);
/** Pack a message with custom type URL prefix */
static Any pack(Message message, String typeUrlPrefix);
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing Any */
static Builder newBuilder(Any prototype);
/** Parse from byte array */
static Any parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Parse from ByteString */
static Any parseFrom(ByteString data) throws InvalidProtocolBufferException;
/** Parse from CodedInputStream */
static Any parseFrom(CodedInputStream input) throws IOException;
/** Get default instance */
static Any getDefaultInstance();
/** Any builder */
static class Builder implements Message.Builder {
/** Get type URL */
String getTypeUrl();
/** Set type URL */
Builder setTypeUrl(String value);
/** Clear type URL */
Builder clearTypeUrl();
/** Get value bytes */
ByteString getValue();
/** Set value bytes */
Builder setValue(ByteString value);
/** Clear value */
Builder clearValue();
/** Build the Any */
Any build();
/** Build partial Any */
Any buildPartial();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another Any */
Builder mergeFrom(Any other);
}
}Represents a structured data object consisting of fields with dynamic values. Similar to a JSON object.
/**
* Represents a structured data object, equivalent to a JSON object.
* Consists of a collection of name/value pairs.
*/
class Struct implements Message {
/** Get all fields in the struct */
Map<String, Value> getFieldsMap();
/** Get number of fields */
int getFieldsCount();
/** Check if field exists */
boolean containsFields(String key);
/** Get field value */
Value getFieldsOrDefault(String key, Value defaultValue);
/** Get field value or throw exception */
Value getFieldsOrThrow(String key);
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing struct */
static Builder newBuilder(Struct prototype);
/** Parse from byte array */
static Struct parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Parse from ByteString */
static Struct parseFrom(ByteString data) throws InvalidProtocolBufferException;
/** Get default instance */
static Struct getDefaultInstance();
/** Struct builder */
static class Builder implements Message.Builder {
/** Get mutable fields map */
Map<String, Value> getMutableFields();
/** Put field value */
Builder putFields(String key, Value value);
/** Put all fields from map */
Builder putAllFields(Map<String, Value> values);
/** Remove field */
Builder removeFields(String key);
/** Clear all fields */
Builder clearFields();
/** Build the struct */
Struct build();
/** Build partial struct */
Struct buildPartial();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another struct */
Builder mergeFrom(Struct other);
}
}Represents a dynamically typed value which can be null, number, string, boolean, struct, or list.
/**
* Represents a dynamically typed value which can hold various types
* including null, number, string, boolean, struct, or list of values.
*/
class Value implements Message {
/** Get the kind of value stored */
KindCase getKindCase();
/** Check if value is null */
boolean hasNullValue();
/** Get null value */
NullValue getNullValue();
/** Check if value is number */
boolean hasNumberValue();
/** Get number value */
double getNumberValue();
/** Check if value is string */
boolean hasStringValue();
/** Get string value */
String getStringValue();
/** Check if value is boolean */
boolean hasBoolValue();
/** Get boolean value */
boolean getBoolValue();
/** Check if value is struct */
boolean hasStructValue();
/** Get struct value */
Struct getStructValue();
/** Check if value is list */
boolean hasListValue();
/** Get list value */
ListValue getListValue();
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing value */
static Builder newBuilder(Value prototype);
/** Parse from byte array */
static Value parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Get default instance */
static Value getDefaultInstance();
/** Value kind enumeration */
enum KindCase {
NULL_VALUE(1),
NUMBER_VALUE(2),
STRING_VALUE(3),
BOOL_VALUE(4),
STRUCT_VALUE(5),
LIST_VALUE(6),
KIND_NOT_SET(0);
/** Get field number */
int getNumber();
}
/** Value builder */
static class Builder implements Message.Builder {
/** Set null value */
Builder setNullValue(NullValue value);
/** Set number value */
Builder setNumberValue(double value);
/** Set string value */
Builder setStringValue(String value);
/** Set boolean value */
Builder setBoolValue(boolean value);
/** Set struct value */
Builder setStructValue(Struct value);
/** Set struct value from builder */
Builder setStructValue(Struct.Builder builderForValue);
/** Set list value */
Builder setListValue(ListValue value);
/** Set list value from builder */
Builder setListValue(ListValue.Builder builderForValue);
/** Clear kind */
Builder clearKind();
/** Build the value */
Value build();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another value */
Builder mergeFrom(Value other);
}
}Represents a repeated Value, equivalent to a JSON array.
/**
* Represents a repeated Value, equivalent to a JSON array.
* Contains an ordered list of dynamically typed values.
*/
class ListValue implements Message {
/** Get all values in the list */
List<Value> getValuesList();
/** Get value at specific index */
Value getValues(int index);
/** Get number of values */
int getValuesCount();
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing list */
static Builder newBuilder(ListValue prototype);
/** Parse from byte array */
static ListValue parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Get default instance */
static ListValue getDefaultInstance();
/** ListValue builder */
static class Builder implements Message.Builder {
/** Get mutable values list */
List<Value> getValuesList();
/** Get value at index */
Value getValues(int index);
/** Set value at index */
Builder setValues(int index, Value value);
/** Set value at index from builder */
Builder setValues(int index, Value.Builder builderForValue);
/** Add value to end */
Builder addValues(Value value);
/** Add value from builder */
Builder addValues(Value.Builder builderForValue);
/** Add all values from collection */
Builder addAllValues(Iterable<? extends Value> values);
/** Clear all values */
Builder clearValues();
/** Remove value at index */
Builder removeValues(int index);
/** Build the list value */
ListValue build();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another list value */
Builder mergeFrom(ListValue other);
}
}Generic empty message that can be used in APIs that need a message but have no content.
/**
* Generic empty message that is useful for APIs that need a message
* but have no actual content to convey.
*/
class Empty implements Message {
/** Create new builder */
static Builder newBuilder();
/** Parse from byte array */
static Empty parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Get default instance */
static Empty getDefaultInstance();
/** Empty builder */
static class Builder implements Message.Builder {
/** Build the empty message */
Empty build();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another empty */
Builder mergeFrom(Empty other);
}
}Represents a set of symbolic field paths for use in update operations and field projection.
/**
* Represents a set of symbolic field paths, for example:
* paths: ["f.a", "f.b.d"]
* Used to specify which fields should be updated or returned.
*/
class FieldMask implements Message {
/** Get all field paths */
List<String> getPathsList();
/** Get path at specific index */
String getPaths(int index);
/** Get number of paths */
int getPathsCount();
/** Create new builder */
static Builder newBuilder();
/** Create builder from existing field mask */
static Builder newBuilder(FieldMask prototype);
/** Parse from byte array */
static FieldMask parseFrom(byte[] data) throws InvalidProtocolBufferException;
/** Get default instance */
static FieldMask getDefaultInstance();
/** FieldMask builder */
static class Builder implements Message.Builder {
/** Get mutable paths list */
List<String> getPathsList();
/** Get path at index */
String getPaths(int index);
/** Set path at index */
Builder setPaths(int index, String value);
/** Add path to end */
Builder addPaths(String value);
/** Add all paths from collection */
Builder addAllPaths(Iterable<String> values);
/** Clear all paths */
Builder clearPaths();
/** Build the field mask */
FieldMask build();
/** Clone this builder */
Builder clone();
/** Clear all fields */
Builder clear();
/** Merge from another field mask */
Builder mergeFrom(FieldMask other);
}
}Wrapper messages for primitive types, useful for distinguishing between zero values and unset values.
/**
* Wrapper message for double.
* Enables distinction between 0.0 and unset value.
*/
class DoubleValue implements Message {
/** Get the double value */
double getValue();
/** Create from primitive value */
static DoubleValue of(double value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static DoubleValue getDefaultInstance();
}
/**
* Wrapper message for float.
* Enables distinction between 0.0f and unset value.
*/
class FloatValue implements Message {
/** Get the float value */
float getValue();
/** Create from primitive value */
static FloatValue of(float value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static FloatValue getDefaultInstance();
}
/**
* Wrapper message for int64.
* Enables distinction between 0L and unset value.
*/
class Int64Value implements Message {
/** Get the long value */
long getValue();
/** Create from primitive value */
static Int64Value of(long value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static Int64Value getDefaultInstance();
}
/**
* Wrapper message for uint64.
* Enables distinction between 0L and unset value.
*/
class UInt64Value implements Message {
/** Get the long value */
long getValue();
/** Create from primitive value */
static UInt64Value of(long value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static UInt64Value getDefaultInstance();
}
/**
* Wrapper message for int32.
* Enables distinction between 0 and unset value.
*/
class Int32Value implements Message {
/** Get the int value */
int getValue();
/** Create from primitive value */
static Int32Value of(int value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static Int32Value getDefaultInstance();
}
/**
* Wrapper message for uint32.
* Enables distinction between 0 and unset value.
*/
class UInt32Value implements Message {
/** Get the int value */
int getValue();
/** Create from primitive value */
static UInt32Value of(int value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static UInt32Value getDefaultInstance();
}
/**
* Wrapper message for bool.
* Enables distinction between false and unset value.
*/
class BoolValue implements Message {
/** Get the boolean value */
boolean getValue();
/** Create from primitive value */
static BoolValue of(boolean value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static BoolValue getDefaultInstance();
}
/**
* Wrapper message for string.
* Enables distinction between empty string and unset value.
*/
class StringValue implements Message {
/** Get the string value */
String getValue();
/** Create from string value */
static StringValue of(String value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static StringValue getDefaultInstance();
}
/**
* Wrapper message for bytes.
* Enables distinction between empty bytes and unset value.
*/
class BytesValue implements Message {
/** Get the ByteString value */
ByteString getValue();
/** Create from ByteString value */
static BytesValue of(ByteString value);
/** Create new builder */
static Builder newBuilder();
/** Get default instance */
static BytesValue getDefaultInstance();
}Represents a null value, used in Value messages to indicate the absence of a value.
/**
* Represents JSON null value.
* Used in Value messages to explicitly represent null.
*/
enum NullValue {
/** The JSON null value */
NULL_VALUE(0);
/** Get the numeric value */
int getNumber();
/** Get enum value from number */
static NullValue valueOf(int value);
/** Get enum value from descriptor */
static NullValue valueOf(Descriptors.EnumValueDescriptor desc);
/** Get the descriptor for this enum */
static Descriptors.EnumDescriptor getDescriptor();
/** Get the descriptor for this value */
Descriptors.EnumValueDescriptor getValueDescriptor();
}import akka.protobufv3.internal.*;
// Create timestamp for current time
long currentSeconds = System.currentTimeMillis() / 1000;
int nanos = (int) ((System.currentTimeMillis() % 1000) * 1000000);
Timestamp timestamp = Timestamp.newBuilder()
.setSeconds(currentSeconds)
.setNanos(nanos)
.build();
// Read timestamp values
long seconds = timestamp.getSeconds();
int nanoseconds = timestamp.getNanos();
// Convert to milliseconds
long millis = seconds * 1000 + nanoseconds / 1000000;import akka.protobufv3.internal.*;
// Create 5 second duration
Duration fiveSeconds = Duration.newBuilder()
.setSeconds(5)
.setNanos(0)
.build();
// Create 1.5 second duration
Duration oneAndHalf = Duration.newBuilder()
.setSeconds(1)
.setNanos(500_000_000)
.build();
// Read duration
long durationSeconds = fiveSeconds.getSeconds();
int durationNanos = fiveSeconds.getNanos();import akka.protobufv3.internal.*;
// Pack a message into Any (assumes MyMessage exists)
// MyMessage original = MyMessage.newBuilder()
// .setName("example")
// .setId(123)
// .build();
// Any anyMessage = Any.pack(original);
// Check if Any contains specific type
// boolean isMyMessage = Any.is(anyMessage, MyMessage.class);
// Unpack the Any
// if (isMyMessage) {
// MyMessage unpacked = anyMessage.unpack(MyMessage.class);
// System.out.println("Unpacked: " + unpacked.getName());
// }import akka.protobufv3.internal.*;
// Create a struct with various value types
Struct struct = Struct.newBuilder()
.putFields("name", Value.newBuilder()
.setStringValue("John Doe")
.build())
.putFields("age", Value.newBuilder()
.setNumberValue(30)
.build())
.putFields("active", Value.newBuilder()
.setBoolValue(true)
.build())
.putFields("metadata", Value.newBuilder()
.setNullValue(NullValue.NULL_VALUE)
.build())
.build();
// Read struct values
Value nameValue = struct.getFieldsOrThrow("name");
if (nameValue.hasStringValue()) {
String name = nameValue.getStringValue();
System.out.println("Name: " + name);
}
Value ageValue = struct.getFieldsOrThrow("age");
if (ageValue.hasNumberValue()) {
double age = ageValue.getNumberValue();
System.out.println("Age: " + age);
}import akka.protobufv3.internal.*;
// Create a list of mixed values
ListValue list = ListValue.newBuilder()
.addValues(Value.newBuilder().setStringValue("hello").build())
.addValues(Value.newBuilder().setNumberValue(42).build())
.addValues(Value.newBuilder().setBoolValue(true).build())
.build();
// Iterate over values
for (Value value : list.getValuesList()) {
switch (value.getKindCase()) {
case STRING_VALUE:
System.out.println("String: " + value.getStringValue());
break;
case NUMBER_VALUE:
System.out.println("Number: " + value.getNumberValue());
break;
case BOOL_VALUE:
System.out.println("Boolean: " + value.getBoolValue());
break;
default:
System.out.println("Other type: " + value.getKindCase());
}
}import akka.protobufv3.internal.*;
// Create wrapper values
StringValue name = StringValue.of("John");
Int32Value age = Int32Value.of(30);
BoolValue active = BoolValue.of(true);
// Use in message (assumes a message with wrapper fields exists)
// UserProfile profile = UserProfile.newBuilder()
// .setName(name)
// .setAge(age)
// .setActive(active)
// .build();
// Check if wrapper fields are set vs default values
// if (profile.hasName()) {
// String nameStr = profile.getName().getValue();
// }