CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-google-api-grpc--proto-google-common-protos

Java Protocol Buffer classes for Google's common protos, providing type-safe access to core Google Cloud API structures and gRPC service definitions

Pending
Overview
Eval results
Files

common-types.mddocs/

Common Data Types

Standard data types shared across Google APIs for representing time, money, geographic coordinates, and other common concepts. These types provide consistent representation and behavior across different services.

Temporal Types

Date

Calendar date representation (year, month, day).

class Date {
  int getYear();
  int getMonth();  // 1-12
  int getDay();    // 1-31
  
  static Date.Builder newBuilder();
  Date.Builder toBuilder();
  static Date parseFrom(byte[] data);
}

interface DateOrBuilder {
  int getYear();
  int getMonth();
  int getDay();
}

DateTime

Date and time with timezone information.

class DateTime {
  int getYear();
  int getMonth();
  int getDay();
  int getHours();
  int getMinutes();
  int getSeconds();
  int getNanos();
  TimeZone getTimeZone();
  Duration getUtcOffset();
  
  static DateTime.Builder newBuilder();
}

TimeOfDay

Time within a day (hour, minute, second, nanos).

class TimeOfDay {
  int getHours();    // 0-23
  int getMinutes();  // 0-59
  int getSeconds();  // 0-59
  int getNanos();    // 0-999,999,999
  
  static TimeOfDay.Builder newBuilder();
}

TimeZone

IANA timezone representation.

class TimeZone {
  String getId();      // e.g., "America/New_York"
  String getVersion();
  
  static TimeZone.Builder newBuilder();
}

Interval

Time interval with start and end times.

class Interval {
  Timestamp getStartTime();
  Timestamp getEndTime();
  
  static Interval.Builder newBuilder();
}

Monetary Types

Money

Monetary amount with currency code.

class Money {
  String getCurrencyCode();  // ISO 4217 currency code
  long getUnits();          // Whole units of currency
  int getNanos();           // Number of nano units (10^-9)
  
  static Money.Builder newBuilder();
  Money.Builder toBuilder();
}

interface MoneyOrBuilder {
  String getCurrencyCode();
  long getUnits();
  int getNanos();
}

Decimal

Arbitrary precision decimal number.

class Decimal {
  String getValue();  // String representation of decimal
  
  static Decimal.Builder newBuilder();
}

Fraction

Mathematical fraction with numerator and denominator.

class Fraction {
  long getNumerator();
  long getDenominator();
  
  static Fraction.Builder newBuilder();
}

Geographic Types

LatLng

Latitude/longitude coordinate pair.

class LatLng {
  double getLatitude();   // -90.0 to +90.0
  double getLongitude();  // -180.0 to +180.0
  
  static LatLng.Builder newBuilder();
}

PostalAddress

Structured postal address.

class PostalAddress {
  int getRevision();
  String getRegionCode();
  String getLanguageCode();
  String getPostalCode();
  String getSortingCode();
  String getAdministrativeArea();
  String getLocality();
  String getSublocality();
  repeated String getAddressLinesList();
  repeated String getRecipientsList();
  String getOrganization();
  
  static PostalAddress.Builder newBuilder();
}

Visual and UI Types

Color

Color representation supporting multiple formats.

class Color {
  float getRed();     // 0.0 to 1.0
  float getGreen();   // 0.0 to 1.0
  float getBlue();    // 0.0 to 1.0
  FloatValue getAlpha();  // Optional alpha channel
  
  static Color.Builder newBuilder();
}

LocalizedText

Text with language code for internationalization.

class LocalizedText {
  String getText();
  String getLanguageCode();  // BCP-47 language tag
  
  static LocalizedText.Builder newBuilder();
}

Utility Types

Expr

Expression for conditions and transformations using CEL (Common Expression Language).

class Expr {
  String getExpression();  // CEL expression
  String getTitle();
  String getDescription();
  String getLocation();
  
