6aa8ef2001-05-23Per Hedbor struct buffer {
1b7a452001-05-31Per Hedbor  unsigned int size; /* Write pos */ unsigned int rpos; /* Read pos */
6aa8ef2001-05-23Per Hedbor  int read_only;
1b7a452001-05-31Per Hedbor  /* If 1, the buffer cannot be written to (data points to str->str) */
13670c2015-05-25Martin Nilsson 
1b7a452001-05-31Per Hedbor  unsigned int allocated_size; /* The actual allocated size */
6aa8ef2001-05-23Per Hedbor 
396fbd2016-08-10Anders Johansson  unsigned char *data;
1b7a452001-05-31Per Hedbor 
6aa8ef2001-05-23Per Hedbor  struct pike_string *str;
1b7a452001-05-31Per Hedbor  /* Used when read_only==1, to save memory. Data points to str->str, * and str has an extra reference. When the buffer is freed, the * reference is freed. */
6aa8ef2001-05-23Per Hedbor };
1b7a452001-05-31Per Hedbor /* Note: All w* and r* functions write and read to the buffer in NBO * (most significant byte first ) * * They also handle unaligned data */
6aa8ef2001-05-23Per Hedbor 
4ac4882017-04-30Martin Nilsson struct buffer *wf_buffer_new( void );
1b7a452001-05-31Per Hedbor /* Create a new (uninitalized) buffer. Use wf_buffer_set_empty or * wf_buffer_set_pike_string to initialize it. */
6aa8ef2001-05-23Per Hedbor void wf_buffer_free( struct buffer *b );
1b7a452001-05-31Per Hedbor /* Free the contents of the buffer and then the buffer */
6aa8ef2001-05-23Per Hedbor  void wf_buffer_clear( struct buffer *b );
1b7a452001-05-31Per Hedbor /* Free the contents of the buffer, Use wf_buffer_set_empty or * wf_buffer_set_pike_string to initialize it again. */
6aa8ef2001-05-23Per Hedbor void wf_buffer_set_empty( struct buffer *b );
1b7a452001-05-31Per Hedbor /* Sets the contents of the buffer to an empty string, and read_only to 0. * This creates a writable buffer. */
6aa8ef2001-05-23Per Hedbor void wf_buffer_set_pike_string( struct buffer *b, struct pike_string *data, int read_only );
1b7a452001-05-31Per Hedbor /* Sets the contents of the buffer to the supplied pikestring, if * read_only is 1, the string is not copied, instead a reference is * added to it. * * To free the data, wf_buffer_clear must be called. */ void wf_buffer_wbyte( struct buffer *b, unsigned char s ); /* Write a byte to the buffer.
13670c2015-05-25Martin Nilsson  * read_only must be 0
1b7a452001-05-31Per Hedbor  */
6aa8ef2001-05-23Per Hedbor 
1b7a452001-05-31Per Hedbor void wf_buffer_wshort( struct buffer *b, unsigned short s );
13670c2015-05-25Martin Nilsson /* Write a (16 bit) short to the buffer. * read_only must be 0
1b7a452001-05-31Per Hedbor  */ void wf_buffer_wint( struct buffer *b, unsigned int s ); /* Write a (32 bit) int to the buffer.
13670c2015-05-25Martin Nilsson  * read_only must be 0
1b7a452001-05-31Per Hedbor  */ int wf_buffer_rbyte( struct buffer *b ); /* Read a byte from the buffer. * If wf_buffer_eof() is true, 0 is returned. */ unsigned int wf_buffer_rint( struct buffer *b ); /* Read an integer from the buffer. * If wf_buffer_eof() is true, 0 is returned. */ int wf_buffer_rshort( struct buffer *b ); /* Read a short from the buffer * If wf_buffer_eof() is true, 0 is returned. */ int wf_buffer_eof( struct buffer *b ); /* Returns 1 if the buffer does not have any more data to _read_ */ void wf_buffer_seek( struct buffer *b, unsigned int pos ); /* Move the read position to pos. if pos is greater than or equal the * size of the buffer, read_pos is moved to the end of the buffer
13670c2015-05-25Martin Nilsson  * instead.
1b7a452001-05-31Per Hedbor  */ void wf_buffer_seek_w( struct buffer *b, unsigned int pos ); /* Set the write position to pos. If pos is greater than the current * size of the buffer, the data segment created is zeroed. */
13670c2015-05-25Martin Nilsson 
396fbd2016-08-10Anders Johansson void wf_buffer_append( struct buffer *b, unsigned char *data, int size );
13670c2015-05-25Martin Nilsson /* Append the specified data to the buffer.
1b7a452001-05-31Per Hedbor  * read_only must be 0. */
6488792001-05-24Per Hedbor int wf_buffer_memcpy( struct buffer *d, struct buffer *s, int nelems );
1b7a452001-05-31Per Hedbor /* Write nelems elements of data from s to d. * read_only must be 0. */
6aa8ef2001-05-23Per Hedbor 
1b7a452001-05-31Per Hedbor void wf_buffer_rewind_r( struct buffer *b, int n ); /* Subtract n from read_pos. * If n == -1, the position is set to 0. */
6aa8ef2001-05-23Per Hedbor 
1b7a452001-05-31Per Hedbor void wf_buffer_rewind_w( struct buffer *b, int n ); /* Subtract n from size. * If n == -1, the size is set to 0. */