fix(core): fix bare types and mt_message writing
This commit is contained in:
parent
9b5ca0cb2a
commit
49eda8f0e3
5 changed files with 44 additions and 26 deletions
|
@ -176,7 +176,7 @@ export class SerializationCounter implements ITlBinaryWriter {
|
|||
|
||||
vector(fn: TlBinaryWriterFunction, items: unknown[], bare?: boolean): void {
|
||||
this.count += bare ? 4 : 8
|
||||
items.forEach((it) => fn.call(this, it))
|
||||
items.forEach((it) => fn.call(this, it, bare))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,11 +301,11 @@ export class BinaryWriter implements ITlBinaryWriter {
|
|||
this._objectMap[obj._].call(this, obj, bare)
|
||||
}
|
||||
|
||||
vector(fn: TlBinaryWriterFunction, val: unknown[]): void {
|
||||
this.uint32(0x1cb5c415)
|
||||
vector(fn: TlBinaryWriterFunction, val: unknown[], bare?: boolean): void {
|
||||
if (!bare) this.uint32(0x1cb5c415)
|
||||
this.uint32(val.length)
|
||||
|
||||
val.forEach((it) => fn.call(this, it))
|
||||
val.forEach((it) => fn.call(this, it, bare))
|
||||
}
|
||||
|
||||
result(): Buffer {
|
||||
|
|
2
packages/tl/binary/writer.d.ts
vendored
2
packages/tl/binary/writer.d.ts
vendored
|
@ -50,7 +50,7 @@ export interface ITlBinaryWriter {
|
|||
*
|
||||
* @param fn Writer function
|
||||
* @param items Items to be written
|
||||
* @param bare Whether the vector is bare (i.e. vector ID should not be written)
|
||||
* @param bare Whether the vector is bare (i.e. object ID should not be written)
|
||||
*/
|
||||
vector(fn: TlBinaryWriterFunction, items: unknown[], bare?: boolean): void
|
||||
}
|
||||
|
|
|
@ -80,6 +80,9 @@ function writeNamespace(nsType) {
|
|||
write(`${cls.id}: function () {`)
|
||||
tab()
|
||||
|
||||
let is_mt_message =
|
||||
nsType === 'mtproto' && cls.name === 'message'
|
||||
|
||||
if (cls.arguments?.length) {
|
||||
write(`var ret = {};`)
|
||||
write(`ret._ = '${prefix}${cls.name}';`)
|
||||
|
@ -106,15 +109,19 @@ function writeNamespace(nsType) {
|
|||
)
|
||||
}
|
||||
} else {
|
||||
write(
|
||||
`ret.${
|
||||
arg.name
|
||||
} = this.${getFunctionCallByTypeName(
|
||||
baseTypePrefix,
|
||||
arg.type,
|
||||
arg
|
||||
)};`
|
||||
)
|
||||
if (is_mt_message && arg.name === 'body') {
|
||||
write('ret.body = this.raw(ret.bytes)')
|
||||
} else {
|
||||
write(
|
||||
`ret.${
|
||||
arg.name
|
||||
} = this.${getFunctionCallByTypeName(
|
||||
baseTypePrefix,
|
||||
arg.type,
|
||||
arg
|
||||
)};`
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -120,13 +120,17 @@ function writeNamespace(nsType) {
|
|||
} else {
|
||||
write(`_assert_has(obj, '${arg.name}')`)
|
||||
}
|
||||
write(
|
||||
`this.${getFunctionCallByTypeName(
|
||||
baseTypePrefix,
|
||||
arg.type,
|
||||
`obj.${arg.name}`
|
||||
)}`
|
||||
)
|
||||
if (is_mt_message && arg.name === 'body') {
|
||||
write('this.raw(obj.body)')
|
||||
} else {
|
||||
write(
|
||||
`this.${getFunctionCallByTypeName(
|
||||
baseTypePrefix,
|
||||
arg.type,
|
||||
`obj.${arg.name}`
|
||||
)}`
|
||||
)
|
||||
}
|
||||
if (arg.optional) {
|
||||
untab()
|
||||
}
|
||||
|
|
|
@ -162,6 +162,9 @@ const writeSingleSchemaEntry = (type) => {
|
|||
ts.tab()
|
||||
ts.write(`readonly _: '${prefix}${cls.name}',`)
|
||||
|
||||
let is_mt_message =
|
||||
type === 'mtproto' && cls.name === 'message'
|
||||
|
||||
if (cls.arguments && cls.arguments.length) {
|
||||
cls.arguments.forEach((arg) => {
|
||||
if (arg.type === '$FlagsBitField') return
|
||||
|
@ -170,11 +173,15 @@ const writeSingleSchemaEntry = (type) => {
|
|||
arg.type = 'boolean'
|
||||
if (arg.description) ts.comment(arg.description)
|
||||
|
||||
ts.write(
|
||||
`readonly ${arg.name}${
|
||||
arg.optional ? '?' : ''
|
||||
}: ${fullTypeName(arg.type)};`
|
||||
)
|
||||
if (is_mt_message && arg.name === 'body') {
|
||||
ts.write('readonly body: Buffer;')
|
||||
} else {
|
||||
ts.write(
|
||||
`readonly ${arg.name}${
|
||||
arg.optional ? '?' : ''
|
||||
}: ${fullTypeName(arg.type)};`
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue