bool cResponsePacket::copyin(const uint8_t* src, uint32_t len) { if (!checkExtend(len)) return false; memcpy(buffer + bufUsed, src, len); bufUsed += len; return true; }
bool cResponsePacket::add_U8(uint8_t c) { if (!checkExtend(sizeof(uint8_t))) return false; buffer[bufUsed] = c; bufUsed += sizeof(uint8_t); return true; }
bool cResponsePacket::add_U64(uint64_t ull) { if (!checkExtend(sizeof(uint64_t))) return false; *(uint64_t*)&buffer[bufUsed] = htonll(ull); bufUsed += sizeof(uint64_t); return true; }
bool cResponsePacket::add_S32(int32_t l) { if (!checkExtend(sizeof(int32_t))) return false; *(int32_t*)&buffer[bufUsed] = htonl(l); bufUsed += sizeof(int32_t); return true; }
bool cResponsePacket::add_U64(uint64_t ull) { if (!checkExtend(sizeof(uint64_t))) return false; uint64_t tmp = __cpu_to_be64(ull); memcpy(&buffer[bufUsed], &tmp, sizeof(uint64_t)); bufUsed += sizeof(uint64_t); return true; }
bool cResponsePacket::add_S32(int32_t l) { if (!checkExtend(sizeof(int32_t))) return false; int32_t tmp = htonl(l); memcpy(&buffer[bufUsed], &tmp, sizeof(int32_t)); bufUsed += sizeof(int32_t); return true; }
bool cResponsePacket::add_String(const char* string) { uint32_t len = strlen(string) + 1; if (!checkExtend(len)) return false; memcpy(buffer + bufUsed, string, len); bufUsed += len; return true; }
bool cRequestPacket::copyin(const uint8_t* src, uint32_t len) { if (!checkExtend(len)) return false; memcpy(buffer + bufUsed, src, len); bufUsed += len; if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength); return true; }
bool cRequestPacket::add_U64(uint64_t ull) { if (!checkExtend(sizeof(uint64_t))) return false; *(uint64_t*)&buffer[bufUsed] = htonll(ull); bufUsed += sizeof(uint64_t); if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength); return true; }
bool cResponsePacket::add_double(double d) { if (!checkExtend(sizeof(double))) return false; uint64_t ull; memcpy(&ull,&d,sizeof(double)); *(uint64_t*)&buffer[bufUsed] = htonll(ull); bufUsed += sizeof(uint64_t); return true; }
bool cRequestPacket::add_String(const char* string) { uint32_t len = strlen(string) + 1; if (!checkExtend(len)) return false; memcpy(buffer + bufUsed, string, len); bufUsed += len; if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength); return true; }
bool cResponsePacket::add_double(double d) { if (!checkExtend(sizeof(double))) return false; uint64_t ull; memcpy(&ull, &d, sizeof(double)); ull = __cpu_to_be64(ull); memcpy(&buffer[bufUsed], &ull, sizeof(uint64_t)); bufUsed += sizeof(uint64_t); return true; }
bool cRequestPacket::add_U8(uint8_t c) { if (!checkExtend(sizeof(uint8_t))) return false; buffer[bufUsed] = c; bufUsed += sizeof(uint8_t); if (!lengthSet) { uint32_t tmp = htonl(bufUsed - headerLength); memcpy(&buffer[userDataLenPos], &tmp, sizeof(uint32_t)); } return true; }
uint8_t* cResponsePacket::reserve(uint32_t len) { if (!checkExtend(len)) return false; uint8_t* result = buffer + bufUsed; bufUsed += len; return result; }