<commit_before>#ifndef RAWPACKET_H_INCLUDED_C51B6961
#define RAWPACKET_H_INCLUDED_C51B6961

/* GNE - Game Networking Engine, a portable multithreaded networking library.
 * Copyright (C) 2001 <NAME> (<EMAIL>)
 * Project website: http://www.rit.edu/~jpw9607/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "gneintern.h"

namespace GNE {
class Packet;

/**
 * A utility class for creating a raw block of data that is used to directly
 * send data through the socket, and on the other side, parse it into
 * system-dependant data.  Users of GNE can also use this class to serialize
 * packets into a form suitable to be sent over their own types of network
 * connections or saved/loaded from a file.  A neat trick might be implemented
 * where a file can "mimic" a server to provide the necessary packets to
 * restore the game state.\n
 * See the example "expacket" for an example of the usage of this class.
 * \bug I don't think RawPacket handles signed ordinals properly yet.
 */
//##ModelId=3B075380030F
class RawPacket {
public:
  /**
   * Create a new RawPacket, optionally with a buffer.  If you pass NULL to
   * this constructor, a new internal buffer will be created, and this
   * RawPacket will then be meant for writing to only.  If you pass a buffer
   * to this constructor, this object will be meant from reading from only.
   * If you pass a buffer into RawPacket, you should delete it yourself later.
   * @param buffer NULL for a writable object, or your own buffer for a
   *               readable object, which you will destroy after this object
   *               has been destroyed.
   */
  //##ModelId=3B075381022A
  RawPacket(gbyte* buffer = NULL);

  /**
   * Destroys this object.  The data buffer will be destroyed at this point,
   * so you cannot use any pointers you got back from getData() after this
   * point.
   */
  //##ModelId=3B075381022C
  virtual ~RawPacket();

  /**
   * Gets the raw block of data.  This will be used by the library to get the
   * data that will actually be sent out to the socket.
   */
  //##ModelId=3B075381022E
  const gbyte* getData() const;

  /**
   * Returns the position in the buffer from 0.  If you are writing to this
   * RawPacket, this will give the next writing position -- which will also
   * be the length of the data written thus far.  If you are reading, this
   * will be the position of the next byte to be read -- the amount of data
   * read thus far.  This way you can tell how much was written or how much
   * was read back in bytes.
   */
  //##ModelId=3B0753810230
  int getPosition() const;

  /**
   * Resets the reading/writing position back to 0.  When writing, this
   * essentially "erases" all data, and when reading this starts reading
   * from the beginning again.
   */
  //##ModelId=3B0753810232
  void reset();

  /**
   * Writes raw data starting at the current position.  This acts just like
   * the memcpy command.
   */
  //##ModelId=3B0753810233
  void writeRaw(const gbyte* block, int length);

  /**
   * Like writeBlock, but just the other way around now :).
   * @see writeBlock
   */
  //##ModelId=3B0753810236
  void readRaw(gbyte* block, int length);

  /**
   * Stream operators for writing to this RawPacket.  All data is converted
   * when appropriate into little endian format.
   */
  //##ModelId=3B0753810239
  RawPacket& operator << (gint8 x);
  //##ModelId=3B075381023B
  RawPacket& operator << (guint8 x);
  //##ModelId=3B075381023D
  RawPacket& operator << (gint16 x);
  //##ModelId=3B075381023F
  RawPacket& operator << (guint16 x);<commit_msg>Doc updates.<commit_after>#ifndef RAWPACKET_H_INCLUDED_C51B6961
#define RAWPACKET_H_INCLUDED_C51B6961

/* GNE - Game Networking Engine, a portable multithreaded networking library.
 * Copyright (C) 2001 <NAME> (<EMAIL>)
 * Project website: http://www.rit.edu/~jpw9607/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "gneintern.h"

namespace GNE {
class Packet;

/**
 * A utility class for creating a raw block of data that is used to directly
 * send data through the socket, and on the other side, parse it into
 * system-dependant data.  Users of GNE can also use this class to serialize
 * packets into a form suitable to be sent over their own types of network
 * connections or saved/loaded from a file.  A neat trick might be implemented
 * where a file can "mimic" a server to provide the necessary packets to
 * restore the game state.
 *
 * See the example "expacket" for an example of the usage of this class.
 */
//##ModelId=3B075380030F
class RawPacket {
public:
  /**
   * Create a new RawPacket, optionally with a buffer.  If you pass NULL to
   * this constructor, a new internal buffer will be created, and this
   * RawPacket will then be meant for writing to only.  If you pass a buffer
   * to this constructor, this object will be meant from reading from only.
   * If you pass a buffer into RawPacket, you should delete it yourself later.
   * @param buffer NULL for a writable object, or your own buffer for a
   *               readable object, which you will destroy after this object
   *               has been destroyed.
   */
  //##ModelId=3B075381022A
  RawPacket(gbyte* buffer = NULL);

  /**
   * Destroys this object.  The data buffer will be destroyed at this point,
   * so you cannot use any pointers you got back from getData() after this
   * point.
   */
  //##ModelId=3B075381022C
  virtual ~RawPacket();

  /**
   * Gets the raw block of data.  This will be used by the library to get the
   * data that will actually be sent out to the socket.
   */
  //##ModelId=3B075381022E
  const gbyte* getData() const;

  /**
   * Returns the position in the buffer from 0.  If you are writing to this
   * RawPacket, this will give the next writing position -- which will also
   * be the length of the data written thus far.  If you are reading, this
   * will be the position of the next byte to be read -- the amount of data
   * read thus far.  This way you can tell how much was written or how much
   * was read back in bytes.
   */
  //##ModelId=3B0753810230
  int getPosition() const;

  /**
   * Resets the reading/writing position back to 0.  When writing, this
   * essentially "erases" all data, and when reading this starts reading
   * from the beginning again.
   */
  //##ModelId=3B0753810232
  void reset();

  /**
   * Writes raw data starting at the current position.  This acts similar to
   * the memcpy function.
   */
  //##ModelId=3B0753810233
  void writeRaw(const gbyte* block, int length);

  /**
   * Like writeRaw, but just the other way around now :).
   * @see writeRaw
   */
  //##ModelId=3B0753810236
  void readRaw(gbyte* block, int length);

  /**
   * Stream operators for writing to this RawPacket.  All data is converted
   * when appropriate into little endian format.
   */
  //##ModelId=3B0753810239
  RawPacket& operator << (gint8 x);
  //##ModelId=3B075381023B
  RawPacket& operator << (guint8 x);
  //##ModelId=3B075381023D
  RawPacket& operator << (gint16 x);
  //##ModelId=3B075381023F
  RawPacket& operator << (guint16 x);
{'fraction_non_alphanumeric': 0.07765731793542305, 'fraction_numerical': 0.03983030874381334, 'mean_word_length': 3.2140019860973186, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3290031', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2437, 'n_words': 1164}