#ifndef TAGS_H
#define TAGS_H
#include <cstdio>
#include <stdint.h>
#include "externs.h"
enum tag_type {
TAG_NO_TAG = 0, TAG_YOU = 1, TAG_YOU_ITEMS, TAG_YOU_DUNGEON, TAG_LEVEL, TAG_LEVEL_ITEMS, TAG_LEVEL_MONSTERS, TAG_GHOST, TAG_LEVEL_ATTITUDE, TAG_LOST_MONSTERS, TAG_LEVEL_TILES,
NUM_TAGS
};
enum tag_file_type {
TAGTYPE_PLAYER = 0, TAGTYPE_LEVEL, TAGTYPE_GHOST,
TAGTYPE_PLAYER_NAME };
enum tag_major_version
{
TAG_MAJOR_START = 5,
TAG_MAJOR_VERSION = 6
};
enum tag_minor_version
{
TAG_MINOR_ARTEFACT = 0, TAG_MINOR_JIYVA = 1, TAG_MINOR_ZOT_OPEN = 2, TAG_MINOR_JELLY = 3, TAG_ANNOTATE_EXCL = 4, TAG_MINOR_UGLY = 5, TAG_MINOR_ROTTING = 6, TAG_MINOR_TRANS = 7, TAG_MINOR_GITREV = 8, TAG_MINOR_DSTRAITS = 9, TAG_MINOR_YOU_PROP = 10, TAG_MINOR_VERSION = 10 };
class writer
{
public:
writer(FILE* output)
: _file(output), _pbuf(0) {}
writer(std::vector<unsigned char>* poutput)
: _file(0), _pbuf(poutput) {}
void writeByte(unsigned char byte);
void write(const void *data, size_t size);
long tell();
private:
FILE* _file;
std::vector<unsigned char>* _pbuf;
};
void marshallByte (writer &, const char& );
void marshallShort (writer &, int16_t );
void marshallLong (writer &, int32_t );
void marshallFloat (writer &, float );
void marshallBoolean (writer &, bool );
void marshallString (writer &, const std::string &, int maxSize = 0);
void marshallString4 (writer &, const std::string &);
void marshallCoord (writer &, const coord_def &);
void marshallItem (writer &, const item_def &);
class reader
{
public:
reader(FILE* input)
: _file(input), _pbuf(0), _read_offset(0) {}
reader(const std::vector<unsigned char>& input)
: _file(0), _pbuf(&input), _read_offset(0) {}
unsigned char readByte();
void read(void *data, size_t size);
private:
FILE* _file;
const std::vector<unsigned char>* _pbuf;
unsigned int _read_offset;
};
char unmarshallByte (reader &);
int16_t unmarshallShort (reader &);
int32_t unmarshallLong (reader &);
float unmarshallFloat (reader &);
bool unmarshallBoolean (reader &);
int unmarshallCString (reader &, char *data, int maxSize);
std::string unmarshallString (reader &, int maxSize = 1000);
void unmarshallString4 (reader &, std::string&);
void unmarshallCoord (reader &, coord_def &c);
void unmarshallItem (reader &, item_def &item);
tag_type tag_read(FILE* inf, char minorVersion);
void tag_write(tag_type tagID, FILE* outf);
void tag_set_expected(char tags[], int fileType);
void tag_missing(int tag, char minorVersion);
int write2(FILE * file, const void *buffer, unsigned int count);
int read2(FILE * file, void *buffer, unsigned int count);
std::string make_date_string( time_t in_date );
time_t parse_date_string( char[20] );
#endif