partially fix big-endian build
samples are the next thing to tackle
This commit is contained in:
parent
7c42453422
commit
142c21e20b
4 changed files with 160 additions and 11 deletions
|
|
@ -77,9 +77,64 @@ int SafeWriter::writeC(signed char val) {
|
|||
return write(&val,1);
|
||||
}
|
||||
|
||||
#ifdef TA_BIG_ENDIAN
|
||||
int SafeWriter::writeS_BE(short val) {
|
||||
return write(&val,2);
|
||||
}
|
||||
|
||||
int SafeWriter::writeS(short val) {
|
||||
unsigned char bytes[2]{(unsigned char)((val>>8)&0xff), (unsigned char)(val&0xff)};
|
||||
return write(bytes,2);
|
||||
}
|
||||
|
||||
int SafeWriter::writeI(int val) {
|
||||
unsigned char bytes[4];
|
||||
bytes[0]=((unsigned int)val)&0xff;
|
||||
bytes[1]=(((unsigned int)val)>>8)&0xff;
|
||||
bytes[2]=(((unsigned int)val)>>16)&0xff;
|
||||
bytes[3]=(((unsigned int)val)>>24)&0xff;
|
||||
return write(bytes,4);
|
||||
}
|
||||
|
||||
int SafeWriter::writeL(int64_t val) {
|
||||
unsigned char bytes[8];
|
||||
bytes[0]=((uint64_t)val)&0xff;
|
||||
bytes[1]=(((uint64_t)val)>>8)&0xff;
|
||||
bytes[2]=(((uint64_t)val)>>16)&0xff;
|
||||
bytes[3]=(((uint64_t)val)>>24)&0xff;
|
||||
bytes[4]=(((uint64_t)val)>>32)&0xff;
|
||||
bytes[5]=(((uint64_t)val)>>40)&0xff;
|
||||
bytes[6]=(((uint64_t)val)>>48)&0xff;
|
||||
bytes[7]=(((uint64_t)val)>>56)&0xff;
|
||||
return write(bytes,8);
|
||||
}
|
||||
|
||||
int SafeWriter::writeF(float val) {
|
||||
unsigned char bytes[4];
|
||||
bytes[0]=((unsigned char*)(&val))[3];
|
||||
bytes[1]=((unsigned char*)(&val))[2];
|
||||
bytes[2]=((unsigned char*)(&val))[1];
|
||||
bytes[3]=((unsigned char*)(&val))[0];
|
||||
return write(bytes,4);
|
||||
}
|
||||
|
||||
int SafeWriter::writeD(double val) {
|
||||
unsigned char bytes[8];
|
||||
bytes[0]=((unsigned char*)(&val))[7];
|
||||
bytes[1]=((unsigned char*)(&val))[6];
|
||||
bytes[2]=((unsigned char*)(&val))[5];
|
||||
bytes[3]=((unsigned char*)(&val))[4];
|
||||
bytes[4]=((unsigned char*)(&val))[3];
|
||||
bytes[5]=((unsigned char*)(&val))[2];
|
||||
bytes[6]=((unsigned char*)(&val))[1];
|
||||
bytes[7]=((unsigned char*)(&val))[0];
|
||||
return write(bytes,8);
|
||||
}
|
||||
#else
|
||||
int SafeWriter::writeS(short val) {
|
||||
return write(&val,2);
|
||||
}
|
||||
|
||||
int SafeWriter::writeS_BE(short val) {
|
||||
unsigned char bytes[2]{(unsigned char)((val>>8)&0xff), (unsigned char)(val&0xff)};
|
||||
return write(bytes,2);
|
||||
|
|
@ -88,23 +143,20 @@ int SafeWriter::writeS_BE(short val) {
|
|||
int SafeWriter::writeI(int val) {
|
||||
return write(&val,4);
|
||||
}
|
||||
|
||||
int SafeWriter::writeL(int64_t val) {
|
||||
return write(&val,8);
|
||||
}
|
||||
|
||||
int SafeWriter::writeF(float val) {
|
||||
return write(&val,4);
|
||||
}
|
||||
|
||||
int SafeWriter::writeD(double val) {
|
||||
return write(&val,8);
|
||||
}
|
||||
int SafeWriter::writeString(String val, bool pascal) {
|
||||
if (pascal) {
|
||||
writeC((unsigned char)val.size());
|
||||
return write(val.c_str(),val.size())+1;
|
||||
} else {
|
||||
return write(val.c_str(),val.size()+1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int SafeWriter::writeWString(WString val, bool pascal) {
|
||||
if (pascal) {
|
||||
writeS((unsigned short)val.size());
|
||||
|
|
@ -120,10 +172,20 @@ int SafeWriter::writeWString(WString val, bool pascal) {
|
|||
return 2+val.size()*2;
|
||||
}
|
||||
}
|
||||
|
||||
int SafeWriter::writeText(String val) {
|
||||
return write(val.c_str(),val.size());
|
||||
}
|
||||
|
||||
int SafeWriter::writeString(String val, bool pascal) {
|
||||
if (pascal) {
|
||||
writeC((unsigned char)val.size());
|
||||
return write(val.c_str(),val.size())+1;
|
||||
} else {
|
||||
return write(val.c_str(),val.size()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void SafeWriter::init() {
|
||||
if (operative) return;
|
||||
buf=new unsigned char[WRITER_BUF_SIZE];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue