-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on May 9, 1986 4:57:16 pm PDT by Lupine of February 22, 1986 5:15:54 pm PST
-- Source interface Lark came from file Lark.bcd, which was created on May 9, 1986 3:47:44 pm PDT with version stamp 111#243#11006740257 from source of May 9, 1986 3:28:51 pm PDT.

-- The RPC stub modules for Lark are:
--   LarkRpcControl.mesa;
--   LarkRpcClientImpl.mesa;
--   LarkRpcBinderImpl.mesa;
--   LarkRpcServerImpl.mesa.

-- The parameters for this translation are:
--   Target language = Cedar
--   Default parameter passing = VALUE
--   Deallocate server heap arguments = TRUE
--   Inline RpcServerImpl dispatcher stubs = TRUE
--   Declare signals = TRUE
--   Warn about short POINTER ("MDS") allocations = TRUE
--   Maximum number of dynamic heap NEWs = 50, MDS NEWs = 50
--   Acceptable parameter protocols = VersionRange[1..1].


DIRECTORY
  DESFace,
  Pup,
  Rope,
  RPC,
  Lark,
  LarkRpcControl USING [InterMdsCallsOnly, LupineProtocolVersion, ProcedureIndex,
      SignalIndex],
  RPCLupine --USING SOME OF [Call, DataLength, Dispatcher, ExportHandle,
      -- ExportInterface, GetStubPkt, maxDataLength, maxPrincipalLength,
      -- maxShortStringLength, pktOverhead, ReceiveExtraPkt, SendPrelimPkt,
      -- StartCall, StartSignal, StubPkt, UnexportInterface]--,
  LupineRuntime --USING SOME OF [BindingError, CheckPktLength, CopyFromPkt,
      -- CopyFromMultiplePkts, CopyToPkt, CopyToMultiplePkts, defaultZones,
      -- DispatchingError, FinishThisPkt, ListHeader, MarshalingError,
      -- MarshalingExprError, MarshalAtom, MarshalRope, NilHeader, ProtocolError,
      -- RopeHeader, RpcPktDoubleWord, RuntimeError, SequenceHeader, SHORT,
      -- StartNextPkt, StringHeader, StubPktDoubleWord, TranslationError,
      -- UnmarshalingError, UnmarshalingExprError, UnmarshalAtom, UnmarshalRope,
      -- WordsForChars]--,
  Atom --USING SOME OF [GetPName, MakeAtom]--;


LarkRpcServerImpl: MONITOR
  IMPORTS Lark, RpcPrivate: RPCLupine, Lupine: LupineRuntime, Atom,
      Rope
  EXPORTS LarkRpcControl
  SHARES  Lark, LarkRpcControl, Rope
  = BEGIN OPEN Lark, RpcControl: LarkRpcControl, RpcPublic: RPC;


-- Standard remote binding routines.

  bound: BOOLEAN ← FALSE;
  myInterface: RpcPrivate.ExportHandle;
  paramZones: RpcPublic.Zones ← RpcPublic.standardZones;

  ExportInterface: PUBLIC ENTRY SAFE PROCEDURE [
        interfaceName: RpcPublic.InterfaceName,
        user: RpcPublic.Principal,
        password: RpcPublic.EncryptionKey,
        parameterStorage: RpcPublic.Zones ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
    IF bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.ExportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "Lark~111#243#11006740257",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      user: user,  password: password,
      dispatcher: ServerDispatcher,
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion ];
    paramZones ← [
      gc: IF parameterStorage.gc # NIL
        THEN parameterStorage.gc ELSE Lupine.defaultZones.gc,
      heap: IF parameterStorage.heap # NIL
        THEN parameterStorage.heap ELSE Lupine.defaultZones.heap,
      mds: IF parameterStorage.mds # NIL
        THEN parameterStorage.mds ELSE Lupine.defaultZones.mds ];
    bound ← TRUE;
    END;

  UnexportInterface: PUBLIC ENTRY SAFE PROCEDURE =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IF ~bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.UnexportInterface[myInterface];
    paramZones ← RpcPublic.standardZones;
    bound ← FALSE;
    END;


