-- fortytwoGetPutImpl.mesa
-- Please do not edit this file.
-- It was generated using CedarRPCGen.

DIRECTORY
  Rope,
  SunRPC,
  fortyone,
  fourtwo,
  fourtwoGetPut,
  fortytwo,
  fortytwoGetPut;

fortytwoGetPutImpl: CEDAR PROGRAM
  IMPORTS SunRPC, fourtwoGetPut  EXPORTS fortytwo, fortytwoGetPut =
BEGIN
Handle: TYPE = SunRPC.Handle;

ROPE: TYPE = Rope.ROPE;

GetQuestionType: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.QuestionType] = {
    res ← VAL[SunRPC.GetInt32[h]];
  };

PutQuestionType: PUBLIC PROC[h: Handle, in: fortytwo.QuestionType] = {
    SunRPC.PutInt32[h, ORD[in]];
  };

Question1TypeNames: PUBLIC ARRAY fortytwo.Question1Type OF ROPE ← [
	"boooring",
	"cooosmic",
	"univeeersal",
	"stuuupid",
	"sillly"
	];

GetQuestion1Type: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.Question1Type] = {
    res ← VAL[SunRPC.GetInt32[h]];
  };

PutQuestion1Type: PUBLIC PROC[h: Handle, in: fortytwo.Question1Type] = {
    SunRPC.PutInt32[h, ORD[in]];
  };

GetanswerRecType: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.answerRecType] = {
    res ← fourtwoGetPut.GetanswerRec[h];
  };

PutanswerRecType: PUBLIC PROC[h: Handle, in: fortytwo.answerRecType] = {
    fourtwoGetPut.PutanswerRec[h, in];
  };

GetTheANSWER: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.TheANSWER] = {
    tag: fortytwo.QuestionType;
    tag ← GetQuestionType[h];
    SELECT tag FROM
      boring => {
          v: REF boring fortytwo.TheANSWERObject ← NEW[boring fortytwo.TheANSWERObject];
          FOR i: INT IN [0..13) DO
            v.b[i] ← SunRPC.GetByte[h];
            ENDLOOP;
          SunRPC.GetAlign[h];
          res ← v;
          };
      cosmic => {
          v: REF cosmic fortytwo.TheANSWERObject ← NEW[cosmic fortytwo.TheANSWERObject];
          v.c ← SunRPC.GetInt32[h];
          res ← v;
          };
      stupid => {
          v: REF stupid fortytwo.TheANSWERObject ← NEW[stupid fortytwo.TheANSWERObject];
          res ← v;
          };
      silly => {
          v: REF silly fortytwo.TheANSWERObject ← NEW[silly fortytwo.TheANSWERObject];
          IF SunRPC.GetInt32[h] # 0 THEN {
            v.d ← NEW[fourtwo.answerRec];
            v.d↑ ← fourtwoGetPut.GetanswerRec[h];
            }
          ELSE
            v.d ← NIL;
          res ← v;
        };
      universal => {
          v: REF universal fortytwo.TheANSWERObject ← NEW[universal fortytwo.TheANSWERObject];
          IF SunRPC.GetInt32[h] # 0 THEN {
            v.d ← NEW[fourtwo.answerRec];
            v.d↑ ← fourtwoGetPut.GetanswerRec[h];
            }
          ELSE
            v.d ← NIL;
          res ← v;
        };
      ENDCASE => NULL;
  };

PutTheANSWER: PUBLIC PROC[h: Handle, in: fortytwo.TheANSWER] = {
    PutQuestionType[h, in.truthType];
    SELECT in.truthType FROM
      boring => {
          v: REF boring fortytwo.TheANSWERObject ← NARROW[in];
          FOR i: INT IN [0..13) DO
            SunRPC.PutByte[h, v.b[i]];
            ENDLOOP;
          SunRPC.PutAlign[h];
          };
      cosmic => {
          v: REF cosmic fortytwo.TheANSWERObject ← NARROW[in];
          SunRPC.PutInt32[h, v.c];
          };
      stupid => {
          v: REF stupid fortytwo.TheANSWERObject ← NARROW[in];
          };
      silly => {
          v: REF silly fortytwo.TheANSWERObject ← NARROW[in];
          IF v.d = NIL THEN {
            SunRPC.PutInt32[h, 0];
          }
          ELSE {
            SunRPC.PutInt32[h, 1];
            fourtwoGetPut.PutanswerRec[h, v.d↑];
          };
        };
      universal => {
          v: REF universal fortytwo.TheANSWERObject ← NARROW[in];
          IF v.d = NIL THEN {
            SunRPC.PutInt32[h, 0];
          }
          ELSE {
            SunRPC.PutInt32[h, 1];
            fourtwoGetPut.PutanswerRec[h, v.d↑];
          };
        };
      ENDCASE => NULL;
  };

