amxmodx/dlls/nvault/Binary.cpp

161 lines
2.6 KiB
C++
Raw Normal View History

// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// NVault Module
//
2005-07-31 10:07:48 +04:00
#include "Binary.h"
2005-08-01 23:56:54 +04:00
#include "amxxmodule.h"
2005-07-31 10:07:48 +04:00
BinaryWriter::BinaryWriter(FILE *fp)
{
m_Fp = fp;
}
bool BinaryWriter::WriteAddr(void *buffer, size_t size)
{
if (fwrite(buffer, size, 1, m_Fp) != 1)
return false;
return true;
}
bool BinaryWriter::WriteUInt32(uint32_t num)
2005-07-31 10:07:48 +04:00
{
if ( !WriteAddr(&num, sizeof(uint32_t)) )
return false;
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryWriter::WriteInt32(int32_t num)
2005-07-31 10:07:48 +04:00
{
if ( !WriteAddr(&num, sizeof(int32_t)) )
return false;
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryWriter::WriteUInt16(uint16_t num)
2005-07-31 10:07:48 +04:00
{
if ( !WriteAddr(&num, sizeof(uint16_t)) )
return false;
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryWriter::WriteInt16(int16_t num)
2005-07-31 10:07:48 +04:00
{
if ( !WriteAddr(&num, sizeof(int16_t)) )
return false;
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryWriter::WriteUInt8(uint8_t num)
2005-07-31 10:07:48 +04:00
{
if ( !WriteAddr(&num, sizeof(uint8_t)) )
return false;
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryWriter::WriteInt8(int8_t num)
2005-07-31 10:07:48 +04:00
{
if ( !WriteAddr(&num, sizeof(int8_t)) )
return false;
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryWriter::WriteChars(const char buffer[], size_t chars)
2005-07-31 10:07:48 +04:00
{
if (!chars)
return true;
2005-07-31 10:07:48 +04:00
if (fwrite(buffer, sizeof(char), chars, m_Fp) != chars)
return false;
return true;
2005-07-31 10:07:48 +04:00
}
2005-07-31 10:07:48 +04:00
BinaryReader::BinaryReader(FILE *fp)
{
m_Fp = fp;
}
bool BinaryReader::ReadAddr(void *buffer, size_t size)
{
if (fread(buffer, size, 1, m_Fp) != 1)
return false;
return true;
}
bool BinaryReader::ReadUInt32(uint32_t& num)
2005-07-31 10:07:48 +04:00
{
if ( !ReadAddr(&num, sizeof(uint32_t)) )
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryReader::ReadInt32(int32_t& num)
2005-07-31 10:07:48 +04:00
{
if ( !ReadAddr(&num, sizeof(int32_t)) )
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryReader::ReadUInt16(uint16_t& num)
2005-07-31 10:07:48 +04:00
{
if ( !ReadAddr(&num, sizeof(uint16_t)) )
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryReader::ReadInt16(int16_t& num)
2005-07-31 10:07:48 +04:00
{
if ( !ReadAddr(&num, sizeof(int16_t)) )
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryReader::ReadUInt8(uint8_t& num)
2005-07-31 10:07:48 +04:00
{
if ( !ReadAddr(&num, sizeof(uint8_t)) )
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryReader::ReadInt8(int8_t& num)
2005-07-31 10:07:48 +04:00
{
if ( !ReadAddr(&num, sizeof(int8_t)) )
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}
bool BinaryReader::ReadChars(char buffer[], size_t chars)
2005-07-31 10:07:48 +04:00
{
if (!chars)
return true;
2005-07-31 10:07:48 +04:00
if (fread(buffer, sizeof(char), chars, m_Fp) != chars)
return false;
2005-07-31 10:07:48 +04:00
return true;
2005-07-31 10:07:48 +04:00
}