Permalink
Browse files

Minimized base64 tables

  • Loading branch information...
dcodeIO committed Dec 11, 2016
1 parent e789367 commit ecbb4a52fbab445e63bf23b91539e853efaefa47

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN -116 Bytes (99%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -37,7 +37,7 @@
"zuul-local": "zuul --ui tape --no-coverage --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js"
},
"dependencies": {
"@protobufjs/base64": "1.0.1",
"@protobufjs/base64": "1.0.2",
"@protobufjs/codegen": "1.0.1",
"@protobufjs/eventemitter": "1.0.1",
"@protobufjs/pool": "1.0.1",
@@ -1,10 +1,11 @@
"use strict";
module.exports = encode;
var Enum = require("./enum"),
Writer = require("./writer"),
types = require("./types"),
util = require("./util");
var Enum = require("./enum"),
Writer = require("./writer"),
types = require("./types"),
util = require("./util");
var safeProp = util.safeProp;
/**
* General purpose message encoder.
@@ -99,17 +100,18 @@ function encode(message, writer) {
*/
/**/
encode.generate = function generate(mtype) {
/* eslint-disable no-unexpected-multiline */
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.getFieldsArray();
var oneofs = mtype.getOneofsArray();
var gen = util.codegen("m", "w")
("w||(w=Writer.create())");
var i;
for (var i = 0; i < fields.length; ++i) {
var field = fields[i].resolve(),
type = field.resolvedType instanceof Enum ? "uint32" : field.type,
wireType = types.basic[type],
prop = util.safeProp(field.name);
prop = safeProp(field.name);
// Map fields
if (field.map) {
@@ -185,17 +187,17 @@ encode.generate = function generate(mtype) {
}
}
for (var i = 0; i < oneofs.length; ++i) { gen
for (var i = 0; i < oneofs.length; ++i) {
var oneof = oneofs[i],
prop = util.safeProp(oneof.name);
prop = safeProp(oneof.name);
gen
("switch(m%s){", prop);
var oneofFields = oneof.getFieldsArray();
for (var j = 0; j < oneofFields.length; ++j) {
var field = oneofFields[j],
type = field.resolvedType instanceof Enum ? "uint32" : field.type,
wireType = types.basic[type],
prop = util.safeProp(field.name);
prop = safeProp(field.name);
gen
("case%j:", field.name);
@@ -219,5 +221,5 @@ encode.generate = function generate(mtype) {
return gen
("return w");
/* eslint-enable no-unexpected-multiline */
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
};
@@ -23,12 +23,14 @@ base64.length = function length(string) {
};
// Base64 encoding table
var b64 = [
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47
];
var b64 = [];
// Base64 decoding table
var s64 = [];
// 65..90, 97..122, 48..57, 43, 47
for (var i = 0; i < 64;)
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
/**
* Encodes a buffer to a base64 encoded string.
@@ -38,7 +40,7 @@ var b64 = [
* @returns {string} Base64 encoded string
*/
base64.encode = function encode(buffer, start, end) {
var string = new Array(Math.ceil((end - start) / 3) * 4);
var string = []; // alt: new Array(Math.ceil((end - start) / 3) * 4);
var i = 0, // output index
j = 0, // goto index
t; // temporary
@@ -71,8 +73,6 @@ base64.encode = function encode(buffer, start, end) {
return String.fromCharCode.apply(String, string);
};
// Base64 decoding table
var s64 = []; for (var i = 0; i < b64.length; ++i) s64[b64[i]] = i;
var invalidEncoding = "invalid encoding";
/**
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/base64",
"description": "A minimal base64 implementation for number arrays.",
"version": "1.0.1",
"version": "1.0.2",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"repository": {
"type": "git",

0 comments on commit ecbb4a5

Please sign in to comment.