|
1 | 1 | 'use strict';
|
| 2 | + |
2 | 3 | function Handler(config) {
|
3 |
| - this.config = config; |
4 |
| - switch (config.entry.protocol) { |
5 |
| - case 'bytearray': { |
6 |
| - this.sendHandler = require('./bytearray.js').create(config.id, config.entry.bufferSize || config.entry.buffersize); |
7 |
| - break; |
8 |
| - } |
9 |
| - case 'json': { |
10 |
| - this.sendHandler = require('./json.js').create(config.id); |
11 |
| - break; |
12 |
| - } |
| 4 | + this.config = config; |
| 5 | + switch (config.entry.protocol) { |
| 6 | + case 'bytearray': { |
| 7 | + this.sendHandler = require('./bytearray.js').create( |
| 8 | + config.id, |
| 9 | + config.entry.bufferSize || config.entry.buffersize, |
| 10 | + ); |
| 11 | + break; |
| 12 | + } |
| 13 | + case 'json': { |
| 14 | + this.sendHandler = require('./json.js').create(config.id); |
| 15 | + break; |
| 16 | + } |
13 | 17 | // case 'dmp': {
|
14 | 18 | // this.sendHandler = require('./dmp.js').create(config.id);
|
15 | 19 | // break;
|
16 | 20 | // }
|
17 |
| - } |
| 21 | + } |
18 | 22 | }
|
19 | 23 |
|
20 | 24 | Handler.prototype.encode = function() {
|
21 |
| - if (this.sendHandler) { |
22 |
| - return this.sendHandler.encode(); |
23 |
| - } |
| 25 | + if (this.sendHandler) { |
| 26 | + return this.sendHandler.encode(); |
| 27 | + } |
24 | 28 | };
|
25 | 29 |
|
26 | 30 | Handler.prototype.decode = function(data, type) {
|
27 |
| - if (type == 'binary') { |
28 |
| - if (data[1] != 0x00) { |
29 |
| - if (!this.receiveHandler) { |
30 |
| - switch (data[5]) { |
31 |
| - case 0x01: { |
32 |
| - this.receiveHandler = require('./bytearray.js').create(this.config.id); |
33 |
| - break; |
34 |
| - } |
| 31 | + if (type == 'binary') { |
| 32 | + if (data[1] != 0x00) { |
| 33 | + if (!this.receiveHandler) { |
| 34 | + switch (data[5]) { |
| 35 | + case 0x01: { |
| 36 | + this.receiveHandler = require('./bytearray.js').create(this.config.id); |
| 37 | + break; |
| 38 | + } |
35 | 39 | // case 0x03: {
|
36 | 40 | // this.receiveHandler = require('./dmp.js').create(this.config.id);
|
37 | 41 | // break;
|
38 | 42 | // }
|
39 |
| - } |
40 |
| - } |
41 |
| - if (this.receiveHandler) { |
42 |
| - this.receiveHandler.decode(data); |
43 |
| - } |
44 |
| - } |
45 |
| - } else if (type == 'utf8') { |
46 |
| - if (!this.receiveHandler) { |
47 |
| - this.receiveHandler = require('./json.js').create(this.config.id); |
48 |
| - } |
49 |
| - if (this.receiveHandler) { |
50 |
| - this.receiveHandler.decode(data); |
51 |
| - } |
52 |
| - } |
| 43 | + } |
| 44 | + } |
| 45 | + if (this.receiveHandler) { |
| 46 | + this.receiveHandler.decode(data); |
| 47 | + } |
| 48 | + } |
| 49 | + } else if (type == 'utf8') { |
| 50 | + if (!this.receiveHandler) { |
| 51 | + this.receiveHandler = require('./json.js').create(this.config.id); |
| 52 | + } |
| 53 | + if (this.receiveHandler) { |
| 54 | + this.receiveHandler.decode(data); |
| 55 | + } |
| 56 | + } |
53 | 57 | };
|
54 | 58 |
|
55 | 59 | Handler.prototype.e = function(arg) {
|
56 |
| - if (this.receiveHandler) { |
57 |
| - return this.receiveHandler.e(arg); |
58 |
| - } |
59 |
| - return false; |
| 60 | + if (this.receiveHandler) { |
| 61 | + return this.receiveHandler.e(arg); |
| 62 | + } |
| 63 | + return false; |
60 | 64 | };
|
61 | 65 |
|
62 | 66 | Handler.prototype.read = function(arg) {
|
63 |
| - if (this.receiveHandler) { |
64 |
| - return this.receiveHandler.read(arg); |
65 |
| - } |
66 |
| - return 0; |
| 67 | + if (this.receiveHandler) { |
| 68 | + return this.receiveHandler.read(arg); |
| 69 | + } |
| 70 | + return 0; |
67 | 71 | };
|
68 | 72 |
|
69 | 73 | Handler.prototype.write = function(arg1, arg2) {
|
70 |
| - if (this.sendHandler) { |
71 |
| - return this.sendHandler.write(arg1, arg2); |
72 |
| - } |
73 |
| - return false; |
| 74 | + if (this.sendHandler) { |
| 75 | + return this.sendHandler.write(arg1, arg2); |
| 76 | + } |
| 77 | + return false; |
74 | 78 | };
|
75 | 79 |
|
76 | 80 | module.exports.create = function(config) {
|
77 |
| - return new Handler(config); |
| 81 | + return new Handler(config); |
78 | 82 | };
|
0 commit comments