{"id":180101,"date":"2020-10-29T03:16:15","date_gmt":"2020-10-28T19:16:15","guid":{"rendered":"http:\/\/4563.org\/?p=180101"},"modified":"2020-10-29T03:16:15","modified_gmt":"2020-10-28T19:16:15","slug":"%e9%97%ae%e5%a4%a7%e5%ae%b6%e4%b8%80%e4%b8%8b-cgo-%e9%87%8c%e9%9d%a2%e7%9a%84%e5%8f%82%e6%95%b0%e8%a6%81%e6%80%8e%e4%b9%88%e4%bc%a0%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=180101","title":{"rendered":"\u95ee\u5927\u5bb6\u4e00\u4e0b CGO \u91cc\u9762\u7684\u53c2\u6570\u8981\u600e\u4e48\u4f20\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u95ee\u5927\u5bb6\u4e00\u4e0b CGO \u91cc\u9762\u7684\u53c2\u6570\u8981\u600e\u4e48\u4f20\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nash <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>package main  \/* #include &lt;stdio.h&gt; unsigned short crc_ccitt(unsigned char *q, int len) {  int i, j;  int c, crc = 0xffff;  for(i=0; i&lt;len; i++) {   c = q[i] &amp; 0x00ff; crc ^= c;   for(j=0; j&lt;8; j++) {    if((crc&amp;0x0001) != 0) {    crc &gt;&gt;= 1;    crc ^= 0xA001;    } else {     crc &gt;&gt;= 1;    }   }  }  return (unsigned short)crc; } *\/ import \"C\" import (  \"fmt\"  \"unsafe\" )  func Crc() {  data := []byte{0x99, 0x88, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0e, 0x0c, 0x32, 0x31, 0x30, 0x31, 0x31, 0x38, 0x30, 0x37, 0x30, 0x30, 0x31, 0x30, 0x18}  crc := C.crc_ccitt((*C.uchar)(unsafe.Pointer(&amp;data)), C.int(len(data)))  \/\/ \u671f\u671b\u7ed3\u679c 56 f9  fmt.Printf(\"%X\", crc) }  func main() {  Crc() } <\/code><\/pre>\n<p>\u6709\u4e2a CRC \u6821\u9a8c\u7684\u4e1c\u897f\u662f C \u5199\u7684\uff0c\u6211\u5c31\u60f3\u7740\u96be\u5f97\u53bb\u7528 go \u5b9e\u73b0\u76f4\u63a5 CGO \u8c03\u7528\uff0c\u53d1\u73b0\u8fd9\u4e2a\u53c2\u6570\u600e\u4e48\u4f20\u90fd\u4e0d\u5bf9\uff0c\u8bf7\u6559\u4e0b\u5404\u4f4d\u5927\u795e\uff0c\u8c22\u8c22<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3941262\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MoYi123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u4e86\u4e00\u4e0b\uff0c<br \/> data := [26]byte{<br \/> 0x99, 0x88, 0x02, 0x00, 0x00,<br \/> 0x01, 0x00, 0x00, 0x00, 0x0a,<br \/> 0x00, 0x0e, 0x0c, 0x32, 0x31,<br \/> 0x30, 0x31, 0x31, 0x38, 0x30,<br \/> 0x37, 0x30, 0x30, 0x31, 0x30,<br \/> 0x18}<br \/>\u8fd9\u6837\u80fd\u8fd4\u56de F9 56                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941263\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imgk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &amp;data[0]                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941264\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jworg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u504f\u4e00\u4e0b\u9898\uff0c\u6709\u8fd9\u4e2a\u8c03\u8bd5\u7684\u65f6\u95f4\u8fd8\u4e0d\u5982\u76f4\u63a5 go \u5b9e\u73b0\u4e86\uff0c\u6216\u8005\u5173\u952e\u8bcd golang ccitt \u5c31\u6709\u76f8\u5e94\u7684\u4ee3\u7801\u5b9e\u73b0\u3002\u53e6\u5916\u63d0\u9192\u4e00\u4e0b\uff0ccgo \u5176\u5b9e\u8c03\u7528\u662f\u6bd4\u8f83\u6162\u7684\uff0c\u5982\u679c\u8c03\u7528\u9891\u7e41\u7684\u8bdd\uff0c\u975e\u5e38\u5f71\u54cd\u6027\u80fd\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941265\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rel <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5730\u5740\u4e0d\u5bf9<br \/>crc := C.crc_ccitt((*C.uchar)(unsafe.Pointer(&amp;data[0])), C.int(len(data)))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u5927\u5bb6\u4e00\u4e0b CGO \u91cc\u9762\u7684\u53c2\u6570\u8981\u600e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/180101"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=180101"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/180101\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=180101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=180101"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=180101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}