pike.git / lib / modules / ADT.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/ADT.pmod/module.pmod:6: Inside #if constant(_ADT)
  #if constant(_ADT)   inherit _ADT;   #endif /* _ADT */      constant List = __builtin.List;      // Internal stuff for ADT.Struct   protected int item_counter;   int get_item_id() { return item_counter++; }    + protected class structError + { +  inherit Error.Generic; +  constant ADT_struct = 1; + } +    //! String buffer with the possibility to read and write data   //! as they would be formatted in structs.   class struct {       string(0..255) buffer;    int index;       //! Create a new buffer, optionally initialized with the    //! value @[s].    void create(void|string(0..255) s)
pike.git/lib/modules/ADT.pmod/module.pmod:54:       //! Appends an unsigned integer in network order to the buffer.    //!    //! @param i    //! Unsigned integer to append.    //! @param len    //! Length of integer in bytes.    this_program put_uint(int i, int(0..) len)    {    if (i<0) -  error("Negative argument.\n"); +  throw(structError("Negative argument.\n"));    add_data([string(0..255)]sprintf("%*c", len, i));    return this;    }       //! Appends a variable stringĀ @[s] preceded with an unsigned integer    //! of the size @[len_width] declaring the length of the string. The    //! string @[s] should be 8 bits wide.    this_program put_var_string(string(0..255) s, int(0..) len_width)    {    add_data([string(0..255)]sprintf("%*H", len_width, s));    return this;    }       //! Appends a bignum @[i] as a variable string preceded with an    //! unsigned integer of the size @[len_width] declaring the length    //! of the string. @[len_width] defaults to 2.    this_program put_bignum(Gmp.mpz i, int(0..)|void len_width)    {    if (i<0) -  error("Negative argument.\n"); +  throw(structError("Negative argument.\n"));    put_var_string(i->digits(256), len_width || 2);    return this;    }       //! Appends the fix sized string @[s] to the buffer.    this_program put_fix_string(string(0..255) s)    {    add_data(s);    return this;    }
pike.git/lib/modules/ADT.pmod/module.pmod:110:    put_uint(sizeof(data), len);    put_fix_uint_array(data, item_size);    return this;    }       //! Reads an unsigned integer from the buffer.    int(0..) get_uint(int len)    {    int(0..) i;    if ( (sizeof(buffer) - index) < len) -  error("No data.\n"); +  throw(structError("No data.\n"));    sscanf(buffer, "%*" + (string) index +"s%" + (string) len + "c", i);    index += len;    return i;    }       //! Reads a fixed sized string of length @[len] from the buffer.    string(0..255) get_fix_string(int len)    {    if ((sizeof(buffer) - index) < len) -  error("No data\n"); +  throw(structError("No data\n"));       string(0..255) res = buffer[index .. index + len - 1];    index += len;    return res;    }       //! Reads a string written by @[put_var_string] from the buffer.    string(0..255) get_var_string(int len)    {    return get_fix_string(get_uint(len));