@threejs-shared/protobuf 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/ProtoBufManager.ts +8 -6
- package/src/ProtobufWebSocketClient.ts +2 -1
- package/src/WebSocketManager.ts +1 -1
- package/src/index.ts +1 -1
- package/src/types.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threejs-shared/protobuf",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Protobuf manager for loading and parsing proto files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"protobufjs": "^7.0.0",
|
|
20
|
-
"@threejs-shared/xodr": "0.1.
|
|
20
|
+
"@threejs-shared/xodr": "0.1.2"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc --noEmit"
|
package/src/ProtoBufManager.ts
CHANGED
|
@@ -64,6 +64,8 @@
|
|
|
64
64
|
// }
|
|
65
65
|
|
|
66
66
|
import * as protobuf from 'protobufjs'
|
|
67
|
+
import type { ProtobufType } from './types'
|
|
68
|
+
import type { Root } from 'protobufjs'
|
|
67
69
|
|
|
68
70
|
/**
|
|
69
71
|
* ProtoBufManager 配置选项
|
|
@@ -84,9 +86,9 @@ export interface ProtoBufManagerOptions {
|
|
|
84
86
|
*/
|
|
85
87
|
export class ProtoBufManager {
|
|
86
88
|
/** 已加载的 proto 类型缓存 */
|
|
87
|
-
private protoCache: Map<string,
|
|
89
|
+
private protoCache: Map<string, ProtobufType> = new Map()
|
|
88
90
|
/** 正在加载的 Promise 缓存,用于并发控制 */
|
|
89
|
-
private loadingPromises: Map<string, Promise<
|
|
91
|
+
private loadingPromises: Map<string, Promise<ProtobufType>> = new Map()
|
|
90
92
|
/** 配置选项 */
|
|
91
93
|
private options: Required<ProtoBufManagerOptions>
|
|
92
94
|
|
|
@@ -101,7 +103,7 @@ export class ProtoBufManager {
|
|
|
101
103
|
*
|
|
102
104
|
* @param protoFilePath proto 文件的路径(URL)
|
|
103
105
|
* @param messageType 消息类型名称(例如:'protobuf.WsFrameData' 或 'SimulationMonitor.SimulationMonitorMsg')
|
|
104
|
-
* @returns Promise<
|
|
106
|
+
* @returns Promise<ProtobufType> 解析后的消息类型
|
|
105
107
|
* @throws {Error} 如果参数无效、文件加载失败、解析失败或消息类型不存在
|
|
106
108
|
*
|
|
107
109
|
* @example
|
|
@@ -110,7 +112,7 @@ export class ProtoBufManager {
|
|
|
110
112
|
* const messageType = await manager.loadProto('/proto/SimulationMonitor.proto', 'SimulationMonitor.SimulationMonitorMsg')
|
|
111
113
|
* ```
|
|
112
114
|
*/
|
|
113
|
-
async loadProto(protoFilePath: string, messageType: string): Promise<
|
|
115
|
+
async loadProto(protoFilePath: string, messageType: string): Promise<ProtobufType> {
|
|
114
116
|
// 参数验证
|
|
115
117
|
if (!protoFilePath || typeof protoFilePath !== 'string') {
|
|
116
118
|
throw new Error('protoFilePath must be a non-empty string')
|
|
@@ -155,7 +157,7 @@ export class ProtoBufManager {
|
|
|
155
157
|
protoFilePath: string,
|
|
156
158
|
messageType: string,
|
|
157
159
|
cacheKey: string
|
|
158
|
-
): Promise<
|
|
160
|
+
): Promise<ProtobufType> {
|
|
159
161
|
try {
|
|
160
162
|
this.log(`Loading proto file: ${protoFilePath}`)
|
|
161
163
|
|
|
@@ -190,7 +192,7 @@ export class ProtoBufManager {
|
|
|
190
192
|
}
|
|
191
193
|
|
|
192
194
|
// 3. 解析 proto 文件
|
|
193
|
-
let root:
|
|
195
|
+
let root: Root
|
|
194
196
|
try {
|
|
195
197
|
root = protobuf.parse(content).root
|
|
196
198
|
} catch (error) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProtoBufManager } from './ProtoBufManager'
|
|
2
2
|
import { WebSocketManager, WebSocketStatus, MessageFormat } from './WebSocketManager'
|
|
3
|
-
import type { ProtobufType
|
|
3
|
+
import type { ProtobufType } from './types'
|
|
4
|
+
import type { WebSocketManagerOptions, WebSocketCallbacks, ProtoBufManagerOptions } from './index'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Protobuf WebSocket 客户端配置
|
package/src/WebSocketManager.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,6 +8,6 @@ import type { ProtobufPlaybackClientConfig, ProtobufPlaybackCallbacks } from './
|
|
|
8
8
|
import type { ProtoBufManagerOptions } from './ProtoBufManager'
|
|
9
9
|
import { TimerManager } from './TimerManager'
|
|
10
10
|
export { ProtoBufManager, WebSocketManager, WebSocketStatus, MessageFormat, ProtobufWebSocketClient, ProtobufPlaybackClient, TimerManager }
|
|
11
|
-
export type {
|
|
11
|
+
export type { ProtobufType } from './types'
|
|
12
12
|
export type { WebSocketManagerOptions, WebSocketCallbacks, ProtobufWebSocketClientConfig, ProtobufPlaybackClientConfig, ProtobufPlaybackCallbacks, ProtoBufManagerOptions }
|
|
13
13
|
|
package/src/types.ts
ADDED