Beispiel #1
0
var old_encode = function (variant, stream) {

    // NOTE: this code matches the old implement and should not be changed
    //       It is useful to compare new performance of the encode method
    //       with the old implementation.
    assert(variant.isValid());

    var encodingByte = variant.dataType.value;

    if (variant.arrayType === VariantArrayType.Array) {

        encodingByte |= Variant_ArrayMask;
    }
    ec.encodeUInt8(encodingByte, stream);
    var encode = factories.findBuiltInType(variant.dataType.key).encode;
    /* istanbul ignore next */
    if (!encode) {
        throw new Error("Cannot find encode function for dataType " + variant.dataType.key);
    }
    if (variant.arrayType === VariantArrayType.Array) {
        var arr = variant.value || [];
        ec.encodeUInt32(arr.length, stream);
        arr.forEach(function (el) {
            encode(el, stream);
        });
    } else {
        encode(variant.value, stream);
    }
};
Beispiel #2
0
function encodeTypedArray(ArrayType, stream, value) {

    assert(value instanceof ArrayType);
    assert(value.buffer instanceof ArrayBuffer);
    ec.encodeUInt32(value.length, stream);

    stream.writeArrayBuffer(value.buffer, value.byteOffset, value.byteLength);

}
Beispiel #3
0
function encodeGeneralArray(dataType, stream, value) {

    var arr = value || [];

    ec.encodeUInt32(arr.length, stream);

    var encode = get_encoder(dataType);
    var i, n = arr.length;
    for (i = 0; i < n; i++) {
        encode(arr[i], stream);
    }
}