public void Init() { EnableBurst = true; EnableBurstFunc = true; Data = new NativeList <CharaData>(Allocator.Persistent); IndexSeq = new NativeList <int>(Allocator.Persistent); _name = new NativeStringList(Allocator.Persistent); _tmp_name = new NativeStringList(Allocator.Persistent); _str_list = new NativeList <ReadOnlyStringEntity>(Allocator.Persistent); _mark_list = new NativeStringList(Allocator.Persistent); _mark_list.Add("#"); _mark_list.Add("<@MARK>"); _mark_list.Add("Header"); _mark_list.Add("ExtData"); _mark_list.Add("ExtDataEnd"); _mark_list.Add("Body"); _mark_list.Add("n_total"); _mark_list.Add("d"); _mark_list.Add("r"); pack.mark_comment = _mark_list[0]; pack.mark_tag = _mark_list[1]; pack.mark_header = _mark_list[2]; pack.mark_ext = _mark_list[3]; pack.mark_ext_end = _mark_list[4]; pack.mark_body = _mark_list[5]; pack.mark_n_total = _mark_list[6]; pack.mark_d = _mark_list[7]; pack.mark_r = _mark_list[8]; _b64_decoder = new NativeBase64Decoder(Allocator.Persistent); _b64_decoded_bytes = new NativeList <byte>(Allocator.Persistent); // initialize references pack.str_list = _str_list.GetUnsafeRef(); pack.b64_decoder = _b64_decoder.GetUnsafeRef(); pack.b64_decoded_bytes = _b64_decoded_bytes.GetUnsafeRef(); pack.tmp_name = _tmp_name.GetUnsafeRef(); pack.IndexSeq = IndexSeq.GetUnsafeRef(); pack.Data = Data.GetUnsafeRef(); pack.name = _name.GetUnsafeRef(); _data_size = 0; _timer = new System.Diagnostics.Stopwatch(); _timer.Start(); _allocated = true; }
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(); }
public bool GetBytes(UnsafeRefToNativeList <byte> buff, Char16 *char_ptr, int char_len) { return(NativeBase64Decoder.GetBytesImpl(info_ptr, buff, char_ptr, char_len)); }
public bool GetBytes(UnsafeRefToNativeList <byte> buff, UnsafeRefToNativeList <Char16> str) { return(NativeBase64Decoder.GetBytesImpl(info_ptr, buff, (Char16 *)str.GetUnsafePtr(), str.Length)); }
public bool GetBytes <T>(UnsafeRefToNativeList <byte> buff, T str) where T : IJaggedArraySliceBase <Char16> { return(NativeBase64Decoder.GetBytesImpl(info_ptr, buff, (Char16 *)str.GetUnsafePtr(), str.Length)); }
public UnsafeRefToNativeBase64Decoder(NativeBase64Decoder decoder) { info_ptr = decoder._info.Target; }
public static UnsafeRefToNativeBase64Decoder GetUnsafeRef(this NativeBase64Decoder target) { return(new UnsafeRefToNativeBase64Decoder(target)); }
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(); }