-- Public procedure dispatcher and public signal and error catcher.

  ServerDispatcher: --PROCEDURE [pkt: RPCPkt, callLength: DataLength,
      -- lastPkt: BOOLEAN, localConversation: Conversation] RETURNS [returnLength:
      -- DataLength]-- RpcPrivate.Dispatcher =
    BEGIN

    -- Catch public signals.

      ENABLE BEGIN

      END;  -- Catch public signals.


    -- Call public procedures (still in dispatcher).

    SELECT LOOPHOLE[pkt.data[0], RpcControl.ProcedureIndex] FROM
      Reset => RETURN[
        ResetStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      SpecifyTones => RETURN[
        SpecifyTonesStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      Feep => RETURN[
        FeepStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Commands => RETURN[
        CommandsStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Connect => RETURN[
        ConnectStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Disconnect => RETURN[
        DisconnectStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      PleaseRegister => RETURN[
        PleaseRegisterStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      WhatIsStatus => RETURN[
        WhatIsStatusStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      WhatAreConnections => RETURN[
        WhatAreConnectionsStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      WhatAreTones => RETURN[
        WhatAreTonesStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      SetKeyTable => RETURN[
        SetKeyTableStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      CommandString => RETURN[
        CommandStringStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      PleaseLogin => RETURN[
        PleaseLoginStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      EchoSupression => RETURN[
        EchoSupressionStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      SetHostNumber => RETURN[
        SetHostNumberStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  ResetStub: --PROCEDURE [shh: SHHH, rName: ROPE]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    rName: ROPE;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal rName: ROPE from pkt.data[pktLength].
      [rName, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, TRUE];
      END;  -- Unmarshal rName.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    Reset[localConversation, rName];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- ResetStub.

  SpecifyTonesStub: --PROCEDURE [shh: SHHH, queueIt: BOOLEAN, tones:
      -- ToneSpec]
    -- RETURNS [ok: BOOLEAN]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    queueIt: BOOLEAN;
    tones: ToneSpec;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, queueIt (1): BOOLEAN];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        ok (0): BOOLEAN];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay;
    pktLength: RpcPrivate.DataLength ← 2;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [queueIt: queueIt] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal tones: ToneSpec from pkt.data[pktLength].
      [tones, pktLength] ← UnmarshalToneSpec[pkt, pktLength];
      END;  -- Unmarshal tones.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    resPkt ← @pkt.data[0];
    IF onePkt
      THEN [resPkt.ok] ← SpecifyTones[localConversation, argPkt.queueIt,
          tones]
      ELSE [resPkt.ok] ← SpecifyTones[localConversation, queueIt, tones];
    END;  -- OnePkt.
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- SpecifyTonesStub.

  FeepStub: --PROCEDURE [shh: SHHH, on: Milliseconds, off: Milliseconds,
      -- waveTable: CARDINAL, queueIt: BOOLEAN, notify: CommandEvent, events:
      -- CommandEvents]
    -- RETURNS [ok: BOOLEAN]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    events: CommandEvents;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, on (1): Milliseconds,
        off (2): Milliseconds, waveTable (3): CARDINAL, queueIt (4): BOOLEAN,
        notify (5): CommandEvent];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        ok (0): BOOLEAN];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 6;
    BEGIN  -- Unmarshal events: CommandEvents from pkt.data[pktLength].
      [events, pktLength] ← UnmarshalCommandEvents[pkt, pktLength];
      END;  -- Unmarshal events.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.ok] ← Feep[localConversation, argPkt.on, argPkt.off, argPkt.waveTable,
        argPkt.queueIt, argPkt.notify, events];
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- FeepStub.

  CommandsStub: --PROCEDURE [shh: SHHH, events: CommandEvents]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    events: CommandEvents;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal events: CommandEvents from pkt.data[pktLength].
      [events, pktLength] ← UnmarshalCommandEvents[pkt, pktLength];
      END;  -- Unmarshal events.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    Commands[localConversation, events];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- CommandsStub.

  ConnectStub: --PROCEDURE [shh: SHHH, specs: ConnectionSpec]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    specs: ConnectionSpec;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal specs: ConnectionSpec from pkt.data[pktLength].
      [specs, pktLength] ← UnmarshalConnectionSpec[pkt, pktLength];
      END;  -- Unmarshal specs.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    Connect[localConversation, specs];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- ConnectStub.

  DisconnectStub: --PROCEDURE [shh: SHHH, buffer: VoiceBuffer]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, buffer (1): VoiceBuffer];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    Disconnect[localConversation, argPkt.buffer];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- DisconnectStub.

  PleaseRegisterStub: --PROCEDURE [shh: SHHH]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    pktLength: RpcPrivate.DataLength ← 1;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    PleaseRegister[localConversation];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- PleaseRegisterStub.

  WhatIsStatusStub: --PROCEDURE [shh: SHHH, which: CARDINAL] RETURNS
      -- [next: CARDINAL, events: StatusEvents]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    events: StatusEvents;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, which (1): CARDINAL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        next (0): CARDINAL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.next, events] ←
      WhatIsStatus[localConversation, argPkt.which];
    pktLength ← 1;
    BEGIN  -- Marshal events: StatusEvents to pkt.data[pktLength].
      pktLength ← MarshalStatusEvents[events, pkt, pktLength];
      END;  -- Marshal events.
    RETURN[returnLength: pktLength];
    END;  -- WhatIsStatusStub.

  WhatAreConnectionsStub: --PROCEDURE [shh: SHHH, which: CARDINAL]
      -- RETURNS [next: CARDINAL, specs: ConnectionSpec]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    specs: ConnectionSpec;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, which (1): CARDINAL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        next (0): CARDINAL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.next, specs] ←
      WhatAreConnections[localConversation, argPkt.which];
    pktLength ← 1;
    BEGIN  -- Marshal specs: ConnectionSpec to pkt.data[pktLength].
      pktLength ← MarshalConnectionSpec[specs, pkt, pktLength];
      END;  -- Marshal specs.
    RETURN[returnLength: pktLength];
    END;  -- WhatAreConnectionsStub.

  WhatAreTonesStub: --PROCEDURE [shh: SHHH] RETURNS [anonP1id3017898:
      -- BOOLEAN]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        anonP1id3017898 (0): BOOLEAN];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 1;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.anonP1id3017898] ← WhatAreTones[localConversation];
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- WhatAreTonesStub.

  SetKeyTableStub: --PROCEDURE [shh: SHHH, table: KeyTable]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    table: KeyTable;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal table: KeyTable from pkt.data[pktLength].
      [table, pktLength] ← UnmarshalKeyTable[pkt, pktLength];
      END;  -- Unmarshal table.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    SetKeyTable[localConversation, table];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- SetKeyTableStub.

  CommandStringStub: --PROCEDURE [shh: SHHH, device: Device, commands:
      -- Rope.ROPE]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    device: Device;
    commands: Rope.ROPE;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, device (1): Device];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [device: device] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal commands: Rope.ROPE from pkt.data[pktLength].
      [commands, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
          FALSE];
      END;  -- Unmarshal commands.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    IF onePkt
      THEN CommandString[localConversation, argPkt.device, commands]
      ELSE CommandString[localConversation, device, commands];
    END;  -- OnePkt.
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- CommandStringStub.

  PleaseLoginStub: --PROCEDURE [shh: SHHH] RETURNS [will: BOOL]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        will (0): BOOL];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 1;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.will] ← PleaseLogin[localConversation];
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- PleaseLoginStub.

  EchoSupressionStub: --PROCEDURE [shh: SHHH, echo: EchoParameters]--
      RpcPrivate.Dispatcher =
    INLINE BEGIN
    echo: EchoParameters;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal echo: EchoParameters from pkt.data[pktLength].
      [echo, pktLength] ← UnmarshalEchoParameters[pkt, pktLength];
      END;  -- Unmarshal echo.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    EchoSupression[localConversation, echo];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- EchoSupressionStub.

  SetHostNumberStub: --PROCEDURE [shh: SHHH, host: Machine]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, host (1): Machine];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    SetHostNumber[localConversation, argPkt.host];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- SetHostNumberStub.


-- Marshall/Unmarshal procedures.
MarshalConnectionSpec: PROC[value: Lark.ConnectionSpec, pkt: RpcPrivate.RPCPkt,
    pktLength0: RpcPrivate.DataLength]
  RETURNS[pktLength: RpcPrivate.DataLength] = BEGIN
  pktLength ← pktLength0; {
  pkt.data[pktLength] ← value=NIL;  pktLength ← pktLength+1;
  IF value # NIL THEN
    BEGIN  -- Marshal value↑: Lark.ConnectionSpecRec to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.ConnectionSpecRec],
          alwaysOnePkt: TRUE];
      END;  -- Marshal value↑.
  };END;