GetYetAnotherAnswer: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.YetAnotherAnswer] = {
    tag: INT32;
    tag ← VAL[SunRPC.GetInt32[h]];
    SELECT tag FROM
      0 => {
          v: REF v0 fortytwo.YetAnotherAnswerObject ← NEW[v0 fortytwo.YetAnotherAnswerObject];
          v.answer ← GetQuestionType[h];
          res ← v;
          };
      1 => {
          v: REF v1 fortytwo.YetAnotherAnswerObject ← NEW[v1 fortytwo.YetAnotherAnswerObject];
          v.a ← SunRPC.GetInt32[h];
          res ← v;
          };
      ENDCASE => {
          v: REF default fortytwo.YetAnotherAnswerObject ← NEW[default fortytwo.YetAnotherAnswerObject];
          v.responseType ← tag;
        res ← v;
        };
  };

PutYetAnotherAnswer: PUBLIC PROC[h: Handle, in: fortytwo.YetAnotherAnswer] = {
    SunRPC.PutInt32[h, ORD[in.responseType]];
    SELECT in.responseType FROM
      0 => {
          v: REF v0 fortytwo.YetAnotherAnswerObject ← NARROW[in];
          PutQuestionType[h, v.answer];
          };
      1 => {
          v: REF v1 fortytwo.YetAnotherAnswerObject ← NARROW[in];
          SunRPC.PutInt32[h, v.a];
          };
      ENDCASE => {
          v: REF default fortytwo.YetAnotherAnswerObject ← NARROW[in];
        };
  };

GettrueAnswerRec: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.trueAnswerRec] = {
    res.tellingTheTruth ← SunRPC.GetInt32[h] # 0;
    FOR i: INT IN [0..fortyone.TRUTHSIZE) DO
      res.theTruth[i] ← SunRPC.GetInt32[h];
      ENDLOOP;
    res.theTRUTH ← GetTheANSWER[h];
  };

PuttrueAnswerRec: PUBLIC PROC[h: Handle, in: fortytwo.trueAnswerRec] = {
    SunRPC.PutInt32[h, IF in.tellingTheTruth THEN 1 ELSE 0];
    FOR i: INT IN [0..fortyone.TRUTHSIZE) DO
      SunRPC.PutInt32[h, in.theTruth[i]];
      ENDLOOP;
    PutTheANSWER[h, in.theTRUTH];
  };

GettrueQuestionRec: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.trueQuestionRec] = {
    res.questionType ← GetQuestionType[h];
    {
    len: INT ← SunRPC.GetInt32[h];
    res.randomNumbers ← NEW[fortytwo.SeqType0Object[len]];
    FOR i: INT IN [0..len) DO
      res.randomNumbers[i] ← SunRPC.GetInt32[h];
      ENDLOOP;
    };
  };

PuttrueQuestionRec: PUBLIC PROC[h: Handle, in: fortytwo.trueQuestionRec] = {
    PutQuestionType[h, in.questionType];
    SunRPC.PutInt32[h, in.randomNumbers.size];
    FOR i: INT IN [0..in.randomNumbers.size) DO
      SunRPC.PutInt32[h, in.randomNumbers[i]];
      ENDLOOP;
  };

GetQuestionRec: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.QuestionRec] = {
    res ← GettrueQuestionRec[h];
  };

PutQuestionRec: PUBLIC PROC[h: Handle, in: fortytwo.QuestionRec] = {
    PuttrueQuestionRec[h, in];
  };

GetAnswerRec: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.AnswerRec] = {
    res ← GettrueAnswerRec[h];
  };

PutAnswerRec: PUBLIC PROC[h: Handle, in: fortytwo.AnswerRec] = {
    PuttrueAnswerRec[h, in];
  };

GetQuestionRecPtr: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.QuestionRecPtr] = {
    IF SunRPC.GetInt32[h] # 0 THEN {
      res ← NEW[fortytwo.QuestionRec];
      res↑ ← GetQuestionRec[h];
      }
    ELSE
      res ← NIL;
  };

