예제 #1
0
        /// <summary>
        /// Reads a string from the <see cref="NetPacket"/>.
        /// Reads a maximum of charLength or the original string length.
        /// </summary>
        public int ReadString(char *ptr, int ptrLength, BitEncoding encoding)
        {
            if (ptr == null)
            {
                throw new ArgumentNullException(nameof(ptr));
            }

            return(ReadStringInternal(ptr, ptrLength, encoding));
        }
        public static string Generate()
        {
            var sb = new StringBuilder();

            for (var i = 1; i < 11; i++)
            {
                var n = BitEncoding.ByteToB64(Random.Next(0, 63));
                sb.Append(n);
            }
            return(sb.ToString());
        }
예제 #3
0
        /// <summary>
        /// Writes a string to the <see cref="NetPacket"/>.
        /// </summary>
        public void WriteString(string value, BitEncoding encoding = BitEncoding.UTF16)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(nameof(value));

                fixed(char *ptr = value)
                {
                    WriteStringInternal(ptr, value.Length, encoding);
                }
        }
예제 #4
0
        public void FStringSerializeTest(string value, BitEncoding encoding)
        {
            string replica = "";

            packet.Serialize(ref value, encoding);
            packet.ResetRead();

            packet.Serialize(ref replica, encoding);

            Assert.AreEqual(value, replica);
        }
예제 #5
0
        public string ReadString(BitEncoding encoding = BitEncoding.UTF16)
        {
            switch (encoding)
            {
            case BitEncoding.ASCII:
                return(ReadString(Encoding.ASCII));

            case BitEncoding.ASCIICompressed:
                return(ReadASCIICompressed());
            }

            return(ReadUTF16Fast());
        }
예제 #6
0
        /// <summary>
        /// Writes a string to the <see cref="NetPacket"/>.
        /// Includes the bytesize as an uint16.
        /// </summary>
        public void WriteString(char *ptr, int charCount, BitEncoding encoding)
        {
            if (ptr == null)
            {
                throw new ArgumentNullException(nameof(ptr));
            }

            if (charCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(charCount));
            }

            WriteStringInternal(ptr, charCount, encoding);
        }
        public static string Generate(string name)
        {
            var bytes  = Encoding.UTF8.GetBytes(name);
            var sha256 = new System.Security.Cryptography.SHA256CryptoServiceProvider();
            var hash   = sha256.ComputeHash(bytes);

            var sb = new StringBuilder();

            for (var i = 1; i < 11; i++)
            {
                var n = BitEncoding.ByteToB64(hash[i] & 63);
                sb.Append(n);
            }
            return(sb.ToString());
        }
예제 #8
0
        private void WriteStringInternal(char *ptr, int charCount, BitEncoding encoding)
        {
            switch (encoding)
            {
            case BitEncoding.ASCII:
                WriteASCIIInternal(ptr, charCount, false);
                return;

            case BitEncoding.ASCIICompressed:
                WriteASCIIInternal(ptr, charCount, true);
                return;
            }

            WriteUTF16Internal(ptr, charCount);
        }
예제 #9
0
        public void WriteString(char[] str, int offset, int length, BitEncoding encoding)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            if ((uint)offset + (uint)length > str.Length)
            {
                throw new ArgumentOutOfRangeException("Offset and length exceed buffer.");

                fixed(char *ptr = &str[offset])
                {
                    WriteStringInternal(ptr, length, encoding);
                }
        }
예제 #10
0
        private void CharArraySmall(BitEncoding encoding)
        {
            m_stream.ResetWrite();

            char[] rep = new char[4];

            m_stream.WriteString("TestString", encoding);
            m_stream.ResetRead();

            int charCount = m_stream.ReadString(rep, encoding);

            Assert.AreEqual(charCount, rep.Length);
            string repStr = new string(rep, 0, charCount);

            Assert.AreEqual("Test", repStr);
        }
예제 #11
0
        public int ReadString(char[] destination, int offset, int length, BitEncoding encoding)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            if ((uint)offset + (uint)length > destination.Length)
            {
                throw new ArgumentOutOfRangeException("Offset and length exceed buffer.");


                fixed(char *ptr = &destination[offset])
                {
                    return(ReadStringInternal(ptr, length, encoding));
                }
        }
예제 #12
0
        private int ReadStringInternal(char *ptr, int ptrLength, BitEncoding encoding)
        {
            if (ptrLength < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(ptrLength));
            }

            switch (encoding)
            {
            case BitEncoding.ASCII:
                return(ReadASCIIInternal(ptr, ptrLength, false));

            case BitEncoding.ASCIICompressed:
                return(ReadASCIIInternal(ptr, ptrLength, true));
            }

            return(ReadUTF16Internal(ptr, ptrLength));
        }
예제 #13
0
        private void CharArraySmall(BitEncoding encoding)
        {
            packet = new NetPacket();

            char[] rep = new char[4];

            packet.WriteString("TestString", encoding);
            packet.ResetRead();

            int charCount = packet.ReadString(rep, encoding);

            Assert.AreEqual(charCount, rep.Length);
            string repStr = new string(rep, 0, charCount);

            Assert.AreEqual("Test", repStr);

            packet.Dispose();
        }
예제 #14
0
 /// <summary>
 /// Reads a string from the <see cref="NetPacket"/>.
 /// </summary>
 public int ReadString(char[] destination, BitEncoding encoding)
 {
     return(ReadString(destination, 0, destination.Length, encoding));
 }
예제 #15
0
 /// <summary>
 /// Writes a string to the <see cref="NetPacket"/>.
 /// Includes the bytesize as an uint16.
 /// </summary>
 public void WriteString(char[] str, BitEncoding encoding)
 {
     WriteString(str, 0, str.Length, encoding);
 }
예제 #16
0
 /// <summary>
 /// Writes a string to the <see cref="BitStreamer"/>.
 /// Includes the bytesize as an uint16.
 /// </summary>
 public BitStreamer WriteString(char[] str, BitEncoding encoding)
 {
     return(WriteString(str, 0, str.Length, encoding));
 }