{"id":217346,"date":"2020-12-01T22:49:49","date_gmt":"2020-12-01T14:49:49","guid":{"rendered":"http:\/\/4563.org\/?p=217346"},"modified":"2020-12-01T22:49:49","modified_gmt":"2020-12-01T14:49:49","slug":"js-%e5%a6%82%e4%bd%95%e5%b0%86-16-%e8%bf%9b%e5%88%b6%e7%9a%84%e6%95%b0%e6%8d%ae%e8%bd%ac%e6%88%90-arraybuffer","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=217346","title":{"rendered":"JS \u5982\u4f55\u5c06 16 \u8fdb\u5236\u7684\u6570\u636e\u8f6c\u6210 ArrayBuffer"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  JS \u5982\u4f55\u5c06 16 \u8fdb\u5236\u7684\u6570\u636e\u8f6c\u6210 ArrayBuffer               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>RT\uff0c\u6700\u8fd1\u5728\u7814\u7a76\u84dd\u7259\u786c\u4ef6\uff0c\u901a\u8fc7 Chrome \u7684 WEB \u84dd\u7259\u63a5\u53e3\u5b9e\u73b0\u84dd\u7259\u786c\u4ef6\u63a7\u5236\u7684\u529f\u80fd\uff0c\u5728\u5b9e\u73b0\u7684\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c \u6211\u4eec\u7684\u84dd\u7259\u901a\u8baf\u534f\u8bae\u4e0a\u9762\u7684\u547d\u4ee4\u90fd\u662f 16 \u8fdb\u5236\u7684\u6bd4\u5982: \u6253\u5f00 LED \u706f\uff0c\u547d\u4ee4\u662f&#8221;0x20&#8243;,\u5173\u95ed LED \u662f \uff1a\u201c0x21\u201d\uff0c\u901a\u8fc7 web API \u63a5\u53e3\u8fde\u63a5\u6210\u529f\u540e\uff0c\u968f\u4fbf\u4f20\u4e86\u4e00\u4e2a str \u7684\u547d\u4ee4\u8fc7\u53bb\uff0c\u7ed3\u679c\u5c31\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\uff1a<\/p>\n<pre><code>'writeValue' on 'BluetoothRemoteGATTCharacteristic': The provided value is not of type '(ArrayBuffer or ArrayBufferView)  <\/code><\/pre>\n<p>\u5c31\u662f\u8bf4\u8fd9\u4e2a\u63a5\u53e3\u53ea\u652f\u6301\u4f20\u9012 ArrayBuffer \u7684\u6570\u636e\uff0c\u4f46\u662f\u6211\u5982\u4f55\u5c06\u201c0x20\u201d\u8fd9\u6837\u7684 16 \u8fdb\u5236\u547d\u4ee4\u8f6c\u6362\u6210 ArrayBuffer \u5462\uff1f \u6211\u8bd5\u4e86\u51e0\u6b21\uff0c\u53d1\u73b0 ArrayBuffer \u5185\u7684\u6570\u636e\u59cb\u7ec8\u662f 10 \u8fdb\u5236\u7684\uff0c\u53ea\u80fd\u6765 V2 \u6c42\u5927\u795e\u6307\u70b9\u4e00\u4e8c\u4e86<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>19<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4418770\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e4b\u524d\u5728 nodejs \u4e0a\uff0c\u6709\u4e00\u4e2a Buffer.from \u7684\u547d\u4ee4\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c06 16 \u8fdb\u5236\u4f20\u5230\u786c\u4ef6\uff0c\u5728\u539f\u751f js \u4e0a\u6709\u70b9\u8499\u4e86\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418771\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rekulas <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7528\u7684\u4ec0\u4e48\u8f6c new ArrayBuffer(0x20) \u8bd5\u8fc7\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418772\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rekulas <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u5404\u79cd\u65b9\u6cd5\u90fd\u4e0d\u884c\u6211\u6000\u7591\u53ef\u80fd\u548c\u4f60\u7684\u4f20\u8f93\u6570\u636e encode \u65b9\u6cd5\u6709\u5173                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418773\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aloxaf <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u867d\u7136\u6211\u4e0d\u4f1a JS\uff0c\u4f46\u6211\u611f\u89c9\u4f60\u5e94\u8be5\u662f\u641e\u9519\u4e86\u4ec0\u4e48\u2026\u2026<\/p>\n<p>\u524d\u51e0\u5929\u5728\u4e00\u4e2a Python \u7fa4\u4e5f\u770b\u5230\u6709\u4eba\u95ee\u4e86\u7c7b\u4f3c\u7684\u95ee\u9898\u3002<br \/>\u4f60\u8981\u77e5\u9053\u8fdb\u5236\u662f\u7ed9\u4eba\u770b\u7684\uff0c\u800c\u5bf9\u4e8e\u4eba\u6765\u8bf4 10 \u8fdb\u5236\u662f\u6700\u81ea\u7136\u7684\uff0c\u6240\u4ee5\u4e0d\u7ba1\u4f60\u5b58\u8fdb\u53bb\u7684\u662f\u4ec0\u4e48\uff0c\u6700\u7ec8\u90fd\u4f1a\u4ee5\u5341\u8fdb\u5236\u5c55\u793a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418774\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : across <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5047\u8bbe\u547d\u4ee4\u662f 8 \u4f4d\u957f\u5ea6\u7684\uff0c\u8fd9\u6837\u4e48\uff1f<br \/>const CMD_BTYE_LENGTH = 8;<br \/>const buffer = new ArrayBuffer(CMD_BTYE_LENGTH);<br \/>const cmd = new DataView(buffer, 0, CMD_BTYE_LENGTH);<br \/>cmd.setInt8(0, 0x21); <br \/>console.log(cmd.getInt8(0));                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418775\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ccworker <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             new Uint8Array([0x21])                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418776\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ccworker <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             var a = new Uint8Array([0x21])<br \/>a.buffer                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418777\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ccworker \u611f\u8c22\u56de\u590d\uff0ca.buffer \u6253\u5370\u51fa\u6765\u662f 33\uff0c\u4e5f\u5c31\u662f\u8bf4\u53d8\u6210\u4e86 10 \u8fdb\u5236\u7684\u4e86\uff0c\u6211\u60f3\u7740\u662f \u6bd4\u5982 \u201c5A20\u201d,ArrayBuffer \u6253\u5370\u51fa\u6765\u5e94\u8be5\u662f [5a,20]                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418778\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : across <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ideacco tostring \uff08 16 \uff09\u7684\u4e8b\u3002<br \/>\u8be5\u8865\u8bfe\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u4e86&#8230;.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418779\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @across \u4e3b\u8981\u662f API \u8981\u6c42\u5fc5\u987b\u4f20\u9012 ArrayBuffer \u7c7b\u578b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418780\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aloxaf <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ideacco \u4f60\u8fd9\u95ee\u9898\u592a\u8fc7\u79bb\u8c31\u6211\u90fd\u4e0d\u77e5\u9053\u8be5\u5982\u4f55\u5411\u4f60\u89e3\u91ca\u2026\u2026<\/p>\n<p>\u4f60\u89c9\u5f97\u5728 js \u91cc 0x20 == 32 \u7684\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f false \uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418781\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aloxaf \u611f\u8c22\u5144\u5f1f\u7684\u56de\u590d\uff0c\u6211\u77e5\u9053\u5728 js \u91cc\u9762 0x20 \u5c31\u662f 32 \u4e86\uff0c\u53ef\u662f\u6211\u8fd9\u8fb9\u7684 API \u8981\u6c42\u4f7f\u7528 ArrayBuffer \u7c7b\u578b,\u4f46\u662f\u8fd9\u4e2a\u7c7b\u578b\u4f60 \u4f7f\u7528 new Uint8Array([0x20]) \u7ed3\u679c\u662f\u5b83\u4f1a\u4f20\u7ed9\u786c\u4ef6 32,\u800c\u786c\u4ef6\u652f\u6301 10 \u8fdb\u5236\u7684\u554a.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418782\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aloxaf \u4e0a\u9762\u53e3\u8bef,\u786c\u4ef6 \u4e0d\u652f\u6301 10 \u8fdb\u5236\u7684\u547d\u4ee4&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418783\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lscho <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u89c9\u5f97\u4f60\u5e94\u8be5\u4ece\u4f20\u8f93\u6570\u636e\u6765\u68c0\u67e5\u3002\u3002\u3002\u4f20\u9012 ArrayBuffer \u5e94\u8be5\u9700\u8981\u4fee\u6539\u4e00\u4e0b\u4f20\u8f93\u6570\u636e\u7684\u7c7b\u578b\u624d\u884c\uff0c\u4e0d\u80fd\u7528 string \u7c7b\u578b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418784\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lscho \u6709\u9053\u7406\u554a\uff0c\u6211\u53bb\u8bd5\u4e00\u4e0b\uff0c\u8c22\u8c22\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418785\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yggd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53c2\u8003\u4e0b\u8fd9\u91cc:<br \/>https:\/\/ionicframework.com\/docs\/native\/ble                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418786\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e2a\u4eba\u6000\u7591\u4f60\u6ca1\u641e\u61c2\u8ba1\u7b97\u673a\u5904\u7406\u6570\u636e\u7684\u65b9\u5f0f\u3002<br \/>\u8ba1\u7b97\u673a\u91cc\u9762\u5b58\u7684\u90fd\u662f\u4e8c\u8fdb\u5236\u6570\u636e\uff0c\u6ca1\u6709\u5341\u8fdb\u5236\u6216\u5341\u516d\u8fdb\u5236\u3002<br \/>\u4f60\u8bf4\u7684\u201c\u5341\u8fdb\u5236\u201d\u3001\u201c\u5341\u516d\u8fdb\u5236\u201d\u662f\u7a0b\u5e8f\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u9605\u8bfb\uff0c\u628a\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u6216\u5341\u516d\u8fdb\u5236\u7684\u5b57\u7b26\u4e32\uff0c\u518d\u663e\u793a\u51fa\u6765\u3002<\/p>\n<p>\u4e2a\u4eba\u5efa\u8bae\u4f60\u63d0\u4f9b\u8fd9\u4e2a\u786c\u4ef6\u7684\u6587\u6863\u6216\u8005\u793a\u4f8b\u4ee3\u7801\uff0c\u76ee\u524d\u7684\u4fe1\u606f\u592a\u5c11\uff0c\u65e0\u6cd5\u77e5\u9053\u5177\u4f53\u8be5\u5982\u4f55\u89e3\u51b3\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418787\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yggd \u975e\u5e38\u611f\u8c22\u53c2\u8003\u7684\u6587\u6863\uff0c\u5df2\u7ecf\u987a\u5229\u89e3\u51b3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4418788\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u611f\u8c22\u56de\u590d\uff0c\u7684\u786e\u662f\u56e0\u4e3a\u81ea\u5df1\u6c34\u5e73\u6709\u9650\uff0c\u5e76\u4e14\u8fd8\u6ca1\u4ed4\u7ec6\u8bfb\u6587\u6863                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>JS \u5982\u4f55\u5c06 16 \u8fdb\u5236\u7684\u6570\u636e\u8f6c\u6210&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\/217346"}],"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=217346"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217346\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217346"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}