public void GlobalSupportedProtocolsOverriddenByHubSupportedProtocols()
        {
            var testData = _invocationTestData["Single supported protocol"];

            var resolver = CreateHubProtocolResolver(new List <IHubProtocol> {
                new MessagePackHubProtocol(), new JsonHubProtocol()
            });

            var serializer = new DefaultHubMessageSerializer(resolver, new List <string>()
            {
                "json"
            }, new List <string>()
            {
                "messagepack"
            });
            var serializedHubMessage = serializer.SerializeMessage(_testMessage);

            Assert.Equal(1, serializedHubMessage.Count);

            Assert.Equal(new List <byte>()
            {
                0x0D,
                0x96,
                0x01,
                0x80,
                0xC0,
                0xA6, (byte)'t', (byte)'a', (byte)'r', (byte)'g', (byte)'e', (byte)'t',
                0x90,
                0x90
            },
                         serializedHubMessage[0].Serialized.ToArray());
        }
Exemple #2
0
        private void WriteHubMessage(Stream stream, HubMessage message)
        {
            // Written as a MessagePack 'map' where the keys are the name of the protocol (as a MessagePack 'str')
            // and the values are the serialized blob (as a MessagePack 'bin').

            var serializedHubMessages = _messageSerializer.SerializeMessage(message);

            MessagePackBinary.WriteMapHeader(stream, serializedHubMessages.Count);

            foreach (var serializedMessage in serializedHubMessages)
            {
                MessagePackBinary.WriteString(stream, serializedMessage.ProtocolName);

                var isArray = MemoryMarshal.TryGetArray(serializedMessage.Serialized, out var array);
                Debug.Assert(isArray);
                MessagePackBinary.WriteBytes(stream, array.Array, array.Offset, array.Count);
            }
        }
Exemple #3
0
        private void WriteHubMessage(ref MessagePackWriter writer, HubMessage message)
        {
            // Written as a MessagePack 'map' where the keys are the name of the protocol (as a MessagePack 'str')
            // and the values are the serialized blob (as a MessagePack 'bin').

            var serializedHubMessages = _messageSerializer.SerializeMessage(message);

            writer.WriteMapHeader(serializedHubMessages.Count);

            foreach (var serializedMessage in serializedHubMessages)
            {
                writer.Write(serializedMessage.ProtocolName);

                var isArray = MemoryMarshal.TryGetArray(serializedMessage.Serialized, out var array);
                Debug.Assert(isArray);
                writer.Write(array);
            }
        }
        public void SerializeMessages(string testName)
        {
            var testData = _invocationTestData[testName];

            var resolver = CreateHubProtocolResolver(new List <IHubProtocol> {
                new MessagePackHubProtocol(), new JsonHubProtocol()
            });
            var protocolNames        = testData.SupportedHubProtocols.ConvertAll(p => p.Name);
            var serializer           = new DefaultHubMessageSerializer(resolver, protocolNames, hubSupportedProtocols: null);
            var serializedHubMessage = serializer.SerializeMessage(_testMessage);

            var allBytes = new List <byte>();

            Assert.Equal(testData.SerializedCount, serializedHubMessage.Count);
            foreach (var message in serializedHubMessage)
            {
                allBytes.AddRange(message.Serialized.ToArray());
            }

            Assert.Equal(testData.Encoded, allBytes);
        }