Publish Vulpes Preview 15 sources for desktop, Android and Tundra

Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
OverSu 2026-09-30 23:13:03 +02:00
commit b38dea0597
25901 changed files with 9982925 additions and 369 deletions

View file

@ -0,0 +1,135 @@
'use strict';
var Transform = require('stream').Transform;
var SEPARATOR = ':';
var SEPARATOR_CODE = SEPARATOR.charCodeAt(0);
/**
* First ocurrence of where string occurs in a buffer.
*
* NOTE: this is not UTF8 safe generally we expect to find the correct
* char fairly quickly unless the buffer is incorrectly formatted.
*
* @param {Buffer} buffer haystack.
* @param {String} code needle.
* @return {Numeric} -1 if not found index otherwise.
*/
function indexInBuffer(buffer, code) {
if (buffer.length === 0)
return -1;
var index = 0;
var length = buffer.length;
do {
if (buffer[index] === code) return index;
} while (
++index && index + 1 < length
);
return -1;
}
/**
* converts an object to a string representation suitable for storage on disk.
* Its very important to note that the length in the string refers to the utf8
* size of the json content in bytes (as utf8) not the JS string length.
*
* @param {Object} object to stringify.
* @return {String} serialized object.
*/
function stringify(object) {
var json = JSON.stringify(object);
var len = Buffer.byteLength(json);
return len + SEPARATOR + json;
}
/**
* attempts to parse a given buffer or string.
*
* @param {Uint8Array|Buffer} input in byteLength:{json..} format.
* @return {Objec} JS object.
*/
function parse(input) {
var stream = new Stream();
var result;
stream.once('data', function(data) {
result = data;
});
stream.write(input);
if (!result) {
throw new Error(
'no command available from parsing:' + input
);
}
return result;
}
function Stream() {
this._pendingLength = null;
this._buffer = new Buffer(0);
Transform.call(this, { objectMode: true });
}
Stream.prototype = {
__proto__: Transform.prototype,
_transform: function(chunk, encoding, cb) {
if (!this._pendingLength) {
var idx = indexInBuffer(chunk, SEPARATOR_CODE);
// Nothing to do just buffer it...
if (idx === -1) {
this._buffer = Buffer.concat([this._buffer, chunk]);
return cb();
}
// number of bytes in the json segment...
var length = Buffer.concat([this._buffer, chunk.slice(0, idx)]);
this._pendingLength = parseInt(length.toString(), 10);
this._buffer = new Buffer(0);
// We have transitioned to a pending length state so do another pass.
return this._transform(chunk.slice(idx + 1), encoding, cb);
}
// Total length too small nothing to do...
if (this._buffer.length + chunk.length < this._pendingLength) {
this._buffer = Buffer.concat([this._buffer, chunk]);
return cb();
}
var buffer = Buffer.concat([this._buffer, chunk]);
var remainder = null;
if (buffer.length > this._pendingLength) {
remainder = buffer.slice(this._pendingLength);
buffer = buffer.slice(0, this._pendingLength);
}
// Reset internal state and push current json string.
this._pendingLength = null;
this._buffer = new Buffer(0);
this.push(JSON.parse(buffer.toString()));
// If we have any remaining data we need to keep processing...
if (remainder) {
return this._transform(remainder, encoding, cb);
}
// Otherwise we are done yay....
return cb();
}
};
exports.parse = parse;
exports.stringify = stringify;
exports.Stream = Stream;
exports.separator = SEPARATOR;

View file

@ -0,0 +1,7 @@
{
"name": "json-wire-protocol",
"version": "1.0.0",
"author": "James Lal",
"main": "lib/index.js",
"description": "JSON wire protocol parser/writer (used in mozilla debugger protocol)"
}

View file

@ -0,0 +1,139 @@
'use strict';
var assert = require('assert');
var jsonWireProtocol = require('../');
suite('json wire protocol', function() {
var subject;
var TWO_BYTE = 'ž';
function createBytes(content) {
return new Buffer(content);
}
test('.separator', function() {
assert.ok(jsonWireProtocol.separator);
});
suite('#stringify', function() {
test('ASCII only', function() {
var input = { a: 'abcdefg' };
var expected = JSON.stringify(input);
expected = expected.length + ':' + expected;
var output = jsonWireProtocol.stringify(input);
assert.deepEqual(expected, output);
});
test('invalid strings', function() {
var invalid = 'xfoobar!';
assert.throws(function() {
jsonWireProtocol.parse(invalid);
});
});
test('with multibyte chars', function() {
var input = { a: TWO_BYTE + TWO_BYTE + TWO_BYTE };
var expected = JSON.stringify(input);
expected = '14:' + expected;
assert.deepEqual(jsonWireProtocol.stringify(input), expected);
});
});
suite('#parse', function() {
test('working string', function() {
var input = { woot: TWO_BYTE };
var string = jsonWireProtocol.stringify(input);
assert.deepEqual(
input,
jsonWireProtocol.parse(createBytes(string))
);
});
});
suite('.Stream', function() {
setup(function() {
subject = new jsonWireProtocol.Stream();
});
suite('#write', function() {
suite('multiple commands over two buffers', function() {
var commandA = { a: 'cool' };
var commandB = { b: 'woot' };
var commandC = { c: 'wtfman' };
var commandD = { d: TWO_BYTE };
var all = [
commandA,
commandB,
commandC
]
.map(jsonWireProtocol.stringify)
.join('');
var half = all.length / 2;
var bufferA = createBytes(all.slice(0, half));
var bufferB = createBytes(all.slice(half) +
jsonWireProtocol.stringify(commandD));
var parsed;
setup(function() {
parsed = [];
subject.on('data', function(result) {
parsed.push(result);
});
subject.write(bufferA);
subject.write(bufferB);
});
test('result after writing to stream', function() {
assert.deepEqual(
parsed,
[commandA, commandB, commandC, commandD]
);
});
});
test('multiple chunks until length', function(done) {
var expected = { longer: TWO_BYTE + 'a' + TWO_BYTE };
var string = jsonWireProtocol.stringify(expected);
subject.on('data', function(result) {
assert.deepEqual(result, expected);
done();
});
for (var i = 0; i < string.length; i++) {
subject.write(createBytes(string[i]));
}
});
suite('entire buffer', function() {
var buffer;
/* 13 ascii bytes */
var string = '{"one":"foo"}';
setup(function() {
buffer = createBytes('13:' + string);
});
test('read entire buffer', function(done) {
var expected = { one: 'foo' };
subject.once('data', function(data) {
assert.deepEqual(data, expected);
done();
});
subject.write(buffer);
});
});
});
});
});