2024-08-13 04:53:07 +03:00
|
|
|
import type { TlEntry, TlFullSchema } from '@mtcute/tl-utils'
|
|
|
|
import { parseFullTlSchema } from '@mtcute/tl-utils'
|
2023-06-05 03:30:48 +03:00
|
|
|
|
|
|
|
// interface TlPackedUnion {
|
|
|
|
// // name
|
|
|
|
// n: string
|
|
|
|
// // comment
|
|
|
|
// d?: string
|
|
|
|
// // methods
|
|
|
|
// m: string[]
|
|
|
|
// // classes
|
|
|
|
// c: string[]
|
|
|
|
// }
|
2021-11-23 00:03:59 +03:00
|
|
|
|
|
|
|
export interface TlPackedSchema {
|
|
|
|
// layer
|
|
|
|
l: number
|
|
|
|
// entries
|
|
|
|
e: TlEntry[]
|
|
|
|
// unions (only comments)
|
|
|
|
u: Record<string, string>
|
|
|
|
}
|
|
|
|
|
2023-09-24 01:32:22 +03:00
|
|
|
export function packTlSchema(schema: TlFullSchema, layer: number): TlPackedSchema {
|
2021-11-23 00:03:59 +03:00
|
|
|
const ret: TlPackedSchema = {
|
|
|
|
l: layer,
|
|
|
|
e: schema.entries,
|
2022-06-30 16:32:56 +03:00
|
|
|
u: {},
|
2021-11-23 00:03:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const name in schema.unions) {
|
|
|
|
const union = schema.unions[name]
|
|
|
|
|
|
|
|
if (union.comment) {
|
|
|
|
ret.u[name] = union.comment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unpackTlSchema(schema: TlPackedSchema): [TlFullSchema, number] {
|
|
|
|
const res = parseFullTlSchema(schema.e)
|
|
|
|
|
|
|
|
for (const name in schema.u) {
|
|
|
|
if (!res.unions[name]) continue
|
|
|
|
|
|
|
|
res.unions[name].comment = schema.u[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
return [res, schema.l]
|
|
|
|
}
|