Exemplo n.º 1
0
        public void Clear()
        {
            Data.Clear();
            IndexSeq.Clear();
            pack.N = 0;
            pack.D = 0;
            pack.R = 0;

            pack.Lines = 0;

            _name.Clear();
            _tmp_name.Clear();
            _str_list.Clear();

            _b64_decoder.Clear();
            _b64_decoded_bytes.Clear();

            // pre-reallocating for after 2nd loadings
            if (_data_size > 0)
            {
                Data.Capacity     = _data_size;
                IndexSeq.Capacity = _data_size;

                _name.Capacity      = 8 * _data_size;         // estimate 8 charactors for name of 1 CharaData
                _tmp_name.Capacity  = 8 * _data_size;
                _name.IndexCapacity = _data_size;
                _tmp_name.Capacity  = _data_size;

                _b64_decoded_bytes.Capacity = 4 * _data_size; // convrt to Int32 array
            }

            pack.read_mode = ReadMode.None;
        }
Exemplo n.º 2
0
        public void CheckParseBase64_Fixed()
        {
            string[] str_list = new string[]
            {
                "ABCDEFG",
                "abcdefg",
                "ABCDEF",
                "abcdef",
            };

            var bytes_native   = new NativeList <byte>(Allocator.Persistent);
            var encoded_native = new NativeList <Char16>(Allocator.Persistent);
            var bytes_decoded  = new NativeList <byte>(Allocator.Persistent);

            var b64_encoder = new NativeBase64Encoder(Allocator.Persistent);
            var b64_decoder = new NativeBase64Decoder(Allocator.Persistent);

            foreach (var str_ref in str_list)
            {
                byte[] bytes_ref   = Encoding.UTF8.GetBytes(str_ref);
                string encoded_ref = Convert.ToBase64String(bytes_ref);

                bytes_native.Clear();
                encoded_native.Clear();
                bytes_decoded.Clear();

                foreach (var b in bytes_ref)
                {
                    bytes_native.Add(b);
                }

                b64_encoder.Clear();
                b64_encoder.GetChars(encoded_native, bytes_native);

                CheckBase64EncodedStr(encoded_native, encoded_ref, true);

                b64_decoder.Clear();
                b64_decoder.GetBytes(bytes_decoded, encoded_native);

                CheckBase64DecodedBytes(bytes_decoded, bytes_ref, true);
            }

            bytes_native.Dispose();
            encoded_native.Dispose();
            bytes_decoded.Dispose();

            b64_encoder.Dispose();
            b64_decoder.Dispose();
        }
Exemplo n.º 3
0
        public void CheckParseBase64_Random(int n)
        {
            Assert.IsTrue(n > 0);
            const int Base64InLine = 76;

            var bytes_native   = new NativeList <byte>(Allocator.Persistent);
            var encoded_native = new NativeList <Char16>(Allocator.Persistent);
            var bytes_decoded  = new NativeList <byte>(Allocator.Persistent);

            var b64_encoder = new NativeBase64Encoder(Allocator.Persistent);
            var b64_decoder = new NativeBase64Decoder(Allocator.Persistent);

            long total_bytes = 0;

            for (int i = 0; i < n; i++)
            {
                int byte_len = random.Next(16, 256);
                total_bytes += byte_len;

                byte[] bytes_ref = new byte[byte_len];
                bytes_native.Clear();
                for (int j = 0; j < byte_len; j++)
                {
                    byte b = (byte)random.Next(0, 255);
                    bytes_ref[j] = b;
                    bytes_native.Add(b);
                }

                string encoded_ref = Convert.ToBase64String(bytes_ref);

                var sb        = new StringBuilder();
                int charcount = 0;
                foreach (char c in encoded_ref)
                {
                    if (charcount == Base64InLine)
                    {
                        sb.Append("\r\n");
                        charcount = 0;
                    }

                    sb.Append(c);
                    charcount++;
                }
                string encoded_ref_withLF = sb.ToString();

                // test for encoded str with CRLF
                encoded_native.Clear();
                bytes_decoded.Clear();

                b64_encoder.Clear();
                b64_encoder.GetChars(encoded_native, bytes_native);

                CheckBase64EncodedStr(encoded_native, encoded_ref_withLF);

                b64_decoder.Clear();
                b64_decoder.GetBytes(bytes_decoded, encoded_native);

                CheckBase64DecodedBytes(bytes_decoded, bytes_ref);

                // test for encoded str without CRLF
                encoded_native.Clear();
                bytes_decoded.Clear();

                b64_encoder.Clear();
                b64_encoder.InsertLineBrakes = false;  // default: encode with "CRLF".
                b64_encoder.GetChars(encoded_native, bytes_native);
                b64_encoder.InsertLineBrakes = true;

                CheckBase64EncodedStr(encoded_native, encoded_ref);

                b64_decoder.Clear();
                b64_decoder.GetBytes(bytes_decoded, encoded_native);

                CheckBase64DecodedBytes(bytes_decoded, bytes_ref);
            }

            Debug.Log("total test bytes: " + total_bytes.ToString() + " B\n");

            bytes_native.Dispose();
            encoded_native.Dispose();
            bytes_decoded.Dispose();

            b64_encoder.Dispose();
            b64_decoder.Dispose();
        }