http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/LICENSE ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/LICENSE b/proton-c/bindings/javascript/LICENSE deleted file mode 100644 index 6b0b127..0000000 --- a/proton-c/bindings/javascript/LICENSE +++ /dev/null @@ -1,203 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/README ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/README b/proton-c/bindings/javascript/README deleted file mode 100644 index 2dea949..0000000 --- a/proton-c/bindings/javascript/README +++ /dev/null @@ -1,426 +0,0 @@ -Qpid Proton JavaScript Language Bindings -======================================== - -The code contained herein provides JavaScript language bindings for working -with the Qpid Proton AMQP 1.0 protocol engine and messenger library. - -Important Note - Modern Browser Needed -====================================== - -The JavaScript binding requires ArrayBuffer/TypedArray and WebSocket support. -Both of these are available in most "modern" browser versions. The author has -only tried running on FireFox and Chrome, though recent Safari, Opera and IE10+ -*should* work too - YMMV. It might be possible to polyfill for older browsers -but the author hasn't tried this. - -Important Note - WebSocket Transport!!! -======================================= - -Before going any further it is really important to realise that the JavaScript -bindings to Proton are somewhat different to the bindings for other languages -because of the restrictions of the execution environment. In particular it is -very important to note that the JavaScript bindings by default use a WebSocket -transport and not a TCP transport, so whilst it's possible to create Server style -applications that clients can connect to (e.g. recv.js and send.js) note that: - -JavaScript clients cannot *directly* talk to "normal" AMQP applications such as -qpidd or (by default) the Java Broker because they use a standard TCP transport. - -This is a slightly irksome issue, but there's no getting away from it because -it's a security restriction imposed by the browser environment. - - -At the moment even for Node.js we are limited to using a WebSocket transport, but -it is on the author's "TODO" list to look at providing a means to use either a -WebSocket transport or a native TCP transport (via node's net library). It should -also be possible to use native TCP for Chrome "packaged apps", but again this is -only on the TODO list so if you want to talk to a "normal" AMQP application you -must live with the WebSocket constraints. - -Option 1. proxy from WebSockets to TCP sockets. The application -<proton>/examples/messenger/javascript/proxy.js -is a simple Node.js WebSocket<->TCP Socket proxy, simply doing: - -node proxy.js - -will stand up a proxy listening by default on WebSocket port 5673 and forwarding -to TCP port 5672 (this is configurable, for options do: node proxy.js -h) - -Rather than using a stand-alone proxy it is possible to have applications stand -up their own proxy (where lport = listen port, thost = target host and -tport = target port): - -var proxy = require('./ws2tcp.js'); -proxy.ws2tcp(lport, thost, tport); - -For talking to the C++ broker unfortunately proxying is currently the only option -as qpidd does not have a WebSocket transport. - -Option 2. The Java Broker's WebSocket transport. -Recent releases of the Qpid Java Broker provide a native WebSocket transport which -means that the JavaScript binding can talk to it with no additional requirements. -It is necessary to configure the Java Broker as the WebSocket transport is not -enabled by default. In <qpid-work>/config.json in the "ports" array you need to add: - -{ - "authenticationProvider" : "passwordFile", - "name" : "AMQP-WS", - "port" : "5673", - "transports" : [ "WS" ] -} - -This sets the JavaBroker to listen on WebSocket port 5673 similar to the proxy. - - -One gotcha that still bites the author *** DO NOT FORGET *** that you will be -using ports that you are not used to!! If you are not connecting check that the -proxy is running and that you are specifying the right ports. I still mess up :-( - -WebRTC Transport -================ - -A WebRTC Transport is supported by emscripten, though the author has not tried it. -If you wan to play with this you are very much on your own at the moment YMMV. - -This is configured by adding to the LINK_FLAGS in CMakeLists.txt --s \"SOCKET_WEBRTC=1\" - - /* WebRTC sockets supports several options on the Module object. - - * Module['host']: true if this peer is hosting, false otherwise - * Module['webrtc']['broker']: hostname for the p2p broker that this peer should use - * Module['webrtc']['session']: p2p session for that this peer will join, or undefined if this peer is hosting - * Module['webrtc']['hostOptions']: options to pass into p2p library if this peer is hosting - * Module['webrtc']['onpeer']: function(peer, route), invoked when this peer is ready to connect - * Module['webrtc']['onconnect']: function(peer), invoked when a new peer connection is ready - * Module['webrtc']['ondisconnect']: function(peer), invoked when an existing connection is closed - * Module['webrtc']['onerror']: function(error), invoked when an error occurs - */ - -If you wanted to play with these you'd likely have to tweak the module.js code in -<proton>/proton-c/bindings/javascript - -The emscripten documentation is a bit light on the WebRTC Transport too, though - -emscripten/tests/test_sockets.py -emscripten/tests/sockets/webrtc_host.c -emscripten/tests/sockets/webrtc_peer.c -emscripten/tests/sockets/p2p/broker/p2p-broker.js -emscripten/tests/sockets/p2p/client/p2p-client.js - -Look like they provide a starting point. -Very much TODO...... - - -Creating The Bindings -===================== - -To generate the JavaScript bindings we actually cross-compile from proton-c - -You will need to have emscripten (https://github.com/kripken/emscripten) installed -to do the cross-compilation and in addition you will require a few things that -emscripten itself depends upon. - -http://kripken.github.io/emscripten-site/docs/building_from_source/index.html#installing-from-source -http://kripken.github.io/emscripten-site/docs/building_from_source/toolchain_what_is_needed.html -provide instructions for installing emscripten and the "fastcomp" LLVM backend. -This approach lets users use the "bleeding edge" version of emscripten on the -"incoming" branch (pretty much analogous to building qpid/proton off svn trunk). -This is the approach that the author of the JavaScript Bindings tends to use. - - -http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html -provides some fairly easy to follow instructions for getting started on several -platforms the main dependencies are as follows (on Windows the SDK includes these): - -* The Emscripten code, from github (git clone git://github.com/kripken/emscripten.git). -* LLVM with Clang. Emscripten uses LLVM and Clang, but at the moment the JavaScript - back-end for LLVM is off on a branch so you can't use a stock LLVM/Clang. - http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html - http://kripken.github.io/emscripten-site/docs/building_from_source/building_fastcomp_manually_from_source.html#building-fastcomp-from-source - has lots of explanation and some easy to follow instructions for downloading - and building fastcomp -* Node.js (0.8 or above; 0.10.17 or above to run websocket-using servers in node) -* Python 2.7.3 -* Java is required in order to use the Closure Compiler to minify the code. - - -If you haven't run Emscripten before it's a good idea to have a play with the -tutorial here: -http://kripken.github.io/emscripten-site/docs/getting_started/Tutorial.html - - - -when you are all set up with emscripten and have got the basic tests in the -tutorial running building Proton should be simple, simply go to the Proton root -directory and follow the main instructions in the README there, in precis (from -the root directory) it's: - - mkdir build - cd build - cmake .. - make - -and you should be all set, to test it's all working do (from the build directory): - cd proton-c/bindings/javascript/examples - - node recv-async.js - -in one window and - - node send-async.js - -in another. - -These examples are actually JavaScript applications that have been directly -compiled from recv-async.c and send-async.c in <proton>/examples/messenger/c -if you'd prefer to write applications in C and compile them to JavaScript that -is a perfectly valid approach and these examples provide a reasonable starting -point for doing so. - -Documentation -============= - -When you've successfully got a working build do: - - make docs - -Which will make all of the proton documentation including the JavaScript docs. -If successful the JSDoc generated documentation should be found here: - -<proton>/build/proton-c/bindings/javascript/html/index.html - - -Using "native" JavaScript -========================= - -The examples in <proton>/examples/messenger/javascript are the best starting point. - -In practice the examples follow a fairly similar pattern to the Python bindings -the most important thing to bear in mind though is that JavaScript is completely -asynchronous/non-blocking, which can catch the unwary. - -An application follows the following (rough) steps: - -1. (optional) Set the heap size. -It's important to realise that most of the library code is compiled C code and -the runtime uses a "virtual heap" to support the underlying malloc/free. This is -implemented internally as an ArrayBuffer with a default size of 16777216. - -To allocate a larger heap an application must set the PROTON_TOTAL_MEMORY global. -In Node.js this would look like (see send.js): -PROTON_TOTAL_MEMORY = 50000000; // Note no var - it needs to be global. - -In a browser it would look like (see send.html): -<script type="text/javascript">PROTON_TOTAL_MEMORY = 50000000;</script> - -2. Load the library and create a message and messenger. -In Node.js this would look like (see send.js): -var proton = require("qpid-proton-messenger"); -var message = new proton.Message(); -var messenger = new proton.Messenger(); - -In a browser it would look like (see send.html): -<script type="text/javascript" src="../../../node_modules/qpid-proton-messenger/lib/proton-messenger.js"></script> - -<script type="text/javascript"> -var message = new proton.Message(); -var messenger = new proton.Messenger(); -.... - -3. Set up event handlers as necessary. - -messenger.on('error', <error callback>); -messenger.on('work', <work callback>); -messenger.on('subscription', <subscription callback>); - - -The work callback is triggered on WebSocket events, so in general you would use -this to send and receive messages, for example in recv.js we have: - -var pumpData = function() { - while (messenger.incoming()) { - var t = messenger.get(message); - - console.log("Address: " + message.getAddress()); - console.log("Subject: " + message.getSubject()); - - // body is the body as a native JavaScript Object, useful for most real cases. - //console.log("Content: " + message.body); - - // data is the body as a proton.Data Object, used in this case because - // format() returns exactly the same representation as recv.c - console.log("Content: " + message.data.format()); - - messenger.accept(t); - } -}; - -messenger.on('work', pumpData); - - -The subscription callback is triggered when the address provided in a call to -messenger.subscribe(<address>); - -Gets resolved. An example of its usage can be found in qpid-config.js which is -a fully functioning and complete port of the python qpid-config tool. It also -illustrates how to do asynchronous request/response based applications. - -Aside from the asynchronous aspects the rest of the API is essentially the same -as the Python binding aside from minor things such as camel casing method names etc. - -Serialisation/Deserialisation, Types etc. -========================================= - -The JavaScript binding tries to be as simple, intuitive and natural as possible -so when sending a message all native JavaScript types including Object literals -and Arrays are transparently supported, for example. - -var message = new proton.Message(); -message.setAddress('amqp://localhost'); -message.setSubject('UK.NEWS'); -message.body = ['Rod', 'Jane', 'Freddy', {cat: true, donkey: 'hee haw'}]; - - -The main thing to bear in mind is that (particularly for sending messages) we -may need to use "adapters" to make sure values are correctly interpreted and -encoded to the correct type in the AMQP type system. This is especially important -when interoperating with a peer written in a strongly typed language (C/C++/Java). - -Some examples of available types follow: - -// UUID -message.body = new proton.Data.Uuid(); - -// AMQP Symbol -message.body = new proton.Data.Symbol("My Symbol"); - -// Binary data (created from a gibberish String in this case). -message.body = new proton.Data.Binary("Monkey BathпогÑÐ¾Ð¼Ð·Ñ Ñвбнм"); - -// Binary data (Get a Uint8Array view of the data and directly access that). -message.body = new proton.Data.Binary(4); -var buffer = message.body.getBuffer(); -buffer[0] = 65; -buffer[1] = 77; -buffer[2] = 81; -buffer[3] = 80; - -// Binary Data (Created from an Array, you can use an ArrayBuffer/TypedArray too). -message.body = new proton.Data.Binary([65, 77, 81, 80]); - - -Note that the implementation of proton.Data.Binary tries to minimise copying so -it accesses the internal emscripten heap *directly* this requires memory management -which is mostly handled transparently, but users need to be aware that the -underlying memory is "owned" by the Message Object, so if Binary data needs to -be maintained after the next call to messenger.get(message); it must be -*explicitly* copied. For more detail do "make docs" and see: -<proton>/build/proton-c/bindings/javascript/html/proton.Data.Binary.html - - -// AMQP Described (value, descriptor) -message.body = new proton.Data.Described('persian, 'com.cheezburger.icanhas'); - -// AMQP Timestamp maps to native JavaScript Date. -message.body = new Date(); - -// Various AMQP Array examples. -message.body = new proton.Data.Array('INT', [1, 3, 5, 7], "odd numbers"); -message.body = new proton.Data.Array('UINT', [1, 3, 5, 7], "odd"); -message.body = new proton.Data.Array('ULONG', [1, 3, 5, 7], "odd"); -message.body = new proton.Data.Array('FLOAT', [1, 3, 5, 7], "odd"); -message.body = new proton.Data.Array('STRING', ["1", "3", "5", "7"], "odd"); - -// A JavaScript TypedArray will map directly to and from an AMQP Array of the -// appropriate type (Internally sets a descriptor of 'TypedArray'). -message.body = new Uint8Array([1, 3, 5, 7]); - -// UUID Array -message.body = new proton.Data.Array('UUID', [new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid(), new proton.Data.Uuid()], "unique"); - -// Null -message.body = null; - -// Boolean -message.body = true; - -// Native JavaScript Array maps to an AMQP List -message.body = ['Rod', 'Jane', 'Freddy']; - -// Native JavaScript Object maps to an AMQP Map -message.body = ['Rod', 'Jane', 'Freddy', {cat: true, donkey: 'hee haw'}]; - -// JavaScript only has a "number" type so the binding provides "decorator" -// methods added to the JavaScript Number class. To access this from number -// primitives it is necessary to either use braces or use a "double dot" so that -// the interpreter can disambiguate from a simple decimal point. The binding will -// attempt to use the correct type such that message.body = 2147483647; would be -// sent as an AMQP integer, but because of the way JavaScript coerces integers -// message.body = 2147483647.0; would also be sent as an AMQP integer because -// 2147483647.0 gets transparently conveted to 2147483647 by the interpreter, so -// to explicitly send this as an AMQP float we'd need to do: -// message.body = 2147483647.0.float(); - -// Some more number examples: -message.body = 66..char(); // char - note double dot. (66).char(); works too. -message.body = 2147483647; // int -message.body = -2147483649; // long -message.body = 12147483649; // long -message.body = (12147483649).long(); // long -message.body = (17223372036854778000).ulong(); // ulong -message.body = (121474.836490).float(); // float -message.body = 12147483649.0.float(); // float -message.body = (4294967296).uint(); // uint -message.body = (255).ubyte(); // ubyte - -Note too that floats are subject to a loss of precision - - -Fortunately most of these quirks only affect serialisation.when the binding -receives a message it will attempt to decode it into the most "natural" native -JavaScript type. - - -One additional decoding "quirk" can be caused by C++ qpid::messaging clients. It -is unfortunately quite common for C++ clients to incorrectly encode Strings as -AMQP Binary by neglecting to provide an encoding. The QMF Management Agent is one -such culprit. This is a bit of a pain, especially because of proton.Data.Binary -memory management quirks and having to remember to explicitly copy the data -on each call to messenger.get(message); In order to cater for this an overloaded -messenger.get(message, true); has been provided. Setting the second parameter to -true forces any received Binary payloads to be decoded as Strings. If you know -that producers might behave in this way and you are not expecting any "real" -Binary data from the producer this convenience mechanism results in nice clean -JavaScript Objects being received and is extremely useful for things like QMF. - -JSON -==== - -As well as allowing native JavaScript Objects and Arrays to be transparently -serialised and deserialised via the AMQP type system it is also possible to -serialise/deserialise as JSON. - -message.setAddress('amqp://localhost'); -message.setContentType('application/json'); -message.body = {array: [1, 2, 3, 4], object: {name: "John Smith", age: 65}}; - -On the wire the above will be encoded as an opaque binary in an AMQP data section -but will be deserialised into a JavaScript Object in exactly the same was as the -previous examples that use the AMQP type system. - -SUPPORT -======= - -To report bugs in the bindings, or to request an enhancement, please file -a tracker request: - - https://issues.apache.org/jira/browse/PROTON - -The main support channel is the qpid-users mailing list, see: - - http://qpid.apache.org/discussion.html#mailing-lists - -You can also directly interact with the development team and other users -in the #qpid channel on irc.freenode.net. - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/TODO ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/TODO b/proton-c/bindings/javascript/TODO deleted file mode 100644 index 81d5e9e..0000000 --- a/proton-c/bindings/javascript/TODO +++ /dev/null @@ -1,49 +0,0 @@ -Qpid Proton JavaScript Language Bindings TODO List -================================================== - -Network code is currently limited to a WebSocket transport, including for Node.js -It would be good to allow a configurable transport so that Node.js and Chrome -packaged apps could use native TCP sockets. - -The JavaScript binding is pure JavaScript, which has been trans-compiled from C -to JavaScript using emscripten. This allows the same code to be used in a browser -and Node.js, but it potentially has a performance penalty in Node.js. An alternative -for Node.js might be to build a SWIG binding (recent versions of SWIG support -JavaScript). This should be viewed as a complementary not competing approach as -it would only work for environments like Node.js and definitely *not* browser -environments, which clearly require pure JavaScript. - -Optimisation are enabled for compiling and linking but there hasn't been any -profiling done yet. The binding code *shouldn't* be the bottleneck but it's -always possible that I messed up. - -Error handling is nowhere near as good as it should be, though this is mostly -because Messenger itself is a bit lacking on the error handling/recovery front. - -Although described as "Proton" this is currently a JavaScript binding for Messenger -and associated Message & Data classes. There has been some talk on the user list -of an alternative reactive API based on proton Engine. This might ultimately be -a better fit for JavaScript but it is very much in its infancy and I haven't -really looked at it yet. - -proton-j seems to use hawt-dispatch, which is modelled after Grand Central -Dispatch so I need to work out what it's using it do do and whether there are -parallels in proton-c - -Although the WebSocket transport uses the sub-protocol 'AMQPWSB10' as specified -in http://docs.oasis-open.org/amqp-bindmap/amqp-wsb/v1.0/amqp-wsb-v1.0.html -section 2.1 it is not technically compliant with the spec. as the AMQP data is -created by the proton-c code, which produces a data-stream for the TCP transport -whereas the WebSocket spec. seems to want to make use of the fact that WebSocket -is a frame based transport (whereas TCP is not). This is quite hard to resolve -as the binding simply sends the contents of the octet buffer created by proton -over the transport and thus to make this binding compliant with the spec. would -require a change to the underlying proton-c code! It is possible that this may be -done in future as SCTP support would require the ability to push AMQP frames too. -In the mean time fortunately the Java Broker WebSocket transport is actually -tolerant of this off-spec. behaviour. My personal view is that both approaches -should be valid and in particular using the standard TCP framing means that it -is straightforward to create WebSocket<->TCP proxies, which is useful given that -only the Java Broker currently has a native WebSocket transport. - - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/binding-close.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/binding-close.js b/proton-c/bindings/javascript/binding-close.js deleted file mode 100644 index 07b68c2..0000000 --- a/proton-c/bindings/javascript/binding-close.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/** - * These values are essentially constants sitting in the proton namespace - * that is to say they will be exported via: - * proton.VERSION_MAJOR - * proton.VERSION_MINOR - * We have to set them after pn_get_version_major/pn_get_version_minor have been - * defined so we must do it here in binding-close.js as it's a --post-js block. - */ -Module['VERSION_MAJOR'] = _pn_get_version_major(); -Module['VERSION_MINOR'] = _pn_get_version_minor(); - -})(); // End of self calling lambda used to wrap library. - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/binding-open.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/binding-open.js b/proton-c/bindings/javascript/binding-open.js deleted file mode 100644 index 40e1b12..0000000 --- a/proton-c/bindings/javascript/binding-open.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -(function() { // Start of self-calling lambda used to avoid polluting global namespace. http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/binding.c ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/binding.c b/proton-c/bindings/javascript/binding.c deleted file mode 100644 index 8da83f6..0000000 --- a/proton-c/bindings/javascript/binding.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/* - * This file is largely just a stub, we're actually creating a JavaScript library - * rather than an executable so most of the work is done at the link stage. - * We do however need to link the libqpid-proton-bitcode.so with *something* and - * this is it. This file also provides a way to pass any global variable or - * #defined values to the JavaScript binding by providing wrapper functions. - */ -#include <uuid/uuid.h> -#include <stdio.h> -#include <proton/version.h> - -// To access #define values in JavaScript we need to wrap them in a function. -int pn_get_version_major() {return PN_VERSION_MAJOR;} -int pn_get_version_minor() {return PN_VERSION_MINOR;} -void pn_uuid_generate(uuid_t out) { uuid_generate(out); } - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-array.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-array.js b/proton-c/bindings/javascript/data-array.js deleted file mode 100644 index 6f9776d..0000000 --- a/proton-c/bindings/javascript/data-array.js +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.Array */ -/* */ -/*****************************************************************************/ - -/** - * TODO make this behave more like a native JavaScript Array: http://www.bennadel.com/blog/2292-extending-javascript-arrays-while-keeping-native-bracket-notation-functionality.htm - * Create a proton.Data.Array. - * @classdesc - * This class represents an AMQP Array. - * @constructor proton.Data.Array - * @param {string|number} type the type of the Number either as a string or number. - * Stored internally as a string corresponding to one of the TypeNames. - * @param {Array|TypedArray} elements the Native JavaScript Array or TypedArray that we wish to serialise. - * @param {object} descriptor an optional object describing the type. - */ -Data['Array'] = function(type, elements, descriptor) { // Data.Array Constructor. - // This block caters for an empty Array or a Described empty Array. - if (arguments.length < 2) { - descriptor = type; - type = 'NULL'; - elements = []; - } - - this['type'] = (typeof type === 'number') ? Data['TypeNames'][type] : type; - this['elements'] = elements; - this['descriptor'] = descriptor; -}; - -/** - * @method toString - * @memberof! proton.Data.Array# - * @returns {string} the String form of a {@link proton.Data.Array}. - */ -Data['Array'].prototype.toString = function() { - var descriptor = (this['descriptor'] == null) ? '' : ':' + this['descriptor']; - return this['type'] + 'Array' + descriptor + '[' + this['elements'] + ']'; -}; - -/** - * @method valueOf - * @memberof! proton.Data.Array# - * @returns {Array} the elements of the {@link proton.Data.Array}. - */ -Data['Array'].prototype.valueOf = function() { - return this['elements']; -}; - -/** - * Compare two instances of proton.Data.Array for equality. N.B. this method - * compares the value of every Array element so its performance is O(n). - * @method equals - * @memberof! proton.Data.Array# - * @param {proton.Data.Array} rhs the instance we wish to compare this instance with. - * @returns {boolean} true iff the two compared instances are equal. - */ -Data['Array'].prototype['equals'] = function(rhs) { - if (rhs instanceof Data['Array'] && - // Check the string value of the descriptors. - (('' + this['descriptor']) === ('' + rhs['descriptor'])) && - (this['type'] === rhs['type'])) { - var elements = this['elements']; - var relements = rhs['elements']; - var length = elements.length; - if (length === relements.length) { - for (var i = 0; i < length; i++) { - if (elements[i].valueOf() !== relements[i].valueOf()) { - return false; - } - } - return true; - } else { - return false; - } - } else { - return false; - } -}; - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-binary.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-binary.js b/proton-c/bindings/javascript/data-binary.js deleted file mode 100644 index 27bac59..0000000 --- a/proton-c/bindings/javascript/data-binary.js +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.Binary */ -/* */ -/*****************************************************************************/ - -/** - * Create a proton.Data.Binary. This constructor takes one or two parameters. - * The first parameter may serve different purposes depending on its type; - * If value is a number then it represents the size of the Binary data buffer, - * if it is a string then we copy the string to the buffer, if it is an Array - * or a TypedArray then we copy the data to the buffer. The optional second - * parameter is a pointer to the data in an internal data store. If start is - * not specified then the number of bytes specified in the first parameter - * will be allocated in the internal data store and start will point to the - * start of that block of data. - * @classdesc - * This class represents an AMQP Binary type. This class allows us to create and - * use raw binary data and map it efficiently between JavaScript client code and - * the underlying implementation, where all data is managed on a "virtual heap". - * <p> - * Client applications should generally not have to care about memory management - * as, for most common use cases, client applications would "transfer ownership" - * to a "container" which would then "own" the underlying data and free the data - * held by the {@link proton.Data.Binary}. - * <p> - * As an example one common use-case would be where client application creates a - * {@link proton.Data.Binary} specifying the required size. It would usually then - * call getBuffer() to access the underlying Uint8Array. At this point the client - * "owns" the data and so would have to call free() if it did nothing more with - * the Binary, however when {@link proton.Data.putBINARY} is called the ownership - * of the raw data on the virtual heap transfers from the Binary to the Data and - * the client no longer needs to call free() itself. In this case the putBINARY() - * call transfers ownership and can then safely call free() on the Binary. - * <p> - * Conversely a common use-case when receiving data is where a Binary may be - * created by {@link proton.Data#getBINARY}. In this case the Binary is simply a - * "view" onto the bytes owned by the Data instance. A client application can - * safely access the bytes from the view, but if it wishes to use the bytes beyond - * the scope of the Data instance (e.g. after the next {@link proton.Messenger#get} - * call then the client must explicitly *copy* the bytes into a new buffer, for - * example via copyBuffer(). - * <p> - * Most of the {@link proton.Data} methods that take {@link proton.Data.Binary} - * as a parameter "consume" the underlying data and take responsibility for - * freeing it from the heap e.g. {@link proton.Data#putBINARY}, {@link proton.Data#decode}. - * For the methods that return a {@link proton.Data.Binary} the call to - * {@link proton.Data#getBINARY}, which is the most common case, returns a Binary - * that has a "view" of the underlying data that is actually owned by the Data - * instance and thus doesn't need to be explicitly freed on the Binary. The call - * to {@link proton.Data#encode} however returns a Binary that represents a *copy* - * of the underlying data, in this case (like a client calling new proton.Data.Binary) - * the client takes responsibility for freeing the data, unless of course it is - * subsequently passed to a method that will consume the data (putBINARY/decode). - * @constructor proton.Data.Binary - * @param {(number|string|Array|TypedArray)} value If value is a number then it - * represents the size of the Binary data buffer, if it is a string then - * we copy the string to the buffer, if it is an Array or a TypedArray - * then we copy the data to the buffer. N.B. although convenient do bear - * in mind that using a mechanism other than constructing with a simple - * size will result in some form of additional data copy. - * @param {number} start an optional pointer to the start of the Binary data buffer. - */ -Data['Binary'] = function(value, start) { // Data.Binary Constructor. - /** - * If the start pointer is specified then the underlying binary data is owned - * by another object, so we set the call to free to be a null function. If - * the start pointer is not passed then we allocate storage of the specified - * size on the emscripten heap and set the call to free to free the data from - * the emscripten heap. - */ - var size = value; - if (start) { - this['free'] = function() {}; - } else { // Create Binary from Array, ArrayBuffer or TypedArray. - var hasArrayBuffer = (typeof ArrayBuffer === 'function'); - if (Data.isArray(value) || - (hasArrayBuffer && value instanceof ArrayBuffer) || - (value.buffer && hasArrayBuffer && value.buffer instanceof ArrayBuffer)) { - value = new Uint8Array(value); - size = value.length; - start = _malloc(size); // Allocate storage from emscripten heap. - Module['HEAPU8'].set(value, start); // Copy the data to the emscripten heap. - } else if (Data.isString(value)) { // Create Binary from native string - value = unescape(encodeURIComponent(value)); // Create a C-like UTF representation. - size = value.length; - start = _malloc(size); // Allocate storage from emscripten heap. - for (var i = 0; i < size; i++) { - setValue(start + i, value.charCodeAt(i), 'i8', 1); - } - } else { // Create unpopulated Binary of specified size. - // If the type is not a number by this point then an unrecognised data - // type has been passed so we create a zero length Binary. - size = Data.isNumber(size) ? size : 0; - start = _malloc(size); // Allocate storage from emscripten heap. - } - this['free'] = function() { - _free(this.start); - this.size = 0; - this.start = 0; - // Set free to a null function to prevent possibility of a "double free". - this['free'] = function() {}; - }; - } - - this.size = size; - this.start = start; -}; - -/** - * Get a Uint8Array view of the data. N.B. this is just a *view* of the data, - * which will go out of scope on the next call to {@link proton.Messenger.get}. If - * a client wants to retain the data then copy should be used to explicitly - * create a copy of the data which the client then owns to do with as it wishes. - * @method getBuffer - * @returns {Uint8Array} a new Uint8Array view of the data. - * @memberof! proton.Data.Binary# - */ -Data['Binary'].prototype['getBuffer'] = function() { - return new Uint8Array(HEAPU8.buffer, this.start, this.size); -}; - -/** - * Explicitly create a *copy* of the Binary, copying the underlying binary data too. - * @method copy - * @param {number} offset an optional offset into the underlying buffer from - * where we want to copy the data, default is zero. - * @param {number} n an optional number of bytes to copy, default is this.size - offset. - * @returns {proton.Data.Binary} a new {@link proton.Data.Binary} created by copying the underlying binary data. - * @memberof! proton.Data.Binary# - */ -Data['Binary'].prototype['copy'] = function(offset, n) { - offset = offset | 0; - n = n ? n : (this.size - offset); - - if (offset >= this.size) { - offset = 0; - n = 0; - } else if ((offset + n) > this.size) { - n = this.size - offset; // Clamp length - } - - var start = _malloc(n); // Allocate storage from emscripten heap. - _memcpy(start, this.start + offset, n); // Copy the raw data to new buffer. - - return new Data['Binary'](n, start); -}; - -/** - * Converts the {@link proton.Data.Binary} to a string. This is clearly most - * useful when the binary data is actually a binary representation of a string - * such as a C style ASCII string. - * @method toString - * @memberof! proton.Data.Binary# - * @returns {string} the String form of a {@link proton.Data.Binary}. - */ -Data['Binary'].prototype.toString = Data['Binary'].prototype.valueOf = function() { - // Create a native JavaScript String from the start/size information. - return Pointer_stringify(this.start, this.size); -}; - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-described.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-described.js b/proton-c/bindings/javascript/data-described.js deleted file mode 100644 index e1f9d84..0000000 --- a/proton-c/bindings/javascript/data-described.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.Described */ -/* */ -/*****************************************************************************/ - -/** - * Create a proton.Data.Described. - * @classdesc - * This class represents an AMQP Described. - * @constructor proton.Data.Described - * @param {object} value the value of the described type. - * @param {string} descriptor an optional string describing the type. - * @property {object} value the actual value of the described type. - * @property {string} descriptor a string describing the type. - */ -Data['Described'] = function(value, descriptor) { // Data.Described Constructor. - this['value'] = value; - this['descriptor'] = descriptor; -}; - -/** - * @method toString - * @memberof! proton.Data.Described# - * @returns {string} the String form of a {@link proton.Data.Described}. - */ -Data['Described'].prototype.toString = function() { - return 'Described(' + this['value'] + ', ' + this['descriptor'] + ')'; -}; - -/** - * @method valueOf - * @memberof! proton.Data.Described# - * @returns {object} the value of the {@link proton.Data.Described}. - */ -Data['Described'].prototype.valueOf = function() { - return this['value']; -}; - -/** - * Compare two instances of proton.Data.Described for equality. - * @method equals - * @memberof! proton.Data.Described# - * @param {proton.Data.Described} rhs the instance we wish to compare this instance with. - * @returns {boolean} true iff the two compared instances are equal. - */ -Data['Described'].prototype['equals'] = function(rhs) { - if (rhs instanceof Data['Described']) { - return ((this['descriptor'] === rhs['descriptor']) && (this['value'] === rhs['value'])); - } else { - return false; - } -}; - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-long.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-long.js b/proton-c/bindings/javascript/data-long.js deleted file mode 100644 index 38fb6c8..0000000 --- a/proton-c/bindings/javascript/data-long.js +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.Long */ -/* */ -/*****************************************************************************/ - -/** - * Create a proton.Data.Long. - * @classdesc - * This class represents a 64 bit Integer value. It is used primarily to pass and - * return 64 bit Integer values to and from the emscripten compiled proton-c library. - * This class is needed because JavaScript cannot natively represent 64 bit - * Integers with sufficient accuracy. - * @constructor proton.Data.Long - * @param {number} low the least significant word. - * @param {number} high the most significant word. - */ -// Use dot notation as it is a "protected" inner class not exported from the closure. -Data.Long = function(low, high) { // Data.Long Constructor. - this.low = low | 0; // force into 32 signed bits. - this.high = high | 0; // force into 32 signed bits. -}; - -// proton.Data.Long constants. -Data.Long.TWO_PWR_16_DBL_ = 1 << 16; -Data.Long.TWO_PWR_32_DBL_ = Data.Long.TWO_PWR_16_DBL_ * Data.Long.TWO_PWR_16_DBL_; -Data.Long.TWO_PWR_64_DBL_ = Data.Long.TWO_PWR_32_DBL_ * Data.Long.TWO_PWR_32_DBL_; -Data.Long.TWO_PWR_63_DBL_ = Data.Long.TWO_PWR_64_DBL_ / 2; -Data.Long.MAX_VALUE = new Data.Long(0xFFFFFFFF | 0, 0x7FFFFFFF | 0); -Data.Long.MIN_VALUE = new Data.Long(0, 0x80000000 | 0); -Data.Long.ZERO = new Data.Long(0, 0); -Data.Long.ONE = new Data.Long(1, 0); - -/** - * @method fromNumber - * @memberof! proton.Data.Long# - * @returns {proton.Data.Long} an instance of {@link proton.Data.Long} created - * using a native JavaScript number. - */ -Data.Long.fromNumber = function(value) { - if (isNaN(value) || !isFinite(value)) { - return Data.Long.ZERO; - } else if (value <= -Data.Long.TWO_PWR_63_DBL_) { - return Data.Long.MIN_VALUE; - } else if (value + 1 >= Data.Long.TWO_PWR_63_DBL_) { - return Data.Long.MAX_VALUE; - } else if (value < 0) { - return Data.Long.fromNumber(-value).negate(); - } else { - return new Data.Long( - (value % Data.Long.TWO_PWR_32_DBL_) | 0, - (value / Data.Long.TWO_PWR_32_DBL_) | 0); - } -}; - -/** - * Return the twos complement of this instance. - * @method negate - * @memberof! proton.Data.Long# - * @returns {proton.Data.Long} the twos complement of this instance. - */ -Data.Long.prototype.negate = function() { - if (this.equals(Data.Long.MIN_VALUE)) { - return Data.Long.MIN_VALUE; - } else { - return this.not().add(Data.Long.ONE); - } -}; - -/** - * Add two instances of {@link proton.Data.Long}. - * @method add - * @memberof! proton.Data.Long# - * @param {proton.Data.Long} rhs the instance we wish to add to this instance. - * @returns {proton.Data.Long} the sum of this value and the rhs. - */ -Data.Long.prototype.add = function(rhs) { - // Divide each number into 4 chunks of 16 bits, and then sum the chunks. - - var a48 = this.high >>> 16; - var a32 = this.high & 0xFFFF; - var a16 = this.low >>> 16; - var a00 = this.low & 0xFFFF; - - var b48 = rhs.high >>> 16; - var b32 = rhs.high & 0xFFFF; - var b16 = rhs.low >>> 16; - var b00 = rhs.low & 0xFFFF; - - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 + b48; - c48 &= 0xFFFF; - return new Data.Long((c16 << 16) | c00, (c48 << 16) | c32); -}; - -/** - * Return the complement of this instance. - * @method not - * @memberof! proton.Data.Long# - * @returns {proton.Data.Long} the complement of this instance. - */ -Data.Long.prototype.not = function() { - return new Data.Long(~this.low, ~this.high); -}; - -/** - * Compare two instances of {@link proton.Data.Long} for equality. - * @method equals - * @memberof! proton.Data.Long# - * @param {proton.Data.Long} rhs the instance we wish to compare this instance with. - * @returns {boolean} true iff the two compared instances are equal. - */ -Data.Long.prototype.equals = function(other) { - return (this.high == other.high) && (this.low == other.low); -}; - -/** - * @method getHighBits - * @memberof! proton.Data.Long# - * @returns {number} the most significant word of a {@link proton.Data.Long}. - */ -Data.Long.prototype.getHighBits = function() { - return this.high; -}; - -/** - * @method getLowBits - * @memberof! proton.Data.Long# - * @returns {number} the least significant word of a {@link proton.Data.Long}. - */ -Data.Long.prototype.getLowBits = function() { - return this.low; -}; - -/** - * @method getLowBitsUnsigned - * @memberof! proton.Data.Long# - * @returns {number} the least significant word of a {@link proton.Data.Long} - * as an unsigned value. - */ -Data.Long.prototype.getLowBitsUnsigned = function() { - return (this.low >= 0) ? this.low : Data.Long.TWO_PWR_32_DBL_ + this.low; -}; - -/** - * @method toNumber - * @memberof! proton.Data.Long# - * @returns {number} a native JavaScript number (with possible loss of precision). - */ -Data.Long.prototype.toNumber = function() { - return (this.high * Data.Long.TWO_PWR_32_DBL_) + this.getLowBitsUnsigned(); -}; - -/** - * @method toString - * @memberof! proton.Data.Long# - * @returns {string} the String form of a {@link proton.Data.Long}. - */ -Data.Long.prototype.toString = function() { - return this.high + ':' + this.getLowBitsUnsigned(); -}; - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-symbol.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-symbol.js b/proton-c/bindings/javascript/data-symbol.js deleted file mode 100644 index c742acb..0000000 --- a/proton-c/bindings/javascript/data-symbol.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.Symbol */ -/* */ -/*****************************************************************************/ - -/** - * Create a proton.Data.Symbol. - * @classdesc - * This class represents an AMQP Symbol. This class is necessary primarily as a - * way to enable us to distinguish between a native String and a Symbol in the - * JavaScript type system. - * @constructor proton.Data.Symbol - * @param {string} s a symbol. - */ -Data['Symbol'] = function(s) { // Data.Symbol Constructor. - this.value = s; -}; - -/** - * @method toString - * @memberof! proton.Data.Symbol# - * @returns {string} the String form of a {@link proton.Data.Symbol}. - */ -Data['Symbol'].prototype.toString = Data['Symbol'].prototype.valueOf = function() { - return this.value; -}; - -/** - * Compare two instances of proton.Data.Symbol for equality. - * @method equals - * @memberof! proton.Data.Symbol# - * @param {proton.Data.Symbol} rhs the instance we wish to compare this instance with. - * @returns {boolean} true iff the two compared instances are equal. - */ -Data['Symbol'].prototype['equals'] = function(rhs) { - return this.toString() === rhs.toString(); -}; - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-typed-number.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-typed-number.js b/proton-c/bindings/javascript/data-typed-number.js deleted file mode 100644 index 034d4ec..0000000 --- a/proton-c/bindings/javascript/data-typed-number.js +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.TypedNumber */ -/* */ -/*****************************************************************************/ - -// ---------------------- JavaScript Number Extensions ------------------------ - -Number.prototype['ubyte'] = function() { - return new Data.TypedNumber('UBYTE', this); -}; - -Number.prototype['byte'] = function() { - return new Data.TypedNumber('BYTE', this); -}; - -Number.prototype['ushort'] = function() { - return new Data.TypedNumber('USHORT', this); -}; - -Number.prototype['short'] = function() { - return new Data.TypedNumber('SHORT', this); -}; - -Number.prototype['uint'] = function() { - return new Data.TypedNumber('UINT', this); -}; - -Number.prototype['int'] = function() { - return new Data.TypedNumber('INT', this); -}; - -Number.prototype['ulong'] = function() { - return new Data.TypedNumber('ULONG', this); -}; - -Number.prototype['long'] = function() { - return new Data.TypedNumber('LONG', this); -}; - -Number.prototype['float'] = function() { - return new Data.TypedNumber('FLOAT', this); -}; - -Number.prototype['double'] = function() { - return new Data.TypedNumber('DOUBLE', this); -}; - -Number.prototype['char'] = function() { - return new Data.TypedNumber('CHAR', this); -}; - -String.prototype['char'] = function() { - return new Data.TypedNumber('CHAR', this.charCodeAt(0)); -}; - -// ------------------------- proton.Data.TypedNumber -------------------------- -/** - * Create a proton.Data.TypedNumber. - * @classdesc - * This class is a simple wrapper class that allows a "type" to be recorded for - * a number. The idea is that the JavaScript Number class is extended with extra - * methods to allow numbers to be "modified" to TypedNumbers, so for example - * 1.0.float() would modify 1.0 by returning a TypedNumber with type = FLOAT - * and value = 1. The strings used for type correspond to the names of the Data - * put* methods e.g. UBYTE, BYTE, USHORT, SHORT, UINT, INT, ULONG, LONG, FLOAT, - * DOUBLE, CHAR so that the correct method to call can be derived from the type. - * @constructor proton.Data.TypedNumber - * @param {(string|number)} type the type of the Number either as a string or number. - * Stored internally as a string corresponding to one of the TypeNames. - * @param {number} value the value of the Number. - */ -// Use dot notation as it is a "protected" inner class not exported from the closure. -Data.TypedNumber = function(type, value) { // Data.TypedNumber Constructor. - this.type = (typeof type === 'number') ? Data['TypeNames'][type] : type; - this.value = value; -}; - -/** - * @method toString - * @memberof! proton.Data.TypedNumber# - * @returns {string} the String form of a {@link proton.Data.TypedNumber}. - */ -Data.TypedNumber.prototype.toString = Data.TypedNumber.prototype.valueOf = function() { - return +this.value; -}; - - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/javascript/data-uuid.js ---------------------------------------------------------------------- diff --git a/proton-c/bindings/javascript/data-uuid.js b/proton-c/bindings/javascript/data-uuid.js deleted file mode 100644 index 4fee84a..0000000 --- a/proton-c/bindings/javascript/data-uuid.js +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/*****************************************************************************/ -/* */ -/* proton.Data.Uuid */ -/* */ -/*****************************************************************************/ - -/** - * Create a proton.Data.Uuid which is a type 4 UUID. - * @classdesc - * This class represents a type 4 UUID, wich may use crypto libraries to generate - * the UUID if supported by the platform (e.g. node.js or a modern browser) - * @constructor proton.Data.Uuid - * @param {number|Array|string} u a UUID. If null a type 4 UUID is generated wich may use crypto if - * supported by the platform. If u is an emscripten "pointer" we copy the - * data from that. If u is a JavaScript Array we use it as-is. If u is a - * String then we try to parse that as a UUID. - * @property {Array} uuid is the compact array form of the UUID. - */ -Data['Uuid'] = function(u) { // Data.Uuid Constructor. - // Helper to copy from emscriptem allocated storage into JavaScript Array. - function _p2a(p) { - var uuid = new Array(16); - for (var i = 0; i < 16; i++) { - uuid[i] = getValue(p + i, 'i8') & 0xFF; // & 0xFF converts to unsigned. - } - return uuid; - }; - - if (!u) { // Generate UUID using emscriptem's uuid_generate implementation. - var sp = Runtime.stackSave(); - var p = allocate(16, 'i8', ALLOC_STACK); // Create temporary pointer storage. - _uuid_generate(p); // Generate UUID into allocated pointer. - this['uuid'] = _p2a(p); // Copy from allocated storage into JavaScript Array. - Runtime.stackRestore(sp); - } else if (Data.isNumber(u)) { // Use pointer that has been passed in. - this['uuid'] = _p2a(u); // Copy from allocated storage into JavaScript Array. - } else if (Data.isArray(u)) { // Use array that has been passed in. - this['uuid'] = u; // Just use the JavaScript Array. - } else if (Data.isString(u)) { // Parse String form UUID. - if (u.length === 36) { - var i = 0; - var uuid = new Array(16); - u.toLowerCase().replace(/[0-9a-f]{2}/g, function(byte) { - if (i < 16) { - uuid[i++] = parseInt(byte, 16); - } - }); - this['uuid'] = uuid; - } - } - this.string = null; -}; - -/** - * Returns the string representation of the proton.Data.Uuid. - * @method toString - * @memberof! proton.Data.Uuid# - * @returns {string} the String - * /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/ - * form of a {@link proton.Data.Uuid}. - */ -Data['Uuid'].prototype.toString = Data['Uuid'].prototype.valueOf = function() { - if (!this.string) { // Check if we've cached the string version. - var i = 0; - var uu = this['uuid']; - var uuid = 'xxxx-xx-xx-xx-xxxxxx'.replace(/[x]/g, function(c) { - var r = uu[i].toString(16); - r = (r.length === 1) ? '0' + r : r; // Zero pad single digit hex values - i++; - return r; - }); - this.string = uuid; - } - return this.string; -}; - -/** - * Compare two instances of proton.Data.Uuid for equality. - * @method equals - * @memberof! proton.Data.Uuid# - * @param {proton.Data.Uuid} rhs the instance we wish to compare this instance with. - * @returns {boolean} true iff the two compared instances are equal. - */ -Data['Uuid'].prototype['equals'] = function(rhs) { - return this.toString() === rhs.toString(); -}; - --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
