i've been wanting to name a commit like this for my entire life, lol. seriously though, a lot has changed: - extracted TL-related stuff to `@mtcute/tl-utils` and `@mtcute/tl-runtime`, rewrote codegen in TS - updated to layer 134, moved to int64 identifiers - rewritten networking (mtproto), rewritten updates handling - *lots* of refactoring still a very early version though, there are a lot of improvements to be made, but at least it runs, lol also tl-reference will not be updated anytime soon because i want to rewrite it
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import { TlEntry } from './types'
|
|
|
|
function normalizeType(s: string): string {
|
|
return s
|
|
.replace(/</g, ' ')
|
|
.replace(/>/g, '')
|
|
.replace('bytes', 'string')
|
|
.replace('int53', 'long')
|
|
}
|
|
|
|
export function writeTlEntryToString(
|
|
entry: TlEntry,
|
|
forIdComputation = false
|
|
): string {
|
|
let str = entry.name
|
|
|
|
if (!forIdComputation && entry.id) {
|
|
str += '#' + entry.id.toString(16)
|
|
}
|
|
|
|
str += ' '
|
|
|
|
if (entry.generics) {
|
|
for (const g of entry.generics) {
|
|
if (forIdComputation) {
|
|
str += g.name + ':' + g.type + ' '
|
|
} else {
|
|
str += '{' + g.name + ':' + g.type + '} '
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const arg of entry.arguments) {
|
|
if (forIdComputation && arg.predicate && arg.type === 'true') continue
|
|
|
|
str += arg.name + ':'
|
|
|
|
if (arg.predicate) {
|
|
str += arg.predicate + '?'
|
|
}
|
|
|
|
if (forIdComputation) {
|
|
str += normalizeType(arg.type) + ' '
|
|
} else {
|
|
str += arg.type + ' '
|
|
}
|
|
}
|
|
|
|
if (forIdComputation) {
|
|
str += '= ' + normalizeType(entry.type)
|
|
} else {
|
|
str += '= ' + entry.type + ';'
|
|
}
|
|
|
|
return str
|
|
}
|