-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wraps command to higher level api, starts client
- Loading branch information
Showing
65 changed files
with
1,006 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,10 @@ | ||
|
||
export type CommandResponse = { | ||
status: number, | ||
length: number, | ||
data: Buffer | ||
}; | ||
|
||
export type Client = { | ||
sendCommand: (code: number, payload: Buffer) => Promise<CommandResponse> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
|
||
import type { CommandResponse } from './client.type.js'; | ||
import { translateCommandCode } from '../wire/command.code.js'; | ||
|
||
|
||
export const handleResponse = (r: Buffer) => { | ||
const status = r.readUint32LE(0); | ||
const length = r.readUint32LE(4); | ||
console.log('<== handleResponse', { status, length }); | ||
return { | ||
status, length, data: r.subarray(8) | ||
}}; | ||
|
||
export const deserializeVoidResponse = | ||
(r: CommandResponse): Boolean => r.status === 0 && r.data.length === 0; | ||
|
||
const COMMAND_LENGTH = 4; | ||
|
||
export const serializeCommand = (command: number, payload: Buffer) => { | ||
const payloadSize = payload.length COMMAND_LENGTH; | ||
const head = Buffer.allocUnsafe(8); | ||
|
||
head.writeUint32LE(payloadSize, 0); | ||
head.writeUint32LE(command, 4); | ||
|
||
console.log( | ||
'==> CMD', command, | ||
translateCommandCode(command), | ||
head.subarray(4, 8).toString('hex'), | ||
'LENGTH', payloadSize, | ||
head.subarray(0, 4).toString('hex') | ||
); | ||
|
||
return Buffer.concat([head, payload]); | ||
} | ||
|
||
|
||
// enum TransportType { | ||
// TCP = 'tcp', | ||
// // TLS = 'tls', | ||
// // QUIC = 'quic' | ||
// } | ||
|
||
// type ClientConfig = { | ||
// transport: TransportType | ||
// host: string, | ||
// port: number | ||
// } | ||
|
||
// export const transportClient = (config: ClientConfig): Client => { | ||
// const {transport} = config; | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.