Read/write XDR encoded data structures (RFC 4506)
npm install --save js-xdr
You can find some examples here.
First, let's import the library:
var xdr = require('js-xdr');
Now, let's look at how to decode some primitive types:
There are a couple of caveats to be aware of with this library:
- We do not support quadruple precision floating point values. Attempting to read or write these values will throw errors.
- NaN is not handled perfectly for floats and doubles. There are several forms of NaN as defined by IEEE754 and the browser polyfill for node's Buffer class seems to handle them poorly.
See js-stellar-base for an example (check out the src/generated directory)
Please see CONTRIBUTING.md for details.
To develop and test js-xdr itself
- Clone the repo
git clone https://github.com/stellar/js-xdr.git
- Install dependencies inside js-xdr folder
cd js-xdr npm install
- Install Node 6.14.0
Because we support earlier versions of Node, please install and develop on Node 6.14.0 so you don't get surprised when your code works locally but breaks in CI.
Here's out to install
nvm if you haven't: https://github.com/creationix/nvm
nvm install # if you've never installed 6.14.0 before you'll want to re-install yarn npm install -g yarn
If you work on several projects that use different Node versions, you might it helpful to install this automatic version manager: https://github.com/wbyoung/avn
4. Observe the project's code style While you're making changes, make sure to run the linter-watcher to catch any linting errors (in addition to making sure your text editor supports ESLint) ```shell node_modules/.bin/gulp watch
If you're working on a file not in
src, limit your code to Node 6.16 ES! See
what's supported here: https://node.green/ (The reason is that our npm library
must support earlier versions of Node, so the tests need to run on those