{"id":41124,"date":"2024-12-01T09:31:05","date_gmt":"2024-12-01T01:31:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/41124\/"},"modified":"2024-12-01T09:31:05","modified_gmt":"2024-12-01T01:31:05","slug":"%e5%a6%82%e4%bd%95%e5%b0%86-uint8-%e5%88%87%e7%89%87%e8%bd%ac%e6%8d%a2%e4%b8%ba%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/41124\/","title":{"rendered":"\u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/span><\/p>\n<h1>\u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 09:48:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9Golang\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u4ece <code>[]uint8<\/code> \u8f6c\u6362\u4e3a <code>string<\/code> \u7684\u6700\u4f73\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/p>\n<p>\u6211\u6b63\u5728\u4f7f\u7528http:\/\/github.com\/confluenceinc\/confluence-kafka-go\/kafka<\/p>\n<p>\u4ece kafka \u8bfb\u53d6\u4e8b\u4ef6\u3002\u4f46\u5b83\u4e0d\u8fd4\u56de\u7eaf\u5b57\u7b26\u4e32\u4e8b\u4ef6\u3002 \u5b83\u8fd4\u56de\u7c7b\u578b\u4e3a <code>[]uint8<\/code> \u7684\u4e8b\u4ef6\u3002 \u5982\u4f55\u5c06\u6b64\u4e8b\u4ef6\u4ece <code>[]uint8<\/code> \u8f6c\u6362\u4e3a <code>string<\/code>\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\uff0c\u8fd9\u610f\u5473\u7740 <code>uint8<\/code>)\uff08\u53c8\u540d <code>[]uint8<\/code>\uff09\u7684\u5207\u7247\u4e5f\u662f <code>byte<\/code>\uff08\u53c8\u540d <code>[]byte<\/code>\uff09\u7684\u5207\u7247\u3002<\/p>\n<p>\u5b57\u8282\u5207\u7247\u548c\u5b57\u7b26\u4e32\u662f\u53ef\u4ee5\u76f4\u63a5\u8f6c\u6362\u7684\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u662f\u7531\u5b57\u8282\u5207\u7247\u652f\u6301\u7684\uff1a<\/p>\n<pre>myByteSlice := []byte{ ... }     \/\/ same as myByteSlice := []uint8{ ... }\nmyString := string(myByteSlice)  \/\/ myString is a string representation of the byte slice\nmyOtherSlice := []byte(myString) \/\/ Converted back to byte slice<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 \u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 \u6765\u6e90\uff1astackoverflow 2024-04-19 09:48:34 0\u6d4f\u89c8 \u6536\u85cf \u5c0f\u4f19\u4f34\u4eec\u5bf9Golang\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u5c06 uint8 \u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01 \u95ee\u9898\u5185\u5bb9 \u4ece []uint8 \u8f6c\u6362\u4e3a string \u7684\u6700\u4f73\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f \u6211\u6b63\u5728\u4f7f\u7528http:\/\/github.com\/confluenceinc\/confluence-kafka-go\/kafka \u4ece kafka \u8bfb\u53d6\u4e8b\u4ef6\u3002\u4f46\u5b83\u4e0d\u8fd4\u56de\u7eaf\u5b57\u7b26\u4e32\u4e8b\u4ef6\u3002 \u5b83\u8fd4\u56de\u7c7b\u578b\u4e3a []uint8 \u7684\u4e8b\u4ef6\u3002 \u5982\u4f55\u5c06\u6b64\u4e8b\u4ef6\u4ece []uint8 \u8f6c\u6362\u4e3a string\uff1f \u89e3\u51b3\u65b9\u6848 \uff0c\u8fd9\u610f\u5473\u7740 uint8)\uff08\u53c8\u540d []uint8\uff09\u7684\u5207\u7247\u4e5f\u662f byte\uff08\u53c8\u540d []byte\uff09\u7684\u5207\u7247\u3002 \u5b57\u8282\u5207\u7247\u548c\u5b57\u7b26\u4e32\u662f\u53ef\u4ee5\u76f4\u63a5\u8f6c\u6362\u7684\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u662f\u7531\u5b57\u8282\u5207\u7247\u652f\u6301\u7684\uff1a myByteSlice := []byte{ &#8230; } \/\/ same as myByteSlice := []uint8{ &#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-41124","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=41124"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41124\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=41124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=41124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=41124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}