UnmarshalConnectionSpec: PROC[pkt: RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[value: Lark.ConnectionSpec, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  isNIL: Lupine.NilHeader;
  isNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
  IF isNIL
    THEN value ← NIL
    ELSE BEGIN
      value ← (paramZones.gc.NEW[Lark.ConnectionSpecRec]);
      BEGIN  -- Unmarshal value↑: Lark.ConnectionSpecRec from pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.ConnectionSpecRec],
            alwaysOnePkt: TRUE];
        END;  -- Unmarshal value↑.
      END;  -- IF isNIL.
  };END;

UnmarshalToneSpec: PROC[pkt: RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[value: Lark.ToneSpec, pktLength: RpcPrivate.DataLength] =
      BEGIN
  pktLength ← pktLength0; {
  isNIL: Lupine.NilHeader;
  IF pktLength+1 > RpcPrivate.maxDataLength
    THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength: pktLength];
  isNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
  IF isNIL
    THEN value ← NIL
    ELSE BEGIN
      value ← (paramZones.gc.NEW[Lark.ToneSpecRec]);
      BEGIN  -- Unmarshal value↑: Lark.ToneSpecRec from pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.ToneSpecRec],
            alwaysOnePkt: FALSE];
        -- Restore garbled REFs to NIL following copy.
        BEGIN OPEN record: value↑;
        LOOPHOLE[record.tones, LONG POINTER] ← NIL;
        END;  -- OPEN record: value↑.
        BEGIN OPEN record: value↑;
        BEGIN  -- Unmarshal record.tones: LIST OF Lark.Tone from pkt.data[pktLength].
          lastNode: LIST OF Lark.Tone ← (record.tones ← NIL);
          listLength: Lupine.ListHeader;
          IF pktLength+2 > RpcPrivate.maxDataLength
            THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength:
                pktLength];
          listLength ← Lupine.RpcPktDoubleWord[pkt, pktLength]↑;
          pktLength ← pktLength + 2;
          WHILE listLength > 0 DO
            thisNode3: LIST OF Lark.Tone = paramZones.gc.CONS[--DefaultValue--,NIL];
            BEGIN  -- Unmarshal thisNode3.first: Lark.Tone from pkt.data[pktLength].
              pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
                  dataAdr: @thisNode3.first, dataLength: SIZE[Lark.Tone],
                  alwaysOnePkt: FALSE];
              END;  -- Unmarshal thisNode3.first.
            IF lastNode # NIL
              THEN lastNode ← (lastNode.rest ← thisNode3)
              ELSE lastNode ← (record.tones ← thisNode3);
            listLength ← listLength - 1;
            ENDLOOP;  -- WHILE listLength > 0.
          END;  -- Unmarshal record.tones.
        END;  -- OPEN record: value↑.
        END;  -- Unmarshal value↑.
      END;  -- IF isNIL.
  };END;