  static Expr.Builder newBuilder();
}

PhoneNumber

International phone number representation.

class PhoneNumber {
  string getE164Number();      // E.164 format (e.g., "+15551234567")
  ShortCode getShortCode();
  string getExtension();
  
  static PhoneNumber.Builder newBuilder();
}

class PhoneNumber.ShortCode {
  string getRegionCode();
  string getNumber();
  
  static ShortCode.Builder newBuilder();
}

Quaternion

3D rotation representation using quaternions.

class Quaternion {
  double getX();
  double getY();
  double getZ();
  double getW();
  
  static Quaternion.Builder newBuilder();
}

Calendar and Date Enums

DayOfWeek

Days of the week enumeration.

enum DayOfWeek {
  DAY_OF_WEEK_UNSPECIFIED(0),
  MONDAY(1),
  TUESDAY(2),
  WEDNESDAY(3),
  THURSDAY(4),
  FRIDAY(5),
  SATURDAY(6),
  SUNDAY(7);
  
  int getNumber();
  static DayOfWeek forNumber(int value);
}

Month

Calendar months enumeration.

enum Month {
  MONTH_UNSPECIFIED(0),
  JANUARY(1),
  FEBRUARY(2),
  MARCH(3),
  APRIL(4),
  MAY(5),
  JUNE(6),
  JULY(7),
  AUGUST(8),
  SEPTEMBER(9),
  OCTOBER(10),
  NOVEMBER(11),
  DECEMBER(12);
  
  int getNumber();
  static Month forNumber(int value);
}

CalendarPeriod

Calendar period types for recurring events.

enum CalendarPeriod {
  CALENDAR_PERIOD_UNSPECIFIED(0),
  DAY(1),
  WEEK(2),
  FORTNIGHT(3),
  MONTH(4),
  QUARTER(5),
  HALF(6),
  YEAR(7);
  
  int getNumber();
  static CalendarPeriod forNumber(int value);
}

Usage Examples

Working with Money

import com.google.type.Money;

// Create $29.99 USD
Money price = Money.newBuilder()
    .setCurrencyCode("USD")
    .setUnits(29)
    .setNanos(990000000)  // 0.99 * 10^9
    .build();

// Create €15.50 EUR
Money euroPrice = Money.newBuilder()
    .setCurrencyCode("EUR")
    .setUnits(15)
    .setNanos(500000000)  // 0.50 * 10^9
    .build();

// Convert to decimal representation
double priceAsDouble = price.getUnits() + (price.getNanos() / 1_000_000_000.0);
System.out.println("Price: " + price.getCurrencyCode() + " " + priceAsDouble);

Working with Dates and Times

import com.google.type.Date;
import com.google.type.TimeOfDay;
import com.google.type.DateTime;

// Create a date
Date birthday = Date.newBuilder()
    .setYear(1990)
    .setMonth(6)   // June
    .setDay(15)
    .build();

// Create a time
TimeOfDay meetingTime = TimeOfDay.newBuilder()
    .setHours(14)    // 2 PM
    .setMinutes(30)
    .setSeconds(0)
    .build();

// Create date and time together
DateTime appointment = DateTime.newBuilder()
    .setYear(2024)
    .setMonth(3)
    .setDay(15)
    .setHours(10)
    .setMinutes(30)
    .build();

Working with Geographic Coordinates

import com.google.type.LatLng;
import com.google.type.PostalAddress;

// Google headquarters coordinates
LatLng googleHQ = LatLng.newBuilder()
    .setLatitude(37.4220656)
    .setLongitude(-122.0840897)
    .build();

// Create postal address
PostalAddress address = PostalAddress.newBuilder()
    .setRegionCode("US")
    .setPostalCode("94043")
    .setAdministrativeArea("CA")
    .setLocality("Mountain View")
    .addAddressLines("1600 Amphitheatre Parkway")
    .addRecipients("Google LLC")
    .build();

Working with Colors

