Skip to content

Commit

Permalink
refactor(win32-api): retriveStruct_PRINTER_INFO()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jul 22, 2022
1 parent 772e456 commit 71e808b
Showing 1 changed file with 27 additions and 41 deletions.
68 changes: 27 additions & 41 deletions packages/win32-api/src/func/winspool/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,42 @@ export function retriveStruct_PRINTER_INFO<L extends M.PRINTER_INFO_LEVEL>(
: pPrinter.byteLength
assert(pcb >= 16, 'Buffer too small')

let ret: M.PRINTER_INFO_X[L][] = []

switch (Level) {
case 1:
return retriveStruct_PRINTER_INFO_1(pPrinter, maxCount, pcb) as M.PRINTER_INFO_X[L][]
case 4:
return retriveStruct_PRINTER_INFO_4(pPrinter, maxCount, pcb) as M.PRINTER_INFO_X[L][]
case 1: {
const structDef = DS.PRINTER_INFO_1
ret = loopRead(
pPrinter,
maxCount,
pcb,
1,
structDef,
) as M.PRINTER_INFO_X[L][]
break
}

case 4: {
const structDef = DS.PRINTER_INFO_4
ret = loopRead(
pPrinter,
maxCount,
pcb,
4,
structDef,
) as M.PRINTER_INFO_X[L][]
break
}

default:
throw new Error(`Level not implemented:${Level}`)
}

}


function retriveStruct_PRINTER_INFO_1(
pPrinter: Buffer,
maxCount: number,
pcbNeeded: number,
): M.PRINTER_INFO_1[] {

const structDef = DS.PRINTER_INFO_1
const ret = loopRead(
pPrinter,
maxCount,
pcbNeeded,
1,
structDef,
)

return ret
}



function rpi1(
addressBuffer: Buffer,
maxByteLength: number,
Expand Down Expand Up @@ -95,25 +100,6 @@ function rpi1(
}



function retriveStruct_PRINTER_INFO_4(
pPrinter: Buffer,
maxCount: number,
pcbNeeded: number,
): M.PRINTER_INFO_4[] {

const structDef = DS.PRINTER_INFO_4
const ret = loopRead(
pPrinter,
maxCount,
pcbNeeded,
4,
structDef,
)

return ret
}

function rpi4(
addressBuffer: Buffer,
maxByteLength: number,
Expand Down

0 comments on commit 71e808b

Please sign in to comment.