[comp.lang.modula2] Best way to handle variable length fields within records

Pieter.Muller@f11.n492.z5.fidonet.org (Pieter Muller) (08/21/90)

Novell uses the following type of request packet in their Netware API:

  Request :RECORD
             Len      :Types.Word;
             Func     :Types.Byte;
             ObjT     :Types.Word;
             ONameLen :Types.Byte;
             OName    :ARRAY [1..47] OF CHAR;
             Seq      :Types.iDWord;
             PNameLen :Types.Byte;
             PName    :ARRAY [1..15] OF CHAR;
           END;

My problem is that OName is really a variable length field, and if 
it is shorter than 47 characters, the rest of the record has to be moved down 
to pack it tightly.  The same goes for PName.

At the moment I use JPI's Lib.Move to move the end of the RECORD in on 
itself, but this is rather messy.

What is the most elegant way to program this in Modula-2?

(BTW Someone suggested the following workaround for this specific Netware 
function:  I can pad OName with zeros and set ONameLen to 47.  But this is 
even more messy because it doesn't follow Novell's specs.)

-- Pieter



--  
uucp: uunet!m2xenix!puddle!5!492!11!Pieter.Muller
Internet: Pieter.Muller@f11.n492.z5.fidonet.org