"use strict";(self.webpackChunktouchsocket=self.webpackChunktouchsocket||[]).push([[9925],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>d});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=r.createContext({}),p=function(e){var t=r.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},s=function(e){var t=p(e.components);return r.createElement(i.Provider,{value:t},e.children)},u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,i=e.parentName,s=c(e,["components","mdxType","originalType","parentName"]),m=p(n),d=a,k=m["".concat(i,".").concat(d)]||m[d]||u[d]||o;return n?r.createElement(k,l(l({ref:t},s),{},{components:n})):r.createElement(k,l({ref:t},s))}));function d(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,l=new Array(o);l[0]=m;var c={};for(var i in t)hasOwnProperty.call(t,i)&&(c[i]=t[i]);c.originalType=e,c.mdxType="string"==typeof e?e:a,l[1]=c;for(var p=2;p{n.r(t),n.d(t,{assets:()=>i,contentTitle:()=>l,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>p});var r=n(7462),a=(n(7294),n(3905));const o={id:"othercore",title:"\u5176\u4ed6\u76f8\u5173\u529f\u80fd\u7c7b"},l=void 0,c={unversionedId:"othercore",id:"othercore",title:"\u5176\u4ed6\u76f8\u5173\u529f\u80fd\u7c7b",description:"\u4e00\u3001Crc\u8ba1\u7b97",source:"@site/docs/othercore.mdx",sourceDirName:".",slug:"/othercore",permalink:"/touchsocket/docs/othercore",draft:!1,editUrl:"https://gitee.com/rrqm_home/touchsocket/tree/master/handbook/docs/othercore.mdx",tags:[],version:"current",lastUpdatedBy:"\u82e5\u6c5d\u68cb\u8317",lastUpdatedAt:1677894439,formattedLastUpdatedAt:"Mar 4, 2023",frontMatter:{id:"othercore",title:"\u5176\u4ed6\u76f8\u5173\u529f\u80fd\u7c7b"},sidebar:"docs",previous:{title:"\u5305\u5e8f\u5217\u5316\u6a21\u5f0f",permalink:"/touchsocket/docs/ipackage"},next:{title:"Tcp\u5165\u95e8\u57fa\u7840",permalink:"/touchsocket/docs/tcpintroduction"}},i={},p=[{value:"\u4e00\u3001Crc\u8ba1\u7b97",id:"\u4e00crc\u8ba1\u7b97",level:2},{value:"\u4e8c\u3001\u65f6\u95f4\u6d4b\u91cf\u5668\uff08TimeMeasurer\uff09",id:"\u4e8c\u65f6\u95f4\u6d4b\u91cf\u5668timemeasurer",level:2},{value:"\u4e09\u3001MD5\u8ba1\u7b97",id:"\u4e09md5\u8ba1\u7b97",level:2},{value:"\u56db\u300116\u8fdb\u5236\u76f8\u5173",id:"\u56db16\u8fdb\u5236\u76f8\u5173",level:2},{value:"\u4e94\u3001\u96ea\u82b1ID\u751f\u6210",id:"\u4e94\u96ea\u82b1id\u751f\u6210",level:2},{value:"\u516d\u3001\u6570\u636e\u538b\u7f29",id:"\u516d\u6570\u636e\u538b\u7f29",level:2},{value:"\u4e03\u3001\u77ed\u65f6\u95f4\u6233",id:"\u4e03\u77ed\u65f6\u95f4\u6233",level:2},{value:"\u516b\u3001\u8bfb\u5199\u9501using",id:"\u516b\u8bfb\u5199\u9501using",level:2}],s={toc:p};function u(e){let{components:t,...n}=e;return(0,a.kt)("wrapper",(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h2",{id:"\u4e00crc\u8ba1\u7b97"},"\u4e00\u3001Crc\u8ba1\u7b97"),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"},"TouchSocket"),"\u4ece\u7f51\u4e0a\u641c\u96c6\u4e86Crc1-23\u7684\u8ba1\u7b97\u65b9\u6cd5\u3002\u5e76\u5c01\u88c5\u5728\u4e86Crc\u7c7b\u4e2d\u3002\n\u4ee5\u6700\u5e38\u7528\u7684Crc16\u4e3a\u4f8b\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"byte[] data = new byte[10];\nbyte[] result = Crc.Crc16(data, 0, data.Length);\n")),(0,a.kt)("h2",{id:"\u4e8c\u65f6\u95f4\u6d4b\u91cf\u5668timemeasurer"},"\u4e8c\u3001\u65f6\u95f4\u6d4b\u91cf\u5668\uff08TimeMeasurer\uff09"),(0,a.kt)("p",null,"\u529f\u80fd\uff1a\u5c01\u88c5\u7684Stopwatch\uff0c\u6d4b\u91cf\u8fd0\u884cAction\u7684\u65f6\u95f4\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"TimeSpan timeSpan = TimeMeasurer.Run(() =>\n {\n Thread.Sleep(1000);\n });\n\n")),(0,a.kt)("h2",{id:"\u4e09md5\u8ba1\u7b97"},"\u4e09\u3001MD5\u8ba1\u7b97"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},'string str = MD5.GetMD5Hash("TouchSocket");\nbool b = MD5.VerifyMD5Hash("TouchSocket",str);\n')),(0,a.kt)("h2",{id:"\u56db16\u8fdb\u5236\u76f8\u5173"},"\u56db\u300116\u8fdb\u5236\u76f8\u5173"),(0,a.kt)("p",null,"\u3010\u5c0616\u8fdb\u5236\u7684\u5b57\u7b26\u8f6c\u6362\u4e3a\u6570\u7ec4\u3011"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"}," public static byte[] ByHexStringToBytes(this string hexString, string splite = default)\n")),(0,a.kt)("p",null,"\u3010\u5c0616\u8fdb\u5236\u7684\u5b57\u7b26\u8f6c\u6362\u4e3aint32\u3011"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"}," public static int ByHexStringToInt32(this string hexString)\n")),(0,a.kt)("h2",{id:"\u4e94\u96ea\u82b1id\u751f\u6210"},"\u4e94\u3001\u96ea\u82b1ID\u751f\u6210"),(0,a.kt)("p",null,"\u96ea\u82b1ID\uff0c\u4f1a\u751f\u6210long\u7c7b\u578b\u7684\u4e0d\u91cd\u590dID\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"SnowflakeIDGenerator generator = new SnowflakeIDGenerator(4);\nlong id=generator.NextID();\n")),(0,a.kt)("h2",{id:"\u516d\u6570\u636e\u538b\u7f29"},"\u516d\u3001\u6570\u636e\u538b\u7f29"),(0,a.kt)("p",null,"\u5185\u90e8\u5c01\u88c5\u4e86Gzip\u7684\u538b\u7f29\u3002\u4f7f\u7528\u9759\u6001\u65b9\u6cd5\u5373\u53ef\u5b8c\u6210\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"\nbyte[] data = new byte[1024];\nnew Random().NextBytes(data);\n\nusing (ByteBlock byteBlock=new ByteBlock())\n{\n GZip.Compress(byteBlock,data,0,data.Length);//\u538b\u7f29\n var decompressData2 = GZip.Decompress(byteBlock.ToArray());//\u89e3\u538b\n}\n\n\n")),(0,a.kt)("p",null,"\u538b\u7f29\u63a5\u53e3\n\u5185\u90e8\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2aIDataCompressor\u7684\u538b\u7f29\u63a5\u53e3\u3002\u76ee\u7684\u662f\u4e3a\u4e86\u5411\u6210\u719f\u6846\u67b6\u4f20\u9012\u538b\u7f29\u65b9\u6cd5\uff08\u4f8b\u5982TcpClient\uff09\u3002\n\u9ed8\u8ba4\u914d\u5907\u4e86\u4e00\u4e2aGZipDataCompressor\u3002\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u3002\u5f53\u7136\u5927\u5bb6\u53ef\u4ee5\u81ea\u7531\u6269\u5c55\u5176\u4ed6\u538b\u7f29\u65b9\u6cd5\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"class MyDataCompressor : IDataCompressor\n{\n public byte[] Compress(ArraySegment data)\n {\n //\u6b64\u5904\u5b9e\u73b0\u538b\u7f29\n throw new NotImplementedException();\n }\n\n public byte[] Decompress(ArraySegment data)\n {\n //\u6b64\u5904\u5b9e\u73b0\u538b\u7f29\n throw new NotImplementedException();\n }\n}\n")),(0,a.kt)("h2",{id:"\u4e03\u77ed\u65f6\u95f4\u6233"},"\u4e03\u3001\u77ed\u65f6\u95f4\u6233"),(0,a.kt)("p",null,"\u4e00\u822c\u7684\uff0c\u65f6\u95f4\u53ef\u7531long\u7c7b\u578b\u4f5c\u4e3a\u552f\u4e00\u65f6\u95f4\u6233\uff0c\u4f46\u662f\u6709\u65f6\u5019\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u77ed\u7c7b\u578b\u7684\u65f6\u95f4\u6233\uff08uint\uff09\uff0c\u6240\u4ee5\u60a8\u53ef\u4ee5\u4f7f\u7528",(0,a.kt)("strong",{parentName:"p"},"DateTimeExtensions"),"\u7c7b\u5b9e\u73b0\uff0c\u6216\u8005\u4f7f\u7528\u5176\u6269\u5c55\u65b9\u6cd5\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"uint timestamp= DateTimeExtensions.ConvertTime(DateTime.Now);\ntimestamp= DateTime.Now.ConvertTime();//\u6269\u5c55\u65b9\u6cd5\n")),(0,a.kt)("h2",{id:"\u516b\u8bfb\u5199\u9501using"},"\u516b\u3001\u8bfb\u5199\u9501using"),(0,a.kt)("p",null,"\u4e00\u822c\u7684\uff0c\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528",(0,a.kt)("strong",{parentName:"p"},"ReaderWriterLockSlim"),"\u8bfb\u5199\u9501\uff0c\u8fdb\u884c\u6210\u5bf9\u7684Enter\u548cExit\u3002\u6240\u4ee5\u6211\u4eec\u4e00\u822c\u4f1a\u4f7f\u7528\u4e0b\u5217\u4ee3\u7801\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"ReaderWriterLockSlim lockSlim = new ReaderWriterLockSlim();\ntry\n{\n lockSlim.EnterReadLock();\n //do something\n}\nfinally \n{\n lockSlim.ExitReadLock();\n}\n")),(0,a.kt)("p",null,"\u4f46\u662f\u4f1a\u663e\u5f97\u4ee3\u7801\u975e\u5e38\u81c3\u80bf\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u7b80\u5316\u4f7f\u7528using\u5b9e\u73b0\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-csharp"},"ReaderWriterLockSlim lockSlim = new ReaderWriterLockSlim();\n\nusing (new ReadLock(lockSlim))\n{\n //do something\n}\n\nusing (new WriteLock(lockSlim))\n{\n //do something\n}\n")),(0,a.kt)("admonition",{title:"\u63d0\u793a",type:"tip"},(0,a.kt)("p",{parentName:"admonition"},(0,a.kt)("strong",{parentName:"p"},"ReadLock"),"\u548c",(0,a.kt)("strong",{parentName:"p"},"WriteLock"),"\u5747\u4e3astruct\u7c7b\u578b\uff0c\u6240\u4ee5\u51e0\u4e4e\u4e0d\u4f1a\u5f71\u54cd\u6027\u80fd\u3002")))}u.isMDXComponent=!0}}]);