-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
471 additions
and
492 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
'use strict' | ||
|
||
const table = require('./base-table') | ||
const table = require('./base-table.json') | ||
|
||
// map for codecConstant -> code | ||
const constants = {} | ||
|
||
for (const [k, v] of Object.entries(table)) { | ||
constants[k.toUpperCase().replace(/-/g, '_')] = parseInt(v.toString('hex'), 16) | ||
for (const [name, code] of Object.entries(table)) { | ||
constants[name.toUpperCase().replace(/-/g, '_')] = code | ||
} | ||
|
||
module.exports = Object.freeze(constants) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
'use strict' | ||
const baseTable = require('./base-table') | ||
|
||
// this creates a map for code as hexString -> codecName | ||
const baseTable = require('./base-table.json') | ||
|
||
// map for hexString -> codecName | ||
const nameTable = {} | ||
module.exports = nameTable | ||
|
||
for (const encodingName in baseTable) { | ||
const code = baseTable[encodingName] | ||
nameTable[code.toString('hex')] = encodingName | ||
nameTable[code.toString(16)] = encodingName | ||
} | ||
|
||
module.exports = Object.freeze(nameTable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
'use strict' | ||
|
||
const table = require('./base-table') | ||
const e = {} | ||
const table = require('./base-table.json') | ||
|
||
for (const [k, v] of Object.entries(table)) { | ||
const key = parseInt(v.toString('hex'), 16) | ||
if (typeof e[key] === 'undefined') e[key] = k | ||
// map for code -> print friendly name | ||
const tableByCode = {} | ||
|
||
for (const [name, code] of Object.entries(table)) { | ||
if (tableByCode[code] === undefined) tableByCode[code] = name | ||
} | ||
|
||
module.exports = Object.freeze(e) | ||
module.exports = Object.freeze(tableByCode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
'use strict' | ||
const baseTable = require('./base-table') | ||
const varintBufferEncode = require('./util').varintBufferEncode | ||
|
||
// this creates a map for codecName -> codeVarintBuffer | ||
const baseTable = require('./base-table.json') | ||
const varintEncode = require('./util').varintEncode | ||
|
||
// map for codecName -> codeVarintBuffer | ||
const varintTable = {} | ||
module.exports = varintTable | ||
|
||
for (const encodingName in baseTable) { | ||
const code = baseTable[encodingName] | ||
varintTable[encodingName] = varintBufferEncode(code) | ||
varintTable[encodingName] = varintEncode(code) | ||
} | ||
|
||
module.exports = Object.freeze(varintTable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,30 @@ | ||
const bent = require('bent') | ||
const HEADER = ` | ||
// THIS FILE IS GENERATED, DO NO EDIT MANUALLY | ||
// For more information see the README.md | ||
'use strict' | ||
|
||
const { numberToBuffer } = require('../src/util') | ||
const table = { | ||
` | ||
const FOOTER = ` | ||
} | ||
for (const [k, v] of Object.entries(table)) { | ||
table[k] = numberToBuffer(v) | ||
} | ||
module.exports = Object.freeze(table) | ||
` | ||
const bent = require('bent') | ||
const path = require('path') | ||
|
||
const get = bent('string') | ||
const url = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv' | ||
const fs = require('fs') | ||
|
||
const parse = async function * () { | ||
let str = await get(url) | ||
let lines = str.split('\n') | ||
let header = lines.shift() | ||
for (let line of lines) { | ||
const str = await get(url) | ||
const lines = str.split('\n') | ||
lines.shift() | ||
for (const line of lines) { | ||
if (!line.length) continue | ||
let [name, tag, code, desc] = line.split(',') | ||
const [name, tag, code] = line.split(',') | ||
yield { name: name.trim(), tag: tag.trim(), code: parseInt(code.trim(), 16) } | ||
} | ||
} | ||
|
||
const run = async () => { | ||
let str = HEADER | ||
let first = true | ||
for await (let entry of parse()) { | ||
key = entry.name | ||
if (key.includes('-')) key = `'${key}'` | ||
console.log(entry) | ||
if (!first) str += ',\n ' | ||
else str += ' ' | ||
str += `${key}: ${entry.code}` | ||
first = false | ||
const table = {} | ||
|
||
for await (const { name, code } of parse()) { | ||
table[name] = code | ||
} | ||
str += FOOTER | ||
fs.writeFileSync(__dirname + '/../src/base-table.js', str) | ||
|
||
fs.writeFileSync(path.join(__dirname, '../src/base-table.json'), JSON.stringify(table, null, 2)) | ||
} | ||
run() |