PutQuestionRecPtr: PUBLIC PROC[h: Handle, in: fortytwo.QuestionRecPtr] = {
    IF in = NIL THEN {
      SunRPC.PutInt32[h, 0];
    }
    ELSE {
      SunRPC.PutInt32[h, 1];
      PutQuestionRec[h, in↑];
    };
  };

GetQuestionRecArray: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.QuestionRecArray] = {
    {
    len: INT ← SunRPC.GetInt32[h];
    res ← NEW[fortytwo.SeqType1Object[len]];
    FOR i: INT IN [0..len) DO
      res[i] ← GetQuestionRec[h];
      ENDLOOP;
    };
  };

PutQuestionRecArray: PUBLIC PROC[h: Handle, in: fortytwo.QuestionRecArray] = {
    SunRPC.PutInt32[h, in.size];
    FOR i: INT IN [0..in.size) DO
      PutQuestionRec[h, in[i]];
      ENDLOOP;
  };

GetQuestionRecArray1: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.QuestionRecArray1] = {
    FOR i: INT IN [0..13) DO
      res[i] ← GetQuestionRec[h];
      ENDLOOP;
  };

PutQuestionRecArray1: PUBLIC PROC[h: Handle, in: fortytwo.QuestionRecArray1] = {
    FOR i: INT IN [0..13) DO
      PutQuestionRec[h, in[i]];
      ENDLOOP;
  };

Gettuple: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.tuple] = {
    res.x ← SunRPC.GetInt32[h];
    res.y ← SunRPC.GetInt32[h];
  };

Puttuple: PUBLIC PROC[h: Handle, in: fortytwo.tuple] = {
    SunRPC.PutInt32[h, in.x];
    SunRPC.PutInt32[h, in.y];
  };

GetrandomTypes: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.randomTypes] = {
    res.a ← SunRPC.GetReal[h];
    res.b ← SunRPC.GetDReal[h];
    [] ← SunRPC.GetByte[h];
    [] ← SunRPC.GetByte[h];
    [] ← SunRPC.GetByte[h];
    res.c ← SunRPC.GetByte[h];
    res.d ← SunRPC.GetInt32[h];
    res.e ← SunRPC.GetInt32[h];
    res.f ← SunRPC.GetInt32[h];
    [] ← SunRPC.GetByte[h];
    [] ← SunRPC.GetByte[h];
    [] ← SunRPC.GetByte[h];
    res.g ← SunRPC.GetByte[h];
    res.h ← SunRPC.GetCard32[h];
    res.i ← SunRPC.GetCard32[h];
    res.j ← SunRPC.GetCard32[h];
    {
    len: INT ← SunRPC.GetInt32[h];
    res.k ← NEW[fortytwo.SeqType2Object[len]];
    FOR i: INT IN [0..len) DO
      res.k[i] ← Gettuple[h];
      ENDLOOP;
    };
    FOR i: INT IN [0..3) DO
      res.l[i] ← SunRPC.GetByte[h];
      ENDLOOP;
    SunRPC.GetAlign[h];
    {
    len: INT ← SunRPC.GetInt32[h];
    res.m ← NEW[fortytwo.SeqType3Object[len]];
    FOR i: INT IN [0..len) DO
      [] ← SunRPC.GetByte[h];
      [] ← SunRPC.GetByte[h];
      [] ← SunRPC.GetByte[h];
      res.m[i] ← SunRPC.GetByte[h];
      ENDLOOP;
    };
  };

PutrandomTypes: PUBLIC PROC[h: Handle, in: fortytwo.randomTypes] = {
    SunRPC.PutReal[h, in.a];
    SunRPC.PutDReal[h, in.b];
    SunRPC.PutInt32[h, in.c];
    SunRPC.PutInt32[h, in.d];
    SunRPC.PutInt32[h, in.e];
    SunRPC.PutInt32[h, in.f];
    SunRPC.PutInt32[h, in.g];
    SunRPC.PutCard32[h, in.h];
    SunRPC.PutCard32[h, in.i];
    SunRPC.PutCard32[h, in.j];
    SunRPC.PutInt32[h, in.k.size];
    FOR i: INT IN [0..in.k.size) DO
      Puttuple[h, in.k[i]];
      ENDLOOP;
    FOR i: INT IN [0..3) DO
      SunRPC.PutByte[h, in.l[i]];
      ENDLOOP;
    SunRPC.PutAlign[h];
    SunRPC.PutInt32[h, in.m.size];
    FOR i: INT IN [0..in.m.size) DO
      SunRPC.PutInt32[h, in.m[i]];
      ENDLOOP;
  };

