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

org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer.kt Maven / Gradle / Ivy

There is a newer version: 2.15.3_unofficial_107
Show newest version
package org.whispersystems.signalservice.internal.serialize

import org.whispersystems.signalservice.api.push.ServiceId.Companion.parseOrThrow
import org.whispersystems.signalservice.api.push.SignalServiceAddress
import org.whispersystems.signalservice.internal.serialize.protos.AddressProto
import java.util.Optional

object SignalServiceAddressProtobufSerializer {
  @JvmStatic
  fun toProtobuf(signalServiceAddress: SignalServiceAddress): AddressProto {
    val builder = AddressProto.Builder()
    builder.uuid(signalServiceAddress.serviceId.toByteString())
    if (signalServiceAddress.number.isPresent) {
      builder.e164(signalServiceAddress.number.get())
    }
    return builder.build()
  }

  @JvmStatic
  fun fromProtobuf(addressProto: AddressProto): SignalServiceAddress {
    if (addressProto.uuid == null) {
      throw IllegalArgumentException("Missing ServiceId!")
    }
    val serviceId = parseOrThrow(
      addressProto.uuid.toByteArray()
    )
    val number = Optional.ofNullable(addressProto.e164)
    return SignalServiceAddress(serviceId, number)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy