-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on March 6, 1986 2:35:11 pm PST by Lupine of May 23, 1985 8:38:08 am PDT
-- Source interface LoganBerry came from file LoganBerry.bcd, which was created on March 6, 1986 11:57:09 am PST with version stamp 210#224#2316577624 from source of March 6, 1986 11:11:43 am PST.

-- The RPC stub modules for LoganBerry are:
--   LoganBerryRpcControl.mesa;
--   LoganBerryRpcClientImpl.mesa;
--   LoganBerryRpcBinderImpl.mesa;
--   LoganBerryRpcServerImpl.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
  RefID,
  Rope,
  RPC,
  LoganBerry,
  LoganBerryRpcControl 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]--;


LoganBerryRpcServerImpl: MONITOR
  IMPORTS LoganBerry, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, Rope
  EXPORTS LoganBerryRpcControl
  SHARES  LoganBerry, LoganBerryRpcControl, Rope
  = BEGIN OPEN LoganBerry, RpcControl: LoganBerryRpcControl, 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 "LoganBerry~210#224#2316577624",
        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

      Error --ERROR [ec: ErrorCode, explanation: ROPE]-- =>
        BEGIN
        ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
            transferIndex (0): RpcControl.SignalIndex ← Error];
        argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
        pktLength: RpcPrivate.DataLength ← 1;
        lastPkt: BOOLEAN;
        RpcPrivate.StartSignal[signalPkt: pkt];
        argPkt.transferIndex ← Error;
        BEGIN  -- Marshal ec: ErrorCode to pkt.data[pktLength].
          pktLength ← Lupine.MarshalAtom[ec, pkt, pktLength];
          END;  -- Marshal ec.
        BEGIN  -- Marshal explanation: ROPE to pkt.data[pktLength].
          pktLength ← Lupine.MarshalRope[explanation, pkt, pktLength,
              FALSE];
          END;  -- Marshal explanation.
        [returnLength: , lastPkt: lastPkt] ←
          RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
              maxReturnLength: 0];
        Lupine.RuntimeError;  -- Impossible to RESUME an ERROR.
        END;  -- Error.

      END;  -- Catch public signals.


    -- Call public procedures (still in dispatcher).

    SELECT LOOPHOLE[pkt.data[0], RpcControl.ProcedureIndex] FROM
      Open => RETURN[
        OpenStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Describe => RETURN[
        DescribeStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      ReadEntry => RETURN[
        ReadEntryStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      EnumerateEntries => RETURN[
        EnumerateEntriesStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      GenerateEntries => RETURN[
        GenerateEntriesStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      NextEntry => RETURN[
        NextEntryStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      EndGenerate => RETURN[
        EndGenerateStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      WriteEntry => RETURN[
        WriteEntryStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      DeleteEntry => RETURN[
        DeleteEntryStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      Close => RETURN[
        CloseStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      BuildIndices => RETURN[
        BuildIndicesStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      CompactLogs => RETURN[
        CompactLogsStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  OpenStub: --PROCEDURE [conv: Conv, dbName: ROPE] RETURNS [db: OpenDB]--
      RpcPrivate.Dispatcher =
    INLINE BEGIN
    dbName: ROPE;
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        db (0): OpenDB];
    resPkt: LONG POINTER TO ResultOverlay;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal dbName: ROPE from pkt.data[pktLength].
      [dbName, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal dbName.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    resPkt ← @pkt.data[0];
    [resPkt.db] ← Open[localConversation, dbName];
    pktLength ← 2;
    RETURN[returnLength: pktLength];
    END;  -- OpenStub.

  DescribeStub: --PROCEDURE [conv: Conv, db: OpenDB] RETURNS [info:
      -- SchemaInfo]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    info: SchemaInfo;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [info] ← Describe[localConversation, argPkt.db];
    pktLength ← 0;
    BEGIN  -- Marshal info: SchemaInfo to pkt.data[pktLength].
      BEGIN OPEN record: info;
      BEGIN  -- Marshal record.dbName: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[record.dbName, pkt, pktLength,
            FALSE];
        END;  -- Marshal record.dbName.
      BEGIN  -- Marshal record.keys: LIST OF AttributeType to pkt.data[pktLength].
        thisNode2: LIST OF AttributeType;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode2 ← record.keys, thisNode2.rest UNTIL thisNode2
            = NIL DO
          listLength ← listLength + 1;  ENDLOOP;
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
        pktLength ← pktLength + 2;
        FOR thisNode2 ← record.keys, thisNode2.rest UNTIL thisNode2
            = NIL DO
          BEGIN  -- Marshal thisNode2.first: AttributeType to pkt.data[pktLength].
            pktLength ← Lupine.MarshalAtom[thisNode2.first, pkt, pktLength];
            END;  -- Marshal thisNode2.first.
          ENDLOOP;  -- FOR thisNode2.
        END;  -- Marshal record.keys.
      BEGIN  -- Marshal record.indexNames: LIST OF ROPE to pkt.data[pktLength].
        thisNode2: LIST OF ROPE;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode2 ← record.indexNames, thisNode2.rest UNTIL thisNode2
            = NIL DO
          listLength ← listLength + 1;  ENDLOOP;
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
        pktLength ← pktLength + 2;
        FOR thisNode2 ← record.indexNames, thisNode2.rest UNTIL thisNode2
            = NIL DO
          BEGIN  -- Marshal thisNode2.first: ROPE to pkt.data[pktLength].
            pktLength ← Lupine.MarshalRope[thisNode2.first, pkt, pktLength,
                FALSE];
            END;  -- Marshal thisNode2.first.
          ENDLOOP;  -- FOR thisNode2.
        END;  -- Marshal record.indexNames.
      BEGIN  -- Marshal record.logs: LIST OF LogID to pkt.data[pktLength].
        thisNode2: LIST OF LogID;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode2 ← record.logs, thisNode2.rest UNTIL thisNode2
            = NIL DO
          listLength ← listLength + 1;  ENDLOOP;
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
        pktLength ← pktLength + 2;
        FOR thisNode2 ← record.logs, thisNode2.rest UNTIL thisNode2
            = NIL DO
          BEGIN
          IF pktLength+1 > RpcPrivate.maxDataLength
            THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
                pktLength];
          pkt.data[pktLength] ← thisNode2.first;  pktLength ← pktLength+1;
          END;
          ENDLOOP;  -- FOR thisNode2.
        END;  -- Marshal record.logs.
      BEGIN  -- Marshal record.logNames: LIST OF ROPE to pkt.data[pktLength].
        thisNode2: LIST OF ROPE;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode2 ← record.logNames, thisNode2.rest UNTIL thisNode2
            = NIL DO
          listLength ← listLength + 1;  ENDLOOP;
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
        pktLength ← pktLength + 2;
        FOR thisNode2 ← record.logNames, thisNode2.rest UNTIL thisNode2
            = NIL DO
          BEGIN  -- Marshal thisNode2.first: ROPE to pkt.data[pktLength].
            pktLength ← Lupine.MarshalRope[thisNode2.first, pkt, pktLength,
                FALSE];
            END;  -- Marshal thisNode2.first.
          ENDLOOP;  -- FOR thisNode2.
        END;  -- Marshal record.logNames.
      END;  -- OPEN record: info.
      END;  -- Marshal info.
    RETURN[returnLength: pktLength];
    END;  -- DescribeStub.

  ReadEntryStub: --PROCEDURE [conv: Conv, db: OpenDB, key: AttributeType,
      -- value: AttributeValue]
    -- RETURNS [entry: Entry, others: BOOLEAN]-- RpcPrivate.Dispatcher
        =
    INLINE BEGIN
    db: OpenDB;
    key: AttributeType;
    value: AttributeValue;
    entry: Entry;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        others (0): BOOLEAN];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay;
    pktLength: RpcPrivate.DataLength ← 3;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [db: db] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal key: AttributeType from pkt.data[pktLength].
      [key, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
      END;  -- Unmarshal key.
    BEGIN  -- Unmarshal value: AttributeValue from pkt.data[pktLength].
      [value, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal value.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    resPkt ← @pkt.data[0];
    IF onePkt
      THEN [entry, resPkt.others] ←
          ReadEntry[localConversation, argPkt.db, key, value]
      ELSE [entry, resPkt.others] ←
          ReadEntry[localConversation, db, key, value];
    END;  -- OnePkt.
    pktLength ← 1;
    BEGIN  -- Marshal entry: Entry to pkt.data[pktLength].
      thisNode1: Entry;
      listLength: Lupine.ListHeader ← 0;
      FOR thisNode1 ← entry, thisNode1.rest UNTIL thisNode1 = NIL DO
        listLength ← listLength + 1;  ENDLOOP;
      IF pktLength+2 > RpcPrivate.maxDataLength
        THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength: pktLength];
      Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
      pktLength ← pktLength + 2;
      FOR thisNode1 ← entry, thisNode1.rest UNTIL thisNode1 = NIL DO
        BEGIN  -- Marshal thisNode1.first: Attribute to pkt.data[pktLength].
          BEGIN OPEN record: thisNode1.first;
          BEGIN  -- Marshal record.type: AttributeType to pkt.data[pktLength].
            pktLength ← Lupine.MarshalAtom[record.type, pkt, pktLength];
            END;  -- Marshal record.type.
          BEGIN  -- Marshal record.value: AttributeValue to pkt.data[pktLength].
            pktLength ← Lupine.MarshalRope[record.value, pkt, pktLength,
                FALSE];
            END;  -- Marshal record.value.
          END;  -- OPEN record: thisNode1.first.
          END;  -- Marshal thisNode1.first.
        ENDLOOP;  -- FOR thisNode1.
      END;  -- Marshal entry.
    RETURN[returnLength: pktLength];
    END;  -- ReadEntryStub.

  EnumerateEntriesStub: --PROCEDURE [db: OpenDB, key: AttributeType,
      -- start: AttributeValue, end: AttributeValue, proc: EntryProc]--
      RpcPrivate.Dispatcher =
    INLINE BEGIN
    db: OpenDB;
    key: AttributeType;
    start: AttributeValue;
    end: AttributeValue;
    proc: EntryProc;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [db: db] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal key: AttributeType from pkt.data[pktLength].
      [key, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
      END;  -- Unmarshal key.
    BEGIN  -- Unmarshal start: AttributeValue from pkt.data[pktLength].
      [start, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal start.
    BEGIN  -- Unmarshal end: AttributeValue from pkt.data[pktLength].
      [end, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal end.
-- ##### Error: Cannot YET marshal transfer (e.g., procedure) parameter.
    -- Identifier or type = EntryProc. --  Lupine.TranslationError;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    IF onePkt
      THEN EnumerateEntries[argPkt.db, key, start, end, proc]
      ELSE EnumerateEntries[db, key, start, end, proc];
    END;  -- OnePkt.
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- EnumerateEntriesStub.

  GenerateEntriesStub: --PROCEDURE [conv: Conv, db: OpenDB, key: AttributeType,
      -- start: AttributeValue, end: AttributeValue]
    -- RETURNS [cursor: Cursor]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    db: OpenDB;
    key: AttributeType;
    start: AttributeValue;
    end: AttributeValue;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        cursor (0): Cursor];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay;
    pktLength: RpcPrivate.DataLength ← 3;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [db: db] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal key: AttributeType from pkt.data[pktLength].
      [key, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
      END;  -- Unmarshal key.
    BEGIN  -- Unmarshal start: AttributeValue from pkt.data[pktLength].
      [start, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal start.
    BEGIN  -- Unmarshal end: AttributeValue from pkt.data[pktLength].
      [end, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal end.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    resPkt ← @pkt.data[0];
    IF onePkt
      THEN [resPkt.cursor] ← GenerateEntries[localConversation, argPkt.db,
          key, start, end]
      ELSE [resPkt.cursor] ← GenerateEntries[localConversation, db,
          key, start, end];
    END;  -- OnePkt.
    pktLength ← 2;
    RETURN[returnLength: pktLength];
    END;  -- GenerateEntriesStub.

  NextEntryStub: --PROCEDURE [conv: Conv, cursor: Cursor, dir: CursorDirection]
    -- RETURNS [entry: Entry]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    entry: Entry;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, cursor (1): Cursor,
        dir (3): CursorDirection];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 4;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [entry] ← NextEntry[localConversation, argPkt.cursor, argPkt.dir];
    pktLength ← 0;
    BEGIN  -- Marshal entry: Entry to pkt.data[pktLength].
      thisNode1: Entry;
      listLength: Lupine.ListHeader ← 0;
      FOR thisNode1 ← entry, thisNode1.rest UNTIL thisNode1 = NIL DO
        listLength ← listLength + 1;  ENDLOOP;
      IF pktLength+2 > RpcPrivate.maxDataLength
        THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength: pktLength];
      Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
      pktLength ← pktLength + 2;
      FOR thisNode1 ← entry, thisNode1.rest UNTIL thisNode1 = NIL DO
        BEGIN  -- Marshal thisNode1.first: Attribute to pkt.data[pktLength].
          BEGIN OPEN record: thisNode1.first;
          BEGIN  -- Marshal record.type: AttributeType to pkt.data[pktLength].
            pktLength ← Lupine.MarshalAtom[record.type, pkt, pktLength];
            END;  -- Marshal record.type.
          BEGIN  -- Marshal record.value: AttributeValue to pkt.data[pktLength].
            pktLength ← Lupine.MarshalRope[record.value, pkt, pktLength,
                FALSE];
            END;  -- Marshal record.value.
          END;  -- OPEN record: thisNode1.first.
          END;  -- Marshal thisNode1.first.
        ENDLOOP;  -- FOR thisNode1.
      END;  -- Marshal entry.
    RETURN[returnLength: pktLength];
    END;  -- NextEntryStub.

  EndGenerateStub: --PROCEDURE [conv: Conv, cursor: Cursor]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, cursor (1): Cursor];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    EndGenerate[localConversation, argPkt.cursor];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- EndGenerateStub.

  WriteEntryStub: --PROCEDURE [conv: Conv, db: OpenDB, entry: Entry,
      -- log: LogID, replace: BOOLEAN]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    db: OpenDB;
    entry: Entry;
    log: LogID;
    replace: BOOLEAN;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB, log
        (3): LogID, replace (4): BOOLEAN];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 5;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [db: db, log: log, replace: replace] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal entry: Entry from pkt.data[pktLength].
      lastNode: Entry ← (entry ← 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
        thisNode1: Entry = paramZones.gc.CONS[--DefaultValue--,NIL];
        BEGIN  -- Unmarshal thisNode1.first: Attribute from pkt.data[pktLength].
          BEGIN OPEN record: thisNode1.first;
          BEGIN  -- Unmarshal record.type: AttributeType from pkt.data[pktLength].
            [record.type, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
            END;  -- Unmarshal record.type.
          BEGIN  -- Unmarshal record.value: AttributeValue from pkt.data[pktLength].
            [record.value, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
                FALSE];
            END;  -- Unmarshal record.value.
          END;  -- OPEN record: thisNode1.first.
          END;  -- Unmarshal thisNode1.first.
        IF lastNode # NIL
          THEN lastNode ← (lastNode.rest ← thisNode1)
          ELSE lastNode ← (entry ← thisNode1);
        listLength ← listLength - 1;
        ENDLOOP;  -- WHILE listLength > 0.
      END;  -- Unmarshal entry.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    IF onePkt
      THEN WriteEntry[localConversation, argPkt.db, entry, argPkt.log,
          argPkt.replace]
      ELSE WriteEntry[localConversation, db, entry, log, replace];
    END;  -- OnePkt.
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- WriteEntryStub.

  DeleteEntryStub: --PROCEDURE [conv: Conv, db: OpenDB, key: AttributeType,
      -- value: AttributeValue]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    db: OpenDB;
    key: AttributeType;
    value: AttributeValue;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [db: db] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal key: AttributeType from pkt.data[pktLength].
      [key, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
      END;  -- Unmarshal key.
    BEGIN  -- Unmarshal value: AttributeValue from pkt.data[pktLength].
      [value, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength, FALSE];
      END;  -- Unmarshal value.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    IF onePkt
      THEN DeleteEntry[localConversation, argPkt.db, key, value]
      ELSE DeleteEntry[localConversation, db, key, value];
    END;  -- OnePkt.
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- DeleteEntryStub.

  CloseStub: --PROCEDURE [conv: Conv, db: OpenDB]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    Close[localConversation, argPkt.db];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- CloseStub.

  BuildIndicesStub: --PROCEDURE [conv: Conv, db: OpenDB]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    BuildIndices[localConversation, argPkt.db];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- BuildIndicesStub.

  CompactLogsStub: --PROCEDURE [conv: Conv, db: OpenDB]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, db (1): OpenDB];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    CompactLogs[localConversation, argPkt.db];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- CompactLogsStub.


-- Marshall/Unmarshal procedures.


-- No module initialization.

END.  -- LoganBerryRpcServerImpl.