GetFooBar: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.FooBar] = {
    res ← SunRPC.GetInt32[h];
  };

PutFooBar: PUBLIC PROC[h: Handle, in: fortytwo.FooBar] = {
    SunRPC.PutInt32[h, in];
  };

Getfoo: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.foo] = {
    tag: CARD32;
    tag ← SunRPC.GetCard32[h];
    SELECT tag FROM
      1 => {
          v: REF v1 fortytwo.fooObject ← NEW[v1 fortytwo.fooObject];
          v.a ← SunRPC.GetCard32[h];
          res ← v;
          };
      2 => {
          v: REF v2 fortytwo.fooObject ← NEW[v2 fortytwo.fooObject];
          {
          len: INT ← SunRPC.GetInt32[h];
          v.b ← NEW[fortytwo.SeqType4Object[len]];
          FOR i: INT IN [0..len) DO
            v.b[i] ← SunRPC.GetCard32[h];
            ENDLOOP;
          };
          res ← v;
          };
      3 => {
          v: REF v3 fortytwo.fooObject ← NEW[v3 fortytwo.fooObject];
          FOR i: INT IN [0..42) DO
            [] ← SunRPC.GetByte[h];
            [] ← SunRPC.GetByte[h];
            [] ← SunRPC.GetByte[h];
            v.c[i] ← SunRPC.GetByte[h];
            ENDLOOP;
          res ← v;
          };
      4 => {
          v: REF v4 fortytwo.fooObject ← NEW[v4 fortytwo.fooObject];
          {
          len: INT ← SunRPC.GetInt32[h];
          v.d ← NEW[fortytwo.SeqType5Object[len]];
          FOR i: INT IN [0..len) DO
            v.d[i] ← SunRPC.GetCard32[h];
            ENDLOOP;
          };
          res ← v;
          };
      ENDCASE => {
          v: REF default fortytwo.fooObject ← NEW[default fortytwo.fooObject];
          v.desc ← tag;
        [] ← SunRPC.GetByte[h];
        [] ← SunRPC.GetByte[h];
        [] ← SunRPC.GetByte[h];
        v.e ← SunRPC.GetByte[h];
        res ← v;
        };
  };

Putfoo: PUBLIC PROC[h: Handle, in: fortytwo.foo] = {
    SunRPC.PutCard32[h, in.desc];
    SELECT in.desc FROM
      1 => {
          v: REF v1 fortytwo.fooObject ← NARROW[in];
          SunRPC.PutCard32[h, v.a];
          };
      2 => {
          v: REF v2 fortytwo.fooObject ← NARROW[in];
          SunRPC.PutInt32[h, v.b.size];
          FOR i: INT IN [0..v.b.size) DO
            SunRPC.PutCard32[h, v.b[i]];
            ENDLOOP;
          };
      3 => {
          v: REF v3 fortytwo.fooObject ← NARROW[in];
          FOR i: INT IN [0..42) DO
            SunRPC.PutInt32[h, v.c[i]];
            ENDLOOP;
          };
      4 => {
          v: REF v4 fortytwo.fooObject ← NARROW[in];
          SunRPC.PutInt32[h, v.d.size];
          FOR i: INT IN [0..v.d.size) DO
            SunRPC.PutCard32[h, v.d[i]];
            ENDLOOP;
          };
      ENDCASE => {
          v: REF default fortytwo.fooObject ← NARROW[in];
        SunRPC.PutInt32[h, v.e];
        };
  };

Getbarr: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.barr] = {
    res.a ← SunRPC.GetCard32[h];
    {
    len: INT ← SunRPC.GetInt32[h];
    res.b ← NEW[fortytwo.SeqType6Object[len]];
    FOR i: INT IN [0..len) DO
      res.b[i] ← SunRPC.GetCard32[h];
      ENDLOOP;
    };
    FOR i: INT IN [0..13) DO
      [] ← SunRPC.GetByte[h];
      [] ← SunRPC.GetByte[h];
      [] ← SunRPC.GetByte[h];
      res.c[i] ← SunRPC.GetByte[h];
      ENDLOOP;
    IF SunRPC.GetInt32[h] # 0 THEN {
      res.d ← NEW[CARD32];
      res.d↑ ← SunRPC.GetCard32[h];
      }
    ELSE
      res.d ← NIL;
  };

