Beispiel #1
0
        public static IMemoryOwner <byte> Encode(DCConnectMessage message)
        {
            int sl = message.ServiceName.Length * 2;

            if (sl > byte.MaxValue)
            {
                throw new ArgumentException("ServiceName too long.", nameof(message));
            }
            int il = message.InstanceName.Length * 2;

            if (il > byte.MaxValue)
            {
                throw new ArgumentException("InstanceName too long.", nameof(message));
            }
            if (message.Args.Length > byte.MaxValue)
            {
                throw new ArgumentException("Args too long.", nameof(message));
            }
            // port, c(servicename):tiny, servicename, c(instancename):tiny, instancename <-- (always less than 15 * 256, i.e. < 3840 bytes)
            var l     = 2 + 1 + sl + 1 + il + 2 + message.Args.Length;
            var array = ExactSizeMemoryPool.Shared.Rent(l + 2);
            var span  = WriteMessageWithCompressedLength(array.Memory.Span, DataLinkMessageType.Connect, l, true);

            Write(ref span, message.Port);
            WriteTinyString(ref span, message.ServiceName);
            WriteTinyString(ref span, message.InstanceName);
            WriteTinyBinary(ref span, message.Args.Span);
            return(array);
        }
Beispiel #2
0
 internal DataLink(DataLinkCollection dlc, IPEndPoint remote, Stream stream, IDataLinkHandler handler, DataLinkDecoder decoder, DCConnectMessage connectMessage, ReadOnlyMemory <byte> memory)
 {
     _dlc             = dlc;
     _stream          = stream;
     _handler         = handler;
     _decoder         = decoder;
     Remote           = remote;
     RemoteName       = connectMessage.InstanceName;
     RemoteListenPort = connectMessage.Port;
     _inPipe.Writer.WriteAsync(memory);
     _inPipe.Writer.FlushAsync();
 }