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

version» Context lines:

pike.git/lib/modules/ADT.pmod/module.pmod:103:    //! to the buffer.    this_program put_fix_uint_array(array(int) data, int(0..) item_size)    {    foreach(data, int i)    put_uint(i, item_size);    return this;    }       //! Appends an array of unsigned integers of width @[item_size]    //! to the buffer, preceded with an unsigned integer @[len] declaring -  //! the size of the array. +  //! the size of the array in bytes.    this_program put_var_uint_array(array(int) data, int(0..) item_size, int(0..) len)    { -  put_uint(sizeof(data), len); +  put_uint(sizeof(data)*item_size, 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)    throw(structError("No data.\n"));
pike.git/lib/modules/ADT.pmod/module.pmod:167:    array(int) res = allocate(size);    for(int i = 0; i<size; i++)    res[i] = get_uint(item_size);    return res;    }       //! Reads an array of integers as written by @[put_var_uint_array]    //! from the buffer.    array(int) get_var_uint_array(int item_size, int len)    { -  return get_fix_uint_array(item_size, get_uint(len)); +  int size = get_uint(len); +  int elems = size/item_size; +  if( elems*item_size != size ) +  throw(structError("Impossible uint array length value.\n")); +  return get_fix_uint_array(item_size, elems);    }       //! Returns one of there is any more data to read.    int(0..1) is_empty()    {    return (index == sizeof(buffer));    }       protected int(0..) _sizeof()    {    return [int(0..)](sizeof(buffer)-index);    }       protected string _sprintf(int t)    {    return t=='O' && sprintf("%O(%O)", this_program, _sizeof());    }   }