示例#1
0
        public byte[] GetBytes()
        {
            var dataMemoryStream = new MemoryStream();
            var dataWriter       = new BigEndianBinaryWriter(dataMemoryStream);

            dataWriter.Write(NewId);

            var selfBuf = endPointFactory.SerializeEndPoint(NewEndPoint);

            if (selfBuf.Length > ushort.MaxValue)
            {
                throw new DnmpException("buf.Length larger then ushort");
            }
            dataWriter.Write((ushort)selfBuf.Length);
            dataWriter.Write(selfBuf);

            dataWriter.Write((ushort)Clients.Count(x => x.Id != NewId));
            foreach (var client in Clients)
            {
                if (client.Id == NewId)
                {
                    continue;
                }
                dataWriter.Write(client.Id);
                dataWriter.Write(client.ParentId);
                var buf = endPointFactory.SerializeEndPoint(client.EndPoint);
                if (buf.Length > ushort.MaxValue)
                {
                    throw new DnmpException("buf.Length larger then ushort");
                }
                dataWriter.Write((ushort)buf.Length);
                dataWriter.Write(buf);
                dataWriter.Write((ushort)client.CustomData.Length);
                dataWriter.Write(client.CustomData);
            }

            return(SymmetricHelper.Encrypt(key, dataMemoryStream.ToArray()));
        }
示例#2
0
        public byte[] GetBytes()
        {
            var memoryStream = new MemoryStream();
            var writer       = new BigEndianBinaryWriter(memoryStream);

            writer.Write(Client.Id);
            var buf = endPointFactory.SerializeEndPoint(Client.EndPoint);

            if (buf.Length > ushort.MaxValue)
            {
                throw new DnmpException("buf.Length larger then ushort");
            }
            writer.Write((ushort)buf.Length);
            writer.Write(buf);
            writer.Write((ushort)Client.CustomData.Length);
            writer.Write(Client.CustomData);

            return(memoryStream.ToArray());
        }