Esempio n. 1
0
        private static bool TryReadSingleGuid(this ProtoBufferReader reader, out Guid value)
        {
            value = default;

            if (!reader.TryReadLength(out var length))
            {
                return(false);
            }

            var endPosition = reader.Position + length;

            while (reader.Position < endPosition && reader.TryReadTag(out var number, out var wireType))
            {
                switch (number)
                {
                case 1:
                    if (!reader.TryReadGuid(out value))
                    {
                        return(false);
                    }
                    break;

                default:
                    if (!reader.TrySkipUnknown(wireType))
                    {
                        return(false);
                    }
                    break;
                }
            }

            return(true);
        }
Esempio n. 2
0
        private static bool TryReadOriginatorInfo(this ProtoBufferReader reader, out OriginatorInfo?originatorInfo)
        {
            originatorInfo = default;

            if (!reader.TryReadLength(out var length))
            {
                return(false);
            }

            var endPosition = reader.Position + length;

            var    senderId          = new PeerId();
            string?senderEndPoint    = null;
            string?initiatorUserName = null;

            while (reader.Position < endPosition && reader.TryReadTag(out var number, out var wireType))
            {
                switch (number)
                {
                case 1:
                    if (!reader.TryReadSingleString(out var peerId))
                    {
                        return(false);
                    }
                    senderId = new PeerId(peerId);
                    break;

                case 2:
                    if (!reader.TryReadString(out senderEndPoint))
                    {
                        return(false);
                    }
                    break;

                case 5:
                    if (!reader.TryReadString(out initiatorUserName))
                    {
                        return(false);
                    }
                    break;

                default:
                    if (!reader.TrySkipUnknown(wireType))
                    {
                        return(false);
                    }
                    break;
                }
            }

            originatorInfo = new OriginatorInfo(senderId, senderEndPoint !, null, initiatorUserName);
            return(true);
        }
Esempio n. 3
0
        private static bool TryReadMember(this ProtoBufferReader reader, TransportMessage transportMessage)
        {
            if (!reader.TryReadTag(out var number, out var wireType))
            {
                return(false);
            }

            switch (number)
            {
            case 1:
                if (!reader.TryReadSingleGuid(out var id))
                {
                    return(false);
                }
                transportMessage.Id = new MessageId(id);
                break;

            case 2:
                if (!reader.TryReadSingleString(out var messageTypeId))
                {
                    return(false);
                }
                transportMessage.MessageTypeId = new MessageTypeId(messageTypeId);
                break;

            case 3:
                if (!reader.TryReadStream(out var content))
                {
                    return(false);
                }
                transportMessage.Content = content;
                break;

            case 4:
                if (!reader.TryReadOriginatorInfo(out var originator) || originator == null)
                {
                    return(false);
                }
                transportMessage.Originator = originator;
                break;

            case 5:
                if (!reader.TryReadString(out var environment))
                {
                    return(false);
                }
                transportMessage.Environment = environment;
                break;

            case 6:
                if (!reader.TryReadBool(out var wasPersisted))
                {
                    return(false);
                }
                transportMessage.WasPersisted = wasPersisted;
                break;

            case 7:
                if (!reader.TryReadSingleString(out var persistentPeerId))
                {
                    return(false);
                }
                transportMessage.PersistentPeerIds ??= new List <PeerId>();
                transportMessage.PersistentPeerIds.Add(new PeerId(persistentPeerId));
                break;

            default:
                if (!reader.TrySkipUnknown(wireType))
                {
                    return(false);
                }
                break;
            }

            return(true);
        }