Skip to content

Commit

Permalink
encoding, refactor: deprecate base64vlq.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed May 29, 2021
1 parent ce181e6 commit e7327b3
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 372 deletions.
99 changes: 0 additions & 99 deletions fibjs/include/ifs/base64vlq.h

This file was deleted.

3 changes: 0 additions & 3 deletions fibjs/include/ifs/encoding.h
Expand Up @@ -17,7 +17,6 @@ namespace fibjs {

class base32_base;
class base64_base;
class base64vlq_base;
class hex_base;
class iconv_base;
class json_base;
Expand Down Expand Up @@ -54,7 +53,6 @@ class encoding_base : public object_base {

#include "ifs/base32.h"
#include "ifs/base64.h"
#include "ifs/base64vlq.h"
#include "ifs/hex.h"
#include "ifs/iconv.h"
#include "ifs/json.h"
Expand All @@ -73,7 +71,6 @@ inline ClassInfo& encoding_base::class_info()
static ClassData::ClassObject s_object[] = {
{ "base32", base32_base::class_info },
{ "base64", base64_base::class_info },
{ "base64vlq", base64vlq_base::class_info },
{ "hex", hex_base::class_info },
{ "iconv", iconv_base::class_info },
{ "json", json_base::class_info },
Expand Down
1 change: 0 additions & 1 deletion fibjs/program/src/fibjs.cpp
Expand Up @@ -15,7 +15,6 @@ void importModule()
IMPORT_MODULE(assert);
IMPORT_MODULE(base32);
IMPORT_MODULE(base64);
IMPORT_MODULE(base64vlq);
IMPORT_MODULE(buffer);
IMPORT_MODULE(child_process);
IMPORT_MODULE(coroutine);
Expand Down
89 changes: 0 additions & 89 deletions fibjs/src/encoding/encoding.cpp
Expand Up @@ -15,7 +15,6 @@ namespace fibjs {
DECLARE_MODULE(encoding);
DECLARE_MODULE(base32);
DECLARE_MODULE(base64);
DECLARE_MODULE(base64vlq);
DECLARE_MODULE(hex);

result_t base32_base::encode(Buffer_base* data, exlib::string& retVal)
Expand Down Expand Up @@ -63,94 +62,6 @@ result_t base64_base::decode(exlib::string data,
return 0;
}

result_t base64vlq_base::encode(int32_t data, exlib::string& retVal)
{
static const char encodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

if (data < 0)
data = ((-data) << 1) | 1;
else
data <<= 1;

do {
int32_t byte = data & 0x1f;
data >>= 5;
if (data)
byte |= 0x20;

retVal.append(1, encodeTable[byte]);
} while (data > 0);

return 0;
}

result_t base64vlq_base::encode(v8::Local<v8::Array> data, exlib::string& retVal)
{
int32_t len = data->Length();
result_t hr;

for (int32_t i = 0; i < len; i++) {
int32_t num;
hr = GetArgumentValue(JSValue(data->Get(i)), num);
if (hr < 0)
return CHECK_ERROR(hr);

hr = encode(num, retVal);
if (hr < 0)
return hr;
}

return 0;
}

result_t base64vlq_base::decode(exlib::string data, v8::Local<v8::Array>& retVal)
{
static const char decodeTable[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, /* 2x !"#$%&'()*+,-./ */
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 3x 0123456789:;<=>? */
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 4x @ABCDEFGHIJKLMNO */
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, /* 5X PQRSTUVWXYZ[\]^_ */
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 6x `abcdefghijklmno */
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 7X pqrstuvwxyz{\}~DEL */
};

const char* _data = data.c_str();
const char* end = _data + data.length();

int32_t cnt = 0;

Isolate* isolate = Isolate::current();
retVal = v8::Array::New(isolate->m_isolate);

while (_data < end) {
unsigned char ch;
int32_t bits = 0;
int32_t num = 0;

while ((_data < end) && (ch = (unsigned char)*_data++)) {
int32_t byte = (ch > 0x20 && ch < 0x80) ? decodeTable[ch - 0x20] : -1;

if (byte != -1) {
num += (byte & 0x1f) << (bits * 5);
bits++;

if (!(byte & 0x20))
break;
} else
break;
}

if (num & 1)
num = -(num >> 1);
else
num = num >> 1;

retVal->Set(cnt++, v8::Number::New(isolate->m_isolate, num));
}

return 0;
}

result_t hex_base::encode(Buffer_base* data, exlib::string& retVal)
{
exlib::string strData;
Expand Down
31 changes: 0 additions & 31 deletions idl/us-en/base64vlq.idl

This file was deleted.

3 changes: 0 additions & 3 deletions idl/us-en/encoding.idl
Expand Up @@ -13,9 +13,6 @@ module encoding
/*! @brief base64 encode and decode module */
static base64;

/*! @brief base64vlq encode and decode module */
static base64vlq;

/*! @brief hex encode and decode module */
static hex;

Expand Down
31 changes: 0 additions & 31 deletions idl/zh-cn/base64vlq.idl

This file was deleted.

1 change: 0 additions & 1 deletion idl/zh-cn/collect.json
Expand Up @@ -33,7 +33,6 @@
"Encoding": [
"base32",
"base64",
"base64vlq",
"encoding",
"hex",
"iconv",
Expand Down
3 changes: 0 additions & 3 deletions idl/zh-cn/encoding.idl
Expand Up @@ -12,9 +12,6 @@ module encoding
/*! @brief base64 编码与解码模块 */
static base64;

/*! @brief base64vlq 编码与解码模块 */
static base64vlq;

/*! @brief hex 编码与解码模块 */
static hex;

Expand Down
1 change: 0 additions & 1 deletion npm/types/dts/_import/bridge.d.ts
Expand Up @@ -25,7 +25,6 @@
/// <reference path="../module/ws.d.ts" />
/// <reference path="../module/base32.d.ts" />
/// <reference path="../module/base64.d.ts" />
/// <reference path="../module/base64vlq.d.ts" />
/// <reference path="../module/encoding.d.ts" />
/// <reference path="../module/hex.d.ts" />
/// <reference path="../module/iconv.d.ts" />
Expand Down
18 changes: 0 additions & 18 deletions npm/types/dts/interface/TypeScript.d.ts

This file was deleted.

41 changes: 0 additions & 41 deletions npm/types/dts/module/base64vlq.d.ts

This file was deleted.

0 comments on commit e7327b3

Please sign in to comment.