|
@@ -1,7 +1,11 @@
|
|
|
|
+<<<<<<< HEAD:src/lib/gramjs/tl/gramJsApi.js
|
|
//const { readFileSync } = require('fs')
|
|
//const { readFileSync } = require('fs')
|
|
import { readFileSync } from 'fs'
|
|
import { readFileSync } from 'fs'
|
|
|
|
|
|
|
|
|
|
|
|
+=======
|
|
|
|
+const { readFileSync } = require('fs')
|
|
|
|
+>>>>>>> 1ab480fe... Gram JS: Remove deps; Fix Factorizator and remove leemon lib:src/lib/gramjs/tl/api.js
|
|
const {
|
|
const {
|
|
parseTl,
|
|
parseTl,
|
|
serializeBytes,
|
|
serializeBytes,
|
|
@@ -58,19 +62,21 @@ function extractParams(fileContent) {
|
|
function argToBytes(x, type) {
|
|
function argToBytes(x, type) {
|
|
switch (type) {
|
|
switch (type) {
|
|
case 'int':
|
|
case 'int':
|
|
- return (struct.pack('<i', x))
|
|
|
|
|
|
+ const i = Buffer.alloc(4)
|
|
|
|
+ return i.writeInt32LE(x, 0)
|
|
case 'long':
|
|
case 'long':
|
|
- return (readBufferFromBigInt(x, 8, true, true))
|
|
|
|
|
|
+ return readBufferFromBigInt(x, 8, true, true)
|
|
case 'int128':
|
|
case 'int128':
|
|
- return (readBufferFromBigInt(x, 16, true, true))
|
|
|
|
|
|
+ return readBufferFromBigInt(x, 16, true, true)
|
|
case 'int256':
|
|
case 'int256':
|
|
- return (readBufferFromBigInt(x, 32, true, true))
|
|
|
|
|
|
+ return readBufferFromBigInt(x, 32, true, true)
|
|
case 'double':
|
|
case 'double':
|
|
- return (struct.pack('<d', x.toString()))
|
|
|
|
|
|
+ const d = Buffer.alloc(8)
|
|
|
|
+ return d.writeDoubleLE(x, 0)
|
|
case 'string':
|
|
case 'string':
|
|
return serializeBytes(x)
|
|
return serializeBytes(x)
|
|
case 'Bool':
|
|
case 'Bool':
|
|
- return (x ? Buffer.from('b5757299', 'hex') : Buffer.from('379779bc', 'hex'))
|
|
|
|
|
|
+ return x ? Buffer.from('b5757299', 'hex') : Buffer.from('379779bc', 'hex')
|
|
case 'true':
|
|
case 'true':
|
|
return Buffer.alloc(0)
|
|
return Buffer.alloc(0)
|
|
case 'bytes':
|
|
case 'bytes':
|
|
@@ -217,7 +223,9 @@ function createClasses(classesType, params) {
|
|
getBytes() {
|
|
getBytes() {
|
|
// The next is pseudo-code:
|
|
// The next is pseudo-code:
|
|
const idForBytes = this.CONSTRUCTOR_ID
|
|
const idForBytes = this.CONSTRUCTOR_ID
|
|
- const buffers = [struct.pack('<I', idForBytes)]
|
|
|
|
|
|
+ const c = Buffer.alloc(4)
|
|
|
|
+ c.writeUInt32LE(idForBytes, 0)
|
|
|
|
+ const buffers = [c]
|
|
for (const arg in argsConfig) {
|
|
for (const arg in argsConfig) {
|
|
if (argsConfig.hasOwnProperty(arg)) {
|
|
if (argsConfig.hasOwnProperty(arg)) {
|
|
if (argsConfig[arg].isFlag) {
|
|
if (argsConfig[arg].isFlag) {
|
|
@@ -228,14 +236,18 @@ function createClasses(classesType, params) {
|
|
if (argsConfig[arg].useVectorId) {
|
|
if (argsConfig[arg].useVectorId) {
|
|
tempBuffers.push(Buffer.from('15c4b51c', 'hex'))
|
|
tempBuffers.push(Buffer.from('15c4b51c', 'hex'))
|
|
}
|
|
}
|
|
|
|
+ const l = Buffer.alloc(4)
|
|
|
|
+ l.writeInt32LE(this[arg].length, 0)
|
|
buffers.push((!this[arg] ? Buffer.alloc(0) : Buffer.concat([...tempBuffers,
|
|
buffers.push((!this[arg] ? Buffer.alloc(0) : Buffer.concat([...tempBuffers,
|
|
- struct.pack('<i', this[arg].length), Buffer.concat(this[arg].map(x => argToBytes(x, argsConfig[arg].type)))])))
|
|
|
|
|
|
+ l, Buffer.concat(this[arg].map(x => argToBytes(x, argsConfig[arg].type)))])))
|
|
}
|
|
}
|
|
} else if (argsConfig[arg].isVector && !argsConfig[arg].isFlag) {
|
|
} else if (argsConfig[arg].isVector && !argsConfig[arg].isFlag) {
|
|
if (argsConfig[arg].isVector) {
|
|
if (argsConfig[arg].isVector) {
|
|
buffers.push(Buffer.from('15c4b51c', 'hex'))
|
|
buffers.push(Buffer.from('15c4b51c', 'hex'))
|
|
}
|
|
}
|
|
- buffers.push(struct.pack('<i', this[arg].length), Buffer.concat(this[arg].map(x => argToBytes(x, argsConfig[arg].type))))
|
|
|
|
|
|
+ const l = Buffer.alloc(4)
|
|
|
|
+ l.writeInt32LE(this[arg].length, 0)
|
|
|
|
+ buffers.push(l, Buffer.concat(this[arg].map(x => argToBytes(x, argsConfig[arg].type))))
|
|
} else if (argsConfig[arg].flagIndicator) {
|
|
} else if (argsConfig[arg].flagIndicator) {
|
|
// @ts-ignore
|
|
// @ts-ignore
|
|
if (!Object.values(argsConfig)
|
|
if (!Object.values(argsConfig)
|
|
@@ -252,13 +264,17 @@ function createClasses(classesType, params) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- buffers.push(struct.pack('<I', flagCalculate))
|
|
|
|
|
|
+ const f = Buffer.alloc(4)
|
|
|
|
+ f.writeUInt32LE(flagCalculate, 0)
|
|
|
|
+ buffers.push(f)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
|
|
|
|
switch (argsConfig[arg].type) {
|
|
switch (argsConfig[arg].type) {
|
|
case 'int':
|
|
case 'int':
|
|
- buffers.push(struct.pack('<i', this[arg]))
|
|
|
|
|
|
+ const i = Buffer.alloc(4)
|
|
|
|
+ i.writeInt32LE(this[arg], 0)
|
|
|
|
+ buffers.push(i)
|
|
break
|
|
break
|
|
case 'long':
|
|
case 'long':
|
|
buffers.push(readBufferFromBigInt(this[arg], 8, true, true))
|
|
buffers.push(readBufferFromBigInt(this[arg], 8, true, true))
|
|
@@ -270,7 +286,9 @@ function createClasses(classesType, params) {
|
|
buffers.push(readBufferFromBigInt(this[arg], 32, true, true))
|
|
buffers.push(readBufferFromBigInt(this[arg], 32, true, true))
|
|
break
|
|
break
|
|
case 'double':
|
|
case 'double':
|
|
- buffers.push(struct.pack('<d', this[arg].toString()))
|
|
|
|
|
|
+ const d = Buffer.alloc(8)
|
|
|
|
+ d.writeDoubleLE(this[arg].toString(), 0)
|
|
|
|
+ buffers.push(d)
|
|
break
|
|
break
|
|
case 'string':
|
|
case 'string':
|
|
buffers.push(serializeBytes(this[arg]))
|
|
buffers.push(serializeBytes(this[arg]))
|
|
@@ -373,5 +391,10 @@ function createClasses(classesType, params) {
|
|
return classes
|
|
return classes
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+<<<<<<< HEAD:src/lib/gramjs/tl/gramJsApi.js
|
|
const gramJsApi = buildApiFromTlSchema()
|
|
const gramJsApi = buildApiFromTlSchema()
|
|
module.exports = gramJsApi
|
|
module.exports = gramJsApi
|
|
|
|
+=======
|
|
|
|
+module.exports = buildApiFromTlSchema()
|
|
|
|
+console.log(module.exports)
|
|
|
|
+>>>>>>> 1ab480fe... Gram JS: Remove deps; Fix Factorizator and remove leemon lib:src/lib/gramjs/tl/api.js
|