Putbarr: PUBLIC PROC[h: Handle, in: fortytwo.barr] = {
    SunRPC.PutCard32[h, in.a];
    SunRPC.PutInt32[h, in.b.size];
    FOR i: INT IN [0..in.b.size) DO
      SunRPC.PutCard32[h, in.b[i]];
      ENDLOOP;
    FOR i: INT IN [0..13) DO
      SunRPC.PutInt32[h, in.c[i]];
      ENDLOOP;
    IF in.d = NIL THEN {
      SunRPC.PutInt32[h, 0];
    }
    ELSE {
      SunRPC.PutInt32[h, 1];
      SunRPC.PutCard32[h, in.d↑];
    };
  };

GetULONG: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.ULONG] = {
    res ← SunRPC.GetCard32[h];
  };

PutULONG: PUBLIC PROC[h: Handle, in: fortytwo.ULONG] = {
    SunRPC.PutCard32[h, in];
  };

Getfoobar: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.foobar] = {
    {
    len: INT ← SunRPC.GetInt32[h];
    res ← NEW[fortytwo.SeqType7Object[len]];
    FOR i: INT IN [0..len) DO
      res[i] ← SunRPC.GetCard32[h];
      ENDLOOP;
    };
  };

Putfoobar: PUBLIC PROC[h: Handle, in: fortytwo.foobar] = {
    SunRPC.PutInt32[h, in.size];
    FOR i: INT IN [0..in.size) DO
      SunRPC.PutCard32[h, in[i]];
      ENDLOOP;
  };

Getfoobaz: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.foobaz] = {
    FOR i: INT IN [0..137) DO
      [] ← SunRPC.GetByte[h];
      [] ← SunRPC.GetByte[h];
      [] ← SunRPC.GetByte[h];
      res[i] ← SunRPC.GetByte[h];
      ENDLOOP;
  };

Putfoobaz: PUBLIC PROC[h: Handle, in: fortytwo.foobaz] = {
    FOR i: INT IN [0..137) DO
      SunRPC.PutInt32[h, in[i]];
      ENDLOOP;
  };

Getfoobarrr: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.foobarrr] = {
    IF SunRPC.GetInt32[h] # 0 THEN {
      res ← NEW[CARD32];
      res↑ ← SunRPC.GetCard32[h];
      }
    ELSE
      res ← NIL;
  };

Putfoobarrr: PUBLIC PROC[h: Handle, in: fortytwo.foobarrr] = {
    IF in = NIL THEN {
      SunRPC.PutInt32[h, 0];
    }
    ELSE {
      SunRPC.PutInt32[h, 1];
      SunRPC.PutCard32[h, in↑];
    };
  };

Getbar: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.bar] = {
    tag: BOOLEAN;
    tag ← VAL[SunRPC.GetInt32[h]];
    SELECT tag FROM
      TRUE => {
          v: REF TRUE fortytwo.barObject ← NEW[TRUE fortytwo.barObject];
          v.a ← SunRPC.GetInt32[h];
          res ← v;
          };
      FALSE => {
          v: REF FALSE fortytwo.barObject ← NEW[FALSE fortytwo.barObject];
          [] ← SunRPC.GetByte[h];
          [] ← SunRPC.GetByte[h];
          [] ← SunRPC.GetByte[h];
          v.b ← SunRPC.GetByte[h];
          res ← v;
          };
      ENDCASE => NULL;
  };

Putbar: PUBLIC PROC[h: Handle, in: fortytwo.bar] = {
    SunRPC.PutInt32[h, ORD[in.desc]];
    SELECT in.desc FROM
      TRUE => {
          v: REF TRUE fortytwo.barObject ← NARROW[in];
          SunRPC.PutInt32[h, v.a];
          };
      FALSE => {
          v: REF FALSE fortytwo.barObject ← NARROW[in];
          SunRPC.PutInt32[h, v.b];
          };
      ENDCASE => NULL;
  };

GetTestNamesArray: PUBLIC PROC[h: Handle] RETURNS [res: fortytwo.TestNamesArray] = {
    res ← VAL[SunRPC.GetInt32[h]];
  };

PutTestNamesArray: PUBLIC PROC[h: Handle, in: fortytwo.TestNamesArray] = {
    SunRPC.PutInt32[h, ORD[in]];
  };

END.