resonance 1.0.1
Loading...
Searching...
No Matches
hxstrtransfer.h
Go to the documentation of this file.
1#pragma once
2
3#include "os/hxstr.h"
4#include "stream/ibstream.h"
5#include "stream/obstream.h"
6
21inline OBStream &SaveHxStr(OBStream &stream, const HxStr &text) {
22 int length = text.mLen;
23 stream.WriteLE(&length, sizeof(length));
24 return stream.Write(text.mStr != nullptr ? text.mStr : g_szEmptyString, length);
25}
26
39inline IBStream &LoadHxStr(IBStream &stream, HxStr &text) {
40 int length;
41 stream.ReadLE(&length, sizeof(length));
42 text.Alloc(length);
43 return stream.Read(text.mStr != nullptr ? text.mStr : const_cast<char *>(g_szEmptyString),
44 length);
45}
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
unsigned mLen
Length excluding the terminator.
Definition hxstr.h:453
void Alloc(unsigned nLen)
Discard the text and reserve a zero-filled buffer.
char * mStr
Text buffer.
Definition hxstr.h:464
Input half of the byte stream interface.
Definition ibstream.h:36
virtual IBStream & Read(void *pDest, int nSize)=0
Move nSize bytes into pDest.
virtual IBStream & ReadLE(void *pDest, int nSize)
Move nSize bytes into pDest through the virtual Read().
Output half of the byte stream interface.
Definition obstream.h:25
virtual OBStream & Write(const void *pSrc, int nSize)=0
Move nSize bytes out of pSrc.
virtual OBStream & WriteLE(const void *pSrc, int nSize)
Move nSize bytes out of pSrc through the virtual Write().
const char * g_szEmptyString
Text an empty HxStr points at, and the substitute for a null buffer.
OBStream & SaveHxStr(OBStream &stream, const HxStr &text)
Write a string as a four-byte length followed by its text, with no terminator.
Definition hxstrtransfer.h:21
IBStream & LoadHxStr(IBStream &stream, HxStr &text)
Read a string written by SaveHxStr() back in place.
Definition hxstrtransfer.h:39