1、毛病描写
> buffer=new Buffer([0x11,0x22,0x33,0x44,0x55,0x66]);
<Buffer 11 22 33 44 55 66>
> buffer.readUInt8(0);
17
> buffer.readUInt8(1);
34
> buffer.readUInt8(2);
51
> buffer.readUInt8(3);
68
> buffer.readUInt8(4);
85
> buffer.readUInt8(5);
102
> buffer.readUInt8(6);
RangeError: index out of range
at checkOffset (buffer.js:615:11)
at Buffer.readUInt8 (buffer.js:653:5)
at repl:1:8
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:431:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:211:10)
>
2、毛病缘由 超越索引值范围
3、解决办法
由于索引值可以为0、1、2、3、4、5,不能超过5,所以不能出现buffer.readUInt8(6);