| 339 | } |
| 340 | |
| 341 | export function encodeProtocolMessage(value: ClientFrame | HostFrame): EncodedProtocolMessage { |
| 342 | const encoded = Buffer.from(JSON.stringify(value), 'utf8'); |
| 343 | if (encoded.byteLength > RUNTIME_HOST_MAX_MESSAGE_BYTES) { |
| 344 | throw new RuntimeHostProtocolError( |
| 345 | 'frame_too_large', |
| 346 | 'Runtime Host message exceeds the byte limit', |
| 347 | ); |
| 348 | } |
| 349 | return encoded as EncodedProtocolMessage; |
| 350 | } |
| 351 | |
| 352 | function requireProtocolVersion(value: unknown, label: string): number { |
| 353 | if (!Number.isSafeInteger(value) || (value as number) < 0) { |