|
| 1 | +/* |
| 2 | + * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | + * copy of this software and associated documentation files (the "Software"), |
| 6 | + * to deal in the Software without restriction, including without limitation |
| 7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | + * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | + * Software is furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | + * DEALINGS IN THE SOFTWARE. |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */ |
| 25 | +/*global */ |
| 26 | + |
| 27 | +(function () { |
| 28 | + "use strict"; |
| 29 | + |
| 30 | + /** |
| 31 | + * @private |
| 32 | + * @type {DomainManager} |
| 33 | + * The DomainManager passed in at init. |
| 34 | + */ |
| 35 | + var _domainManager = null; |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * @private |
| 40 | + * @type {Buffer} |
| 41 | + */ |
| 42 | + var _buffer = new Buffer(18); |
| 43 | + |
| 44 | + // write some bytes into the buffer with varied alignments |
| 45 | + _buffer.writeUInt8(1, 0); |
| 46 | + _buffer.writeUInt32LE(Math.pow(2, 32) - 1, 1); |
| 47 | + _buffer.writeFloatBE(3.141592, 5); |
| 48 | + _buffer.writeDoubleLE(Number.MAX_VALUE, 9); |
| 49 | + _buffer.writeInt8(-128, 17); |
| 50 | + |
| 51 | + /** |
| 52 | + * @private |
| 53 | + * @return {Buffer} |
| 54 | + */ |
| 55 | + function _getBufferSync() { |
| 56 | + return _buffer; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @private |
| 61 | + * @param {function(?string, Buffer=)} callback |
| 62 | + */ |
| 63 | + function _getBufferAsync(callback) { |
| 64 | + process.nextTick(function () { |
| 65 | + callback(null, _buffer); |
| 66 | + }); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param {DomainManager} DomainManager The DomainManager for the server |
| 71 | + */ |
| 72 | + function init(DomainManager) { |
| 73 | + _domainManager = DomainManager; |
| 74 | + if (!_domainManager.hasDomain("test")) { |
| 75 | + _domainManager.registerDomain("test", {major: 0, minor: 1}); |
| 76 | + } |
| 77 | + _domainManager.registerCommand( |
| 78 | + "binaryTest", |
| 79 | + "getBufferSync", |
| 80 | + _getBufferSync, |
| 81 | + false, |
| 82 | + "Get a byte array synchronously", |
| 83 | + [], |
| 84 | + {name: "bytes", type: "Buffer"} |
| 85 | + ); |
| 86 | + _domainManager.registerCommand( |
| 87 | + "binaryTest", |
| 88 | + "getBufferAsync", |
| 89 | + _getBufferAsync, |
| 90 | + true, |
| 91 | + "Get a byte array asynchronously", |
| 92 | + [], |
| 93 | + {name: "bytes", type: "Buffer"} |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + exports.init = init; |
| 98 | + |
| 99 | +}()); |
0 commit comments