147965edb31008b71d174667cc4f20dad965eaa8 — Emma 4 months ago 4bc58da
Less header
2 files changed, 7 insertions(+), 7 deletions(-)

M library/bare.mjs
M README.md => README.md +6 -6
@@ 5,13 5,13 @@ This is a work-in-progress JavaScript/Node.js implementation of [BARE](https://b
The idea is, that the schema converter runs on node.js, while the resulting JavaScript classes should be usable
both in the browser and in other javascript environments.

### What is still missing
## What is still missing
 * Union type, this one is difficult to translate to js, so I'm going to have to think about use cases and how to make them convenient to use
 * Conversion error handling and integrity verification.
 * Unit tests, these will come last.

### How to use
#### Schema converter
## How to use
### Schema converter
The converter located at `converter/bare.js` is a runnable node.js script, which takes two arguments: `[input, [output]]`.
If one or both are not given, it will write to `stdout`, and read from `stdin` respectively.
For now the output is barely formatted, each type gets its own line, some whitespace is added for legibility.

@@ 23,7 23,7 @@ either in the schema, or by reordering the lines in the output. JS will complain
I am thinking about trying to reorder the types in code, but circular dependencies will always need manual intervention,
and might not work in JS either way. It would be nice to have, but is rather low priority.

#### Resulting module
### Resulting module
The output from the converter is a file which only works in conjunction with `library/bare.mjs`.
This file contains all the message conversion logic, whereas the conversion output contains the layout specifics
of the types you specified in your schema file.

@@ 35,7 35,7 @@ in the type definitions of the second file. Most browsers support this spec, and
Should your environment not support this feature, or you don't want to use modules, you can full well remove the import and export statements,
and load the two files like regular scripts. (I'm not 100% on this, but you can probably even leave them in)

##### Now to the actual how-to for using this in a web page:
#### Now to the actual how-to for using this in a web page:

If you want to use a bare type in your `main.js` script file, you need to load it as a module: `<script type="module" src="main.js"></script>`.
The basic gist is, that modules do not share a scope, but read the MDN article above for more details.

@@ 47,7 47,7 @@ Just make sure that the `library/bare.mjs` file is in the same folder as the out
Or you can only load some types directly into your scope: `import {Address, Point} from './path/to/output.js';`.
You can even rename them with `Type as OtherName` inside those brackets, should that matter in your use case.

### A note about Number and 64 bits
## A note about Number and 64 bits
Javascript is a wonderful language, and as such it doesn't use an integer type for numbers.
Instead, every single number is stored as a double precision float.
This limits the usable range of integers to 53 bits, which means the maximum unsigned value is just over 9 quadrillion `(10^15)`.

M library/bare.mjs => library/bare.mjs +1 -1
@@ 528,7 528,7 @@ class BareStruct extends BareType {
	static entries; // = [['key', type], ...]

	static pack(obj) {
		let bin = new Uint8Array();
		let bin = new Uint8Array(0);
		for (let i = 0; i < this.entries.length; i++) {
			let [key, type] = this.entries[i];
			let bytes = type.pack(obj[key]);