java.lang.Object
org.apache.avro.reflect.CustomEncoding<com.google.cloud.Timestamp>
org.apache.beam.sdk.io.gcp.spanner.changestreams.encoder.TimestampEncoding

public class TimestampEncoding extends CustomEncoding<com.google.cloud.Timestamp>
This encoder/decoder writes a com.google.cloud.Timestamp object as a pair of long and int to avro and reads a Timestamp object from the same pair. The long stores the number of seconds since January 1, 1970, 00:00:00 UTC. A negative value is the number of seconds before January 1, 1970, 00:00:00 UTC. The int stores the fractional seconds components, in the range 0..999999999.
  • Constructor Details

    • TimestampEncoding

      public TimestampEncoding()
  • Method Details

    • write

      protected void write(Object datum, Encoder out) throws IOException
      Serializes a Timestamp received as datum to the output encoder out. A null timestamp is serialized with negative fields (seconds and nanos).
      Specified by:
      write in class CustomEncoding<com.google.cloud.Timestamp>
      Parameters:
      datum - the Timestamp to be encoded
      out - the Encoder where the timestamp should be serialized to
      Throws:
      IOException - if it was not possible to write the timestamp into the provided encoder
    • read

      protected com.google.cloud.Timestamp read(Object reuse, Decoder in) throws IOException
      Deserializes a Timestamp from the given Decoder.
      Specified by:
      read in class CustomEncoding<com.google.cloud.Timestamp>
      Parameters:
      reuse - ignored
      in - the Decoder to read the timestamp fields from
      Returns:
      null if the fields are negative or an instance of a Timestamp instead.
      Throws:
      IOException - if it was not possible to read the timestamp from the provided decoder