monorepo 버전 준비
## @strpc 기존 RPC를 package화 ### @strpc/express express의 middleware + router 결함 ## @sammo 게임 전체 - server, client - gateway_server, gateway_client
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { BytesLike, BufferSource } from "../types.js";
|
||||
|
||||
export function convertBytesLikeToUint8Array(data: string, encodeUTF8: boolean): Uint8Array;
|
||||
export function convertBytesLikeToUint8Array(data: BufferSource | string): Uint8Array;
|
||||
export function convertBytesLikeToUint8Array(data: BytesLike, encodeUTF8 = true): Uint8Array {
|
||||
if (data instanceof Uint8Array) {
|
||||
return data;
|
||||
}
|
||||
if (data instanceof ArrayBuffer) {
|
||||
return new Uint8Array(data);
|
||||
}
|
||||
if (data instanceof SharedArrayBuffer) {
|
||||
return new Uint8Array(data);
|
||||
}
|
||||
if (data instanceof Uint8Array) {
|
||||
return data;
|
||||
}
|
||||
if (ArrayBuffer.isView(data)) {
|
||||
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
||||
}
|
||||
if (typeof (data) === 'string') {
|
||||
if(encodeUTF8){
|
||||
return (new TextEncoder()).encode(data);
|
||||
}
|
||||
return new Uint8Array(data.split('').map(s=>s.codePointAt(0) as number));
|
||||
}
|
||||
throw new Error(`Unknown data type ${typeof (data)}`);
|
||||
}
|
||||
Reference in New Issue
Block a user