import com.google.type.Color;
import com.google.protobuf.FloatValue;

// Create red color
Color red = Color.newBuilder()
    .setRed(1.0f)
    .setGreen(0.0f)
    .setBlue(0.0f)
    .build();

// Create semi-transparent blue
Color transparentBlue = Color.newBuilder()
    .setRed(0.0f)
    .setGreen(0.0f)
    .setBlue(1.0f)
    .setAlpha(FloatValue.of(0.5f))  // 50% transparency
    .build();

Working with Expressions

import com.google.type.Expr;

// Create a CEL expression for access control
Expr accessCondition = Expr.newBuilder()
    .setExpression("request.auth.claims.email.endsWith('@company.com')")
    .setTitle("Company Email Required")
    .setDescription("Only users with company email addresses can access this resource")
    .build();

// Create a validation expression
Expr ageValidation = Expr.newBuilder()
    .setExpression("request.age >= 18 && request.age <= 120")
    .setTitle("Valid Age Range")
    .setDescription("Age must be between 18 and 120")
    .build();

Phone Number Handling

import com.google.type.PhoneNumber;

// Create E.164 format phone number
PhoneNumber phoneNumber = PhoneNumber.newBuilder()
    .setE164Number("+15551234567")
    .build();

// Create short code
PhoneNumber.ShortCode shortCode = PhoneNumber.ShortCode.newBuilder()
    .setRegionCode("US")
    .setNumber("12345")
    .build();

PhoneNumber shortPhoneNumber = PhoneNumber.newBuilder()
    .setShortCode(shortCode)
    .build();

Validation and Constraints

Money Validation

public boolean isValidMoney(Money money) {
    if (money.getCurrencyCode().isEmpty() || money.getCurrencyCode().length() != 3) {
        return false; // Invalid currency code
    }
    
    if (money.getNanos() < 0 || money.getNanos() >= 1_000_000_000) {
        return false; // Invalid nanos value
    }
    
    if (money.getUnits() < 0 && money.getNanos() > 0) {
        return false; // Sign mismatch
    }
    
    return true;
}

Date Validation

public boolean isValidDate(Date date) {
    if (date.getYear() < 1 || date.getMonth() < 1 || date.getMonth() > 12) {
        return false;
    }
    
    if (date.getDay() < 1 || date.getDay() > 31) {
        return false;
    }
    
    // Additional validation for days per month would go here
    return true;
}

Coordinate Validation

public boolean isValidLatLng(LatLng latLng) {
    double lat = latLng.getLatitude();
    double lng = latLng.getLongitude();
    
    return lat >= -90.0 && lat <= 90.0 && lng >= -180.0 && lng <= 180.0;
}

Conversion Utilities

Money to String

public String formatMoney(Money money) {
    double amount = money.getUnits() + (money.getNanos() / 1_000_000_000.0);
    return String.format("%s %.2f", money.getCurrencyCode(), amount);
}

public Money parseMoney(String currencyCode, double amount) {
    long units = (long) amount;
    int nanos = (int) ((amount - units) * 1_000_000_000);
    
    return Money.newBuilder()
        .setCurrencyCode(currencyCode)
        .setUnits(units)
        .setNanos(nanos)
        .build();
}

Date Conversion

import java.time.LocalDate;

public LocalDate toLocalDate(Date date) {
    return LocalDate.of(date.getYear(), date.getMonth(), date.getDay());
}

public Date fromLocalDate(LocalDate localDate) {
    return Date.newBuilder()
        .setYear(localDate.getYear())
        .setMonth(localDate.getMonthValue())
        .setDay(localDate.getDayOfMonth())
        .build();
}

Install with Tessl CLI

npx tessl i tessl/maven-com-google-api-grpc--proto-google-common-protos

docs

api-infrastructure.md

apps-cards.md

cloud-platform.md

common-types.md

index.md

longrunning-operations.md

rpc-status.md

tile.json