<commit_before>// Filename: dcPacker.h
// Created by:  drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#ifndef DCPACKER_H
#define DCPACKER_H

#include "dcbase.h"
#include "dcPackerInterface.h"
#include "dcSubatomicType.h"
#include "dcPackData.h"
#include "dcPackerCatalog.h"
#include "dcPython.h"

class DCClass;
class DCSwitchParameter;

////////////////////////////////////////////////////////////////////
//       Class : DCPacker
// Description : This class can be used for packing a series of
//               numeric and string data into a binary stream,
//               according to the DC specification.
//
//               See also direct/src/doc/dcPacker.txt for a more
//               complete description and examples of using this
//               class.
////////////////////////////////////////////////////////////////////
class EXPCL_DIRECT DCPacker {
PUBLISHED:
  DCPacker();
  ~DCPacker();

  INLINE void clear_data();

  void begin_pack(const DCPackerInterface *root);
  bool end_pack();

  void set_unpack_data(const string &data);
public:
  void set_unpack_data(const char *unpack_data, size_t unpack_length, 
                       bool owns_unpack_data);

PUBLISHED:
  void begin_unpack(const DCPackerInterface *root);
  bool end_unpack();

  void begin_repack(const DCPackerInterface *root);
  bool end_repack();

  bool seek(const string &field_name);
  bool seek(int seek_index);

  INLINE bool has_nested_fields() const;
  INLINE int get_num_nested_fields() const;
  INLINE bool more_nested_fields() const;

  INLINE const DCPackerInterface *get_current_parent() const;
  INLINE const DCPackerInterface *get_current_field() const;
  INLINE const DCSwitchParameter *get_last_switch() const;
  INLINE DCPackType get_pack_type() const;

  void push();
  void pop();

  INLINE void pack_double(double value);
  INLINE void pack_int(int value);
  INLINE void pack_uint(unsigned int value);
  INLINE void pack_int64(PN_int64 value);
  INLINE void pack_uint64(PN_uint64 value);
  INLINE void pack_string(const string &value);
  INLINE void pack_literal_value(const string &value);
  void pack_default_value();

  INLINE double unpack_double();
  INLINE int unpack_int();
  INLINE unsigned int unpack_uint();
  INLINE PN_int64 unpack_int64();
  INLINE PN_uint64 unpack_uint64();
  INLINE string unpack_string();
  INLINE string unpack_literal_value();
  void unpack_validate();
  void unpack_skip();

public:
  // The following are variants on the above unpack() calls that pass
  // the result back by reference instead of as a return value.
  INLINE void unpack_double(double &value);
  INLINE void unpack_int(int &value);
  INLINE void unpack_uint(unsigned int &value);
  INLINE void unpack_int64(PN_int64 &value);
  INLINE void unpack_uint64(PN_uint64 &value);
  INLINE void unpack_string(string &value);
  INLINE void unpack_literal_value(string &value);

PUBLISHED:

#ifdef HAVE_PYTHON
  void pack_object(PyObject *object);
  PyObject *unpack_object();
#endif

  bool parse_and_pack(const string &formatted_object);
  bool parse_and_pack(istream &in);
  string unpack_and_format();
  void unpack_and_format(ostream &out);

  INLINE bool had_pack_error() const;
  INLINE bool had_range_error() const;
  INLINE bool had_error() const;
  INLINE size_t get_num_unpacked_bytes() const;

  INLINE size_t get_length() const;
  INLINE string get_string() const;
public:
  INLINE void get_string(string &data) const;
  INLINE const char *get_data() const;
  INLINE char *take_data();

  INLINE void append_data(const char *buffer, size_t size);
  INLINE char *get_write_pointer(size_t size);

PUBLISHED:
  INLINE static int get_num_stack_elements_ever_allocated();

  // The following methods are used only for packing (or unpacking)
  // raw data into the buffer between packing sessions (e.g. between
  // calls to end_pack() and the next begin_pack()).

  INLINE void raw_pack_int8(int value);
  INLINE void raw_pack_int16(int value);
  INLINE void raw_pack_int32(int value);
  INLINE void raw_pack_int64(PN_int64 value);
  INLINE void raw_pack_uint8(unsigned int value);
  INLINE void raw_pack_uint16(unsigned int value);
  INLINE void raw_pack_uint32(unsigned int value);
  INLINE void raw_pack_uint64(PN_uint64 value);
  INLINE void raw_pack_float64(double value);
  INLINE void raw_pack_string(const string &value);

// this is a hack to allw me to get in and out of 32bit Mode Faster
// need to agree with channel_type in dcbase.h
#define RAW_PACK_CHANNEL(in)  raw_pack_int64(in)
  

