( kvMsg: KvServerMessage, blobStore: Map<string, Uint8Array>, sendFrame: (data: Uint8Array) => void, )
| 908 | } |
| 909 | |
| 910 | function handleKvMessage( |
| 911 | kvMsg: KvServerMessage, |
| 912 | blobStore: Map<string, Uint8Array>, |
| 913 | sendFrame: (data: Uint8Array) => void, |
| 914 | ): void { |
| 915 | const kvCase = kvMsg.message.case; |
| 916 | |
| 917 | if (kvCase === "getBlobArgs") { |
| 918 | const blobId = kvMsg.message.value.blobId; |
| 919 | const blobIdKey = Buffer.from(blobId).toString("hex"); |
| 920 | const blobData = blobStore.get(blobIdKey); |
| 921 | sendKvResponse( |
| 922 | kvMsg, "getBlobResult", |
| 923 | create(GetBlobResultSchema, blobData ? { blobData } : {}), |
| 924 | sendFrame, |
| 925 | ); |
| 926 | } else if (kvCase === "setBlobArgs") { |
| 927 | const { blobId, blobData } = kvMsg.message.value; |
| 928 | blobStore.set(Buffer.from(blobId).toString("hex"), blobData); |
| 929 | sendKvResponse( |
| 930 | kvMsg, "setBlobResult", |
| 931 | create(SetBlobResultSchema, {}), |
| 932 | sendFrame, |
| 933 | ); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | function handleExecMessage( |
| 938 | execMsg: ExecServerMessage, |
no test coverage detected