Pike v8.1 release 6

Class ADT.Struct

Description

Implements a struct which can be used for serialization and deserialization of data.

Example

class ID3 { inherit ADT.Struct; Item head = Chars(3); Item title = Chars(30); Item artist = Chars(30); Item album = Chars(30); Item year = Chars(4); Item comment = Chars(30); Item genre = Byte(); }

Stdio.File f = Stdio.File("foo.mp3"); f->seek(-128); ADT.Struct tag = ID3(f); if(tag->head=="TAG") { write("Title: %s\n", tag->title); tag->title = "A new title" + "\0"*19; f->seek(-128); f->write( (string)tag ); }

Example

class HollerithString { inherit ADT.Struct; Item strlen = Word(); Item str = Chars(strlen); }


Method create

ADT.Struct ADT.Struct(void|string|Stdio.File data)

Parameter data

Data to be decoded and populate the struct. Can either be a file object or a string.