  INLINE int raw_unpack_int8();
  INLINE int raw_unpack_int16();
  INLINE int raw_unpack_int32();
  INLINE PN_int64 raw_unpack_int64();
  INLINE unsigned int raw_unpack_uint8();
  INLINE unsigned int raw_unpack_uint16();<commit_msg>channels are uint64 not int64 - typo fix<commit_after>// Filename: dcPacker.h
// Created by:  drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#ifndef DCPACKER_H
#define DCPACKER_H

#include "dcbase.h"
#include "dcPackerInterface.h"
#include "dcSubatomicType.h"
#include "dcPackData.h"
#include "dcPackerCatalog.h"
#include "dcPython.h"

class DCClass;
class DCSwitchParameter;

////////////////////////////////////////////////////////////////////
//       Class : DCPacker
// Description : This class can be used for packing a series of
//               numeric and string data into a binary stream,
//               according to the DC specification.
//
//               See also direct/src/doc/dcPacker.txt for a more
//               complete description and examples of using this
//               class.
////////////////////////////////////////////////////////////////////
class EXPCL_DIRECT DCPacker {
PUBLISHED:
  DCPacker();
  ~DCPacker();

  INLINE void clear_data();

  void begin_pack(const DCPackerInterface *root);
  bool end_pack();

  void set_unpack_data(const string &data);
public:
  void set_unpack_data(const char *unpack_data, size_t unpack_length, 
                       bool owns_unpack_data);

PUBLISHED:
  void begin_unpack(const DCPackerInterface *root);
  bool end_unpack();

  void begin_repack(const DCPackerInterface *root);
  bool end_repack();

  bool seek(const string &field_name);
  bool seek(int seek_index);

  INLINE bool has_nested_fields() const;
  INLINE int get_num_nested_fields() const;
  INLINE bool more_nested_fields() const;

  INLINE const DCPackerInterface *get_current_parent() const;
  INLINE const DCPackerInterface *get_current_field() const;
  INLINE const DCSwitchParameter *get_last_switch() const;
  INLINE DCPackType get_pack_type() const;

  void push();
  void pop();

  INLINE void pack_double(double value);
  INLINE void pack_int(int value);
  INLINE void pack_uint(unsigned int value);
  INLINE void pack_int64(PN_int64 value);
  INLINE void pack_uint64(PN_uint64 value);
  INLINE void pack_string(const string &value);
  INLINE void pack_literal_value(const string &value);
  void pack_default_value();

  INLINE double unpack_double();
  INLINE int unpack_int();
  INLINE unsigned int unpack_uint();
  INLINE PN_int64 unpack_int64();
  INLINE PN_uint64 unpack_uint64();
  INLINE string unpack_string();
  INLINE string unpack_literal_value();
  void unpack_validate();
  void unpack_skip();

public:
  // The following are variants on the above unpack() calls that pass
  // the result back by reference instead of as a return value.
  INLINE void unpack_double(double &value);
  INLINE void unpack_int(int &value);
  INLINE void unpack_uint(unsigned int &value);
  INLINE void unpack_int64(PN_int64 &value);
  INLINE void unpack_uint64(PN_uint64 &value);
  INLINE void unpack_string(string &value);
  INLINE void unpack_literal_value(string &value);

PUBLISHED:

#ifdef HAVE_PYTHON
  void pack_object(PyObject *object);
  PyObject *unpack_object();
#endif

  bool parse_and_pack(const string &formatted_object);
  bool parse_and_pack(istream &in);
  string unpack_and_format();
  void unpack_and_format(ostream &out);

  INLINE bool had_pack_error() const;
  INLINE bool had_range_error() const;
  INLINE bool had_error() const;
  INLINE size_t get_num_unpacked_bytes() const;

  INLINE size_t get_length() const;
  INLINE string get_string() const;
public:
  INLINE void get_string(string &data) const;
  INLINE const char *get_data() const;
  INLINE char *take_data();

  INLINE void append_data(const char *buffer, size_t size);
  INLINE char *get_write_pointer(size_t size);

PUBLISHED:
  INLINE static int get_num_stack_elements_ever_allocated();

  // The following methods are used only for packing (or unpacking)
  // raw data into the buffer between packing sessions (e.g. between
  // calls to end_pack() and the next begin_pack()).

  INLINE void raw_pack_int8(int value);
  INLINE void raw_pack_int16(int value);
  INLINE void raw_pack_int32(int value);
  INLINE void raw_pack_int64(PN_int64 value);
  INLINE void raw_pack_uint8(unsigned int value);
  INLINE void raw_pack_uint16(unsigned int value);
  INLINE void raw_pack_uint32(unsigned int value);
  INLINE void raw_pack_uint64(PN_uint64 value);
  INLINE void raw_pack_float64(double value);
  INLINE void raw_pack_string(const string &value);

// this is a hack to allw me to get in and out of 32bit Mode Faster
// need to agree with channel_type in dcbase.h
#define RAW_PACK_CHANNEL(in)  raw_pack_uint64(in)
  

  INLINE int raw_unpack_int8();
  INLINE int raw_unpack_int16();
  INLINE int raw_unpack_int32();
  INLINE PN_int64 raw_unpack_int64();
  INLINE unsigned int raw_unpack_uint8();
  INLINE unsigned int raw_unpack_uint16();
{'fraction_non_alphanumeric': 0.13210922787193974, 'fraction_numerical': 0.014500941619585688, 'mean_word_length': 3.3262729124236254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4601062', 'n_tokens_mistral': 3427, 'n_tokens_neox': 3108, 'n_words': 1041}