Esempio n. 1
0
        public static SignalServiceAddress FromProtobuf(AddressProto addressProto)
        {
            Guid?  uuid   = addressProto.HasUuid ? UuidUtil.ParseOrThrow(addressProto.Uuid.ToByteArray()) : (Guid?)null;
            string?number = addressProto.HasE164 ? addressProto.E164 : null;
            string?relay  = addressProto.HasRelay ? addressProto.Relay : null;

            return(new SignalServiceAddress(uuid, number, relay));
        }
        public void Serialize_And_Deserialize_E164_Address()
        {
            SignalServiceAddress address      = new SignalServiceAddress(null, "+15552345678", null);
            AddressProto         addressProto = SignalServiceAddressProtobufSerializer.ToProtobuf(address);
            SignalServiceAddress deserialized = SignalServiceAddressProtobufSerializer.FromProtobuf(addressProto);

            Assert.AreEqual(address, deserialized);
        }
        public void Serialize_And_Deserialize_Both_Address_With_Relay()
        {
            SignalServiceAddress address      = new SignalServiceAddress(Guid.NewGuid(), "+15552345678", "relay");
            AddressProto         addressProto = SignalServiceAddressProtobufSerializer.ToProtobuf(address);
            SignalServiceAddress deserialized = SignalServiceAddressProtobufSerializer.FromProtobuf(addressProto);

            Assert.AreEqual(address, deserialized);
        }
        public void Serialize_And_Deserialize_Uuid_Address()
        {
            SignalServiceAddress address      = new SignalServiceAddress(Guid.NewGuid(), null, null);
            AddressProto         addressProto = SignalServiceAddressProtobufSerializer.ToProtobuf(address);
            SignalServiceAddress deserialized = SignalServiceAddressProtobufSerializer.FromProtobuf(addressProto);

            Assert.AreEqual(address, deserialized);
        }
Esempio n. 5
0
        public static AddressProto ToProtobuf(SignalServiceAddress signalServiceAddress)
        {
            AddressProto builder = new AddressProto();

            if (signalServiceAddress.GetNumber() != null)
            {
                builder.E164 = signalServiceAddress.E164;
            }
            if (signalServiceAddress.Uuid.HasValue)
            {
                builder.Uuid = ByteString.CopyFrom(UuidUtil.ToByteArray(signalServiceAddress.Uuid.Value));
            }
            if (signalServiceAddress.Relay != null)
            {
                builder.Relay = signalServiceAddress.Relay;
            }
            return(builder);
        }