steamutils 1.4.95 → 1.4.97
Sign up to get free protection for your applications and to get access to all the features.
- package/_steamproto.js +39 -33
- package/full_steamproto.js +39 -33
- package/index.js +6 -4
- package/package.json +1 -1
- package/steamproto.js +40 -34
- package/utils.js +37 -0
package/_steamproto.js
CHANGED
@@ -1,33 +1,39 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import { fileURLToPath } from "url";
|
3
|
-
import Protobuf from "protobufjs";
|
4
|
-
|
5
|
-
const __filename = fileURLToPath(import.meta.url);
|
6
|
-
const __dirname = path.dirname(__filename);
|
7
|
-
|
8
|
-
export class SteamProto {
|
9
|
-
constructor(proto) {
|
10
|
-
this._proto = proto;
|
11
|
-
}
|
12
|
-
|
13
|
-
toProto() {
|
14
|
-
const root = new Protobuf.Root().loadSync(path.join(`${__dirname}/protos/`, this._proto.filename), {
|
15
|
-
keepCase: true,
|
16
|
-
});
|
17
|
-
return root[this._proto.name];
|
18
|
-
}
|
19
|
-
|
20
|
-
protoEncode(obj) {
|
21
|
-
const protobuf = this.toProto();
|
22
|
-
return protobuf.encode(protobuf.create(obj)).finish();
|
23
|
-
}
|
24
|
-
|
25
|
-
protoEncodeBase64(obj) {
|
26
|
-
return this.protoEncode(obj).toString("base64");
|
27
|
-
}
|
28
|
-
|
29
|
-
protoDecode(obj) {
|
30
|
-
const protobuf = this.toProto();
|
31
|
-
|
32
|
-
|
33
|
-
}
|
1
|
+
import path from "path";
|
2
|
+
import { fileURLToPath } from "url";
|
3
|
+
import Protobuf from "protobufjs";
|
4
|
+
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
6
|
+
const __dirname = path.dirname(__filename);
|
7
|
+
|
8
|
+
export class SteamProto {
|
9
|
+
constructor(proto) {
|
10
|
+
this._proto = proto;
|
11
|
+
}
|
12
|
+
|
13
|
+
toProto() {
|
14
|
+
const root = new Protobuf.Root().loadSync(path.join(`${__dirname}/protos/`, this._proto.filename), {
|
15
|
+
keepCase: true,
|
16
|
+
});
|
17
|
+
return root[this._proto.name];
|
18
|
+
}
|
19
|
+
|
20
|
+
protoEncode(obj) {
|
21
|
+
const protobuf = this.toProto();
|
22
|
+
return protobuf.encode(protobuf.create(obj)).finish();
|
23
|
+
}
|
24
|
+
|
25
|
+
protoEncodeBase64(obj) {
|
26
|
+
return this.protoEncode(obj).toString("base64");
|
27
|
+
}
|
28
|
+
|
29
|
+
protoDecode(obj) {
|
30
|
+
const protobuf = this.toProto();
|
31
|
+
try {
|
32
|
+
return protobuf.toObject(protobuf.decode(obj), { defaults: true });
|
33
|
+
} catch (e) {
|
34
|
+
console.error(`[${this._proto.name}] protoDecode 1`, typeof obj, obj);
|
35
|
+
console.error(`[${this._proto.name}] protoDecode 2`, e);
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|