All files / json-pack/src/nfs/v4 Nfsv4FullEncoder.ts

68.18% Statements 30/44
100% Branches 1/1
63.63% Functions 7/11
68.18% Lines 30/44

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 14026x 26x 26x 26x               26x           572x 572x 572x 572x 572x                   765x 765x                   765x 765x 765x 765x 765x                 3x 3x       759x 759x 759x 759x 759x                 3x 3x                 3x 3x 3x 3x                                                                                                          
import {Writer} from '@jsonjoy.com/buffers/lib/Writer';
import {Nfsv4Encoder} from './Nfsv4Encoder';
import {RpcMessageEncoder} from '../../rpc/RpcMessageEncoder';
import {RmRecordEncoder} from '../../rm/RmRecordEncoder';
import {type Nfsv4Proc, type Nfsv4CbProc, Nfsv4Const} from './constants';
import type {RpcOpaqueAuth} from '../../rpc/messages';
import {RpcAcceptStat} from '../../rpc/constants';
import type {XdrEncoder} from '../../xdr';
import type * as msg from './messages';
import type {IWriter, IWriterGrowable} from '@jsonjoy.com/buffers';
 
export class Nfsv4FullEncoder<W extends IWriter & IWriterGrowable = IWriter & IWriterGrowable> {
  public readonly nfsEncoder: Nfsv4Encoder<W>;
  public readonly rpcEncoder: RpcMessageEncoder<W>;
  public readonly rmEncoder: RmRecordEncoder<W>;
  public readonly xdr: XdrEncoder;
 
  constructor(public readonly writer: W = new Writer() as any) {
    this.nfsEncoder = new Nfsv4Encoder(writer);
    this.rpcEncoder = new RpcMessageEncoder(writer);
    this.rmEncoder = new RmRecordEncoder(writer);
    this.xdr = this.nfsEncoder.xdr;
  }
 
  public encodeCall(
    xid: number,
    proc: Nfsv4Proc,
    cred: RpcOpaqueAuth,
    verf: RpcOpaqueAuth,
    request: msg.Nfsv4CompoundRequest,
  ): Uint8Array {
    this.writeCall(xid, proc, cred, verf, request);
    return this.writer.flush();
  }
 
  public writeCall(
    xid: number,
    proc: Nfsv4Proc,
    cred: RpcOpaqueAuth,
    verf: RpcOpaqueAuth,
    request: msg.Nfsv4CompoundRequest,
  ): void {
    const rm = this.rmEncoder;
    const state = rm.startRecord();
    this.rpcEncoder.writeCall(xid, Nfsv4Const.PROGRAM, Nfsv4Const.VERSION, proc, cred, verf);
    this.nfsEncoder.writeCompound(request, true);
    rm.endRecord(state);
  }
 
  public encodeAcceptedCompoundReply(
    xid: number,
    proc: Nfsv4Proc,
    verf: RpcOpaqueAuth,
    response: msg.Nfsv4CompoundResponse,
  ): Uint8Array {
    this.writeAcceptedCompoundReply(xid, verf, response);
    return this.writer.flush();
  }
 
  public writeAcceptedCompoundReply(xid: number, verf: RpcOpaqueAuth, compound: msg.Nfsv4CompoundResponse): void {
    const rm = this.rmEncoder;
    const state = rm.startRecord();
    this.rpcEncoder.writeAcceptedReply(xid, verf, RpcAcceptStat.SUCCESS);
    compound.encode(this.xdr);
    rm.endRecord(state);
  }
 
  public encodeRejectedReply(
    xid: number,
    rejectStat: number,
    mismatchInfo?: {low: number; high: number},
    authStat?: number,
  ): Uint8Array {
    this.writeRejectedReply(xid, rejectStat, mismatchInfo, authStat);
    return this.writer.flush();
  }
 
  public writeRejectedReply(
    xid: number,
    rejectStat: number,
    mismatchInfo?: {low: number; high: number},
    authStat?: number,
  ): void {
    const rm = this.rmEncoder;
    const state = rm.startRecord();
    this.rpcEncoder.writeRejectedReply(xid, rejectStat, mismatchInfo, authStat);
    rm.endRecord(state);
  }
 
  public encodeCbCall(
    xid: number,
    cbProgram: number,
    proc: Nfsv4CbProc,
    cred: RpcOpaqueAuth,
    verf: RpcOpaqueAuth,
    request: msg.Nfsv4CbCompoundRequest,
  ): Uint8Array {
    this.writeCbCall(xid, cbProgram, proc, cred, verf, request);
    return this.writer.flush();
  }
 
  public writeCbCall(
    xid: number,
    cbProgram: number,
    proc: Nfsv4CbProc,
    cred: RpcOpaqueAuth,
    verf: RpcOpaqueAuth,
    request: msg.Nfsv4CbCompoundRequest,
  ): void {
    const rm = this.rmEncoder;
    const state = rm.startRecord();
    this.rpcEncoder.writeCall(xid, cbProgram, Nfsv4Const.VERSION, proc, cred, verf);
    this.nfsEncoder.writeCbCompound(request, true);
    rm.endRecord(state);
  }
 
  public encodeCbAcceptedReply(
    xid: number,
    proc: Nfsv4CbProc,
    verf: RpcOpaqueAuth,
    response: msg.Nfsv4CbCompoundResponse,
  ): Uint8Array {
    this.writeCbAcceptedReply(xid, proc, verf, response);
    return this.writer.flush();
  }
 
  public writeCbAcceptedReply(
    xid: number,
    proc: Nfsv4CbProc,
    verf: RpcOpaqueAuth,
    response: msg.Nfsv4CbCompoundResponse,
  ): void {
    const rm = this.rmEncoder;
    const state = rm.startRecord();
    this.rpcEncoder.writeAcceptedReply(xid, verf, RpcAcceptStat.SUCCESS);
    this.nfsEncoder.writeCbCompound(response, false);
    rm.endRecord(state);
  }
}