MarshalStatusEvents: PROC[value: Lark.StatusEvents, pkt: RpcPrivate.RPCPkt,
    pktLength0: RpcPrivate.DataLength]
  RETURNS[pktLength: RpcPrivate.DataLength] = BEGIN
  pktLength ← pktLength0; {
  BEGIN  -- Marshal value↑: Lark.StatusEventSequence to pkt.data[pktLength].
    pkt.data[pktLength] ← value=NIL;  pktLength ← pktLength+1;
    IF value # NIL THEN BEGIN
      -- Record has a sequence, put its length up front.
      Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← LENGTH[DESCRIPTOR[value↑]];
      pktLength ← pktLength + 2;
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.StatusEventSequence[LENGTH[DESCRIPTOR[value↑]]]],
          alwaysOnePkt: TRUE];
      END;  -- IF value # NIL.
    END;  -- Marshal value↑.
  };END;

UnmarshalEchoParameters: PROC[pkt: RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[value: Lark.EchoParameters, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  isNIL: Lupine.NilHeader;
  isNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
  IF isNIL
    THEN value ← NIL
    ELSE BEGIN
      value ← (paramZones.gc.NEW[Lark.EchoParameterRecord]);
      BEGIN  -- Unmarshal value↑: Lark.EchoParameterRecord from pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.EchoParameterRecord],
            alwaysOnePkt: TRUE];
        END;  -- Unmarshal value↑.
      END;  -- IF isNIL.
  };END;

UnmarshalCommandEvents: PROC[pkt: RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[value: Lark.CommandEvents, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  BEGIN  -- Unmarshal value↑: Lark.CommandEventSequence from pkt.data[pktLength].
    recordIsNIL: Lupine.NilHeader;
    recordIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
    IF recordIsNIL
      THEN value ← NIL
      ELSE BEGIN
        seqLength: Lupine.SequenceHeader;
        seqLength ← Lupine.RpcPktDoubleWord[pkt, pktLength]↑;
        pktLength ← pktLength + 2;
        value ← (paramZones.gc.NEW[Lark.CommandEventSequence[Lupine.SHORT[seqLength]]]);
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.CommandEventSequence[LENGTH[DESCRIPTOR[value↑]]]],
            alwaysOnePkt: TRUE];
        END;  -- IF recordIsNIL.
    END;  -- Unmarshal value↑.
  };END;

UnmarshalKeyTable: PROC[pkt: RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[value: Lark.KeyTable, pktLength: RpcPrivate.DataLength] =
      BEGIN
  pktLength ← pktLength0; {
  BEGIN  -- Unmarshal value↑: Lark.KeyTableBody from pkt.data[pktLength].
    recordIsNIL: Lupine.NilHeader;
    recordIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
    IF recordIsNIL
      THEN value ← NIL
      ELSE BEGIN
        seqLength: Lupine.SequenceHeader;
        seqLength ← Lupine.RpcPktDoubleWord[pkt, pktLength]↑;
        pktLength ← pktLength + 2;
        value ← (paramZones.gc.NEW[Lark.KeyTableBody[Lupine.SHORT[seqLength]]]);
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.KeyTableBody[LENGTH[DESCRIPTOR[value↑]]]],
            alwaysOnePkt: TRUE];
        END;  -- IF recordIsNIL.
    END;  -- Unmarshal value↑.
  };END;



-- No module initialization.

END.  -- LarkRpcServerImpl.