コード例 #1
0
        public DeserializationState ReadValue(ReadOnlySpan <byte> data, DeserializationSession session)
        {
            if (session.ParsedValue.Uri != null)
            {
                throw new DeserializationException("No more than one URI field is allowed per session description");
            }

            if (session.ParsedValue.MediaDescriptions != null && session.ParsedValue.MediaDescriptions.Any())
            {
                throw new DeserializationException($"Uri MUST be specified before the first media field");
            }

            var remainingSlice = data;

            //header
            SerializationHelpers.ParseRequiredHeader("Uri field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            //uri
            var uriString =
                SerializationHelpers.ParseRequiredString("Uri field",
                                                         SerializationHelpers.NextRequiredField("Uri field", remainingSlice));

            if (Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out var parsedUri))
            {
                session.ParsedValue.Uri = parsedUri;
            }
            else
            {
                throw new DeserializationException($"Invalid Uri field value: {uriString}");
            }

            return(OptionalValueDeSerializer.Instance.ReadValue);
        }
コード例 #2
0
        public EncriptionKey ReadValue(ReadOnlySpan <byte> data)
        {
            var remainingSlice = data;

            //header
            SerializationHelpers.ParseRequiredHeader("Encription key field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            var encKey = new EncriptionKey();

            // Type
            var indexOfEnd = remainingSlice.IndexOf(SDPSerializer.ByteColon);

            // Only method must be present
            if (indexOfEnd == -1)
            {
                encKey.Method = SerializationHelpers.ParseRequiredString("Encription key field: method", remainingSlice);
                return(encKey);
            }
            else
            {
                encKey.Method = SerializationHelpers.ParseRequiredString("Encription key field: method", remainingSlice.Slice(0, indexOfEnd));
                encKey.Value  = SerializationHelpers.ParseRequiredString("Encription key field: value", remainingSlice.Slice(indexOfEnd + 1));
            }

            return(encKey);
        }
コード例 #3
0
        public ConnectionData ReadValue(ReadOnlySpan <byte> data)
        {
            var remainingSlice = data;

            // header
            SerializationHelpers.ParseRequiredHeader("Connection Data field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            var connData = new ConnectionData();

            // nettype
            connData.Nettype =
                SerializationHelpers.ParseRequiredString("Connection Data field: nettype",
                                                         SerializationHelpers.NextRequiredDelimitedField("Connection Data field: nettype", SDPSerializer.ByteSpace, remainingSlice, out var consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // addrtype
            connData.AddrType =
                SerializationHelpers.ParseRequiredString("Connection Data field: addrtype",
                                                         SerializationHelpers.NextRequiredDelimitedField("Connection Data field: addrtype", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // connection-address
            connData.ConnectionAddress =
                SerializationHelpers.ParseRequiredString("Connection Data field: connection-address", remainingSlice);

            return(connData);
        }
コード例 #4
0
        public string ReadValue(ReadOnlySpan <byte> data)
        {
            var remainingSlice = data;

            //header
            SerializationHelpers.ParseRequiredHeader("Attribute field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            var value = SerializationHelpers.ParseRequiredString("Attribute field", remainingSlice);

            return(value);
        }
コード例 #5
0
        public DeserializationState ReadValue(ReadOnlySpan <byte> data, DeserializationSession session)
        {
            var remainingSlice = data;

            //header
            SerializationHelpers.ParseRequiredHeader("Origin field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            session.ParsedValue.Origin = new Origin();

            //username
            session.ParsedValue.Origin.UserName =
                SerializationHelpers.ParseRequiredString("Origin field: username",
                                                         SerializationHelpers.NextRequiredDelimitedField("Origin field: username", SDPSerializer.ByteSpace, remainingSlice, out var consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            //sess-id
            session.ParsedValue.Origin.SessionId = SerializationHelpers.ParseLong("Origin field: sess-id",
                                                                                  SerializationHelpers.NextRequiredDelimitedField("Origin field: sess-id", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            //sess-version
            session.ParsedValue.Origin.SessionVersion = SerializationHelpers.ParseLong("Origin field: sess-version",
                                                                                       SerializationHelpers.NextRequiredDelimitedField("Origin field: sess-version", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            //nettype
            session.ParsedValue.Origin.Nettype =
                SerializationHelpers.ParseRequiredString("Origin field: nettype",
                                                         SerializationHelpers.NextRequiredDelimitedField("Origin field: nettype", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            //addrtype
            session.ParsedValue.Origin.AddrType =
                SerializationHelpers.ParseRequiredString("Origin field: addrtype",
                                                         SerializationHelpers.NextRequiredDelimitedField("Origin field: addrtype", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // unicast-address
            session.ParsedValue.Origin.UnicastAddress =
                SerializationHelpers.ParseRequiredString("Origin field: unicast-address", remainingSlice);

            return(SessionNameSerializer.Instance.ReadValue);
        }
コード例 #6
0
        public MediaDescription ReadValue(ReadOnlySpan <byte> data)
        {
            var remainingSlice = data;

            //header
            SerializationHelpers.ParseRequiredHeader("Media field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            var mDescr = new MediaDescription();

            // Media
            mDescr.Media =
                SerializationHelpers.ParseRequiredString("Media field: Media",
                                                         SerializationHelpers.NextRequiredDelimitedField("Media field: Media", SDPSerializer.ByteSpace, remainingSlice, out var consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // port
            mDescr.Port =
                SerializationHelpers.ParseRequiredString("Media field: Port",
                                                         SerializationHelpers.NextRequiredDelimitedField("Media field: Port", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // Proto
            mDescr.Proto =
                SerializationHelpers.ParseRequiredString("Media field: Proto",
                                                         SerializationHelpers.NextRequiredDelimitedField("Media field: Proto", SDPSerializer.ByteSpace, remainingSlice, out consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // fmt
            if (remainingSlice.Length == 0)
            {
                throw new DeserializationException("Invalid Media field: fmt, expected required values");
            }
            else
            {
                mDescr.Fmts = Encoding.UTF8.GetString(remainingSlice).Split((char)SDPSerializer.ByteSpace);
            }

            return(mDescr);
        }
コード例 #7
0
        public DeserializationState ReadValue(ReadOnlySpan <byte> data, DeserializationSession session)
        {
            if (session.ParsedValue.MediaDescriptions != null && session.ParsedValue.MediaDescriptions.Any())
            {
                throw new DeserializationException("Email address MUST be specified before the first media field");
            }

            var remainingSlice = data;

            //header
            SerializationHelpers.ParseRequiredHeader("Email field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            //uri
            var emailString =
                SerializationHelpers.ParseRequiredString("Email field",
                                                         SerializationHelpers.NextRequiredField("Email field", remainingSlice));

            session.ParsedValue.EmailNumbers = session.ParsedValue.EmailNumbers ?? new List <string>();
            session.ParsedValue.EmailNumbers.Add(emailString);
            return(OptionalValueDeSerializer.Instance.ReadValue);
        }
コード例 #8
0
        public Bandwidth ReadValue(ReadOnlySpan <byte> data)
        {
            var remainingSlice = data;

            // header
            SerializationHelpers.ParseRequiredHeader("Bandwith field", remainingSlice, HeaderBytes);
            remainingSlice = remainingSlice.Slice(HeaderBytes.Length);

            var bandwith = new Bandwidth();

            // type
            bandwith.Type =
                SerializationHelpers.ParseRequiredString("Bandwith field: Type",
                                                         SerializationHelpers.NextRequiredDelimitedField("Bandwith field: Type", SDPSerializer.ByteColon, remainingSlice, out var consumed));
            remainingSlice = remainingSlice.Slice(consumed + 1);

            // value
            bandwith.Value =
                SerializationHelpers.ParseRequiredString("Bandwith field: value", remainingSlice);

            return(bandwith);
        }