in shims/qpid-proton-cpp/src/qpidit/jms_hdrs_props_test/Receiver.cpp [204:252]
void Receiver::receiveJmsBytesMessage(const proton::message& msg) {
if(_jmsMessageType.compare("JMS_BYTESMESSAGE_TYPE") != 0) {
throw qpidit::IncorrectMessageBodyTypeError(_jmsMessageType, "JMS_BYTESMESSAGE_TYPE");
}
std::string subType(_subTypeList[_subTypeIndex]);
proton::binary body = proton::get<proton::binary>(msg.body());
if (subType.compare("boolean") == 0) {
if (body.size() != 1) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=boolean", 1, body.size());
_receivedSubTypeList.append(body[0] ? Json::Value("True") : Json::Value("False"));
} else if (subType.compare("byte") == 0) {
if (body.size() != sizeof(int8_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=byte", sizeof(int8_t), body.size());
int8_t val = *((int8_t*)body.data());
_receivedSubTypeList.append(Json::Value(toHexStr<int8_t>(val)));
} else if (subType.compare("bytes") == 0) {
_receivedSubTypeList.append(Json::Value(b64_encode(body)));
} else if (subType.compare("char") == 0) {
if (body.size() != sizeof(uint16_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=char", sizeof(uint16_t), body.size());
// TODO: This is ugly: ignoring first byte - handle UTF-16 correctly
char c = body[1];
std::ostringstream oss;
oss << c;
_receivedSubTypeList.append(Json::Value(b64_encode(proton::binary(oss.str()))));
} else if (subType.compare("double") == 0) {
if (body.size() != sizeof(int64_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=double", sizeof(int64_t), body.size());
int64_t val = be64toh(*((int64_t*)body.data()));
_receivedSubTypeList.append(Json::Value(toHexStr<int64_t>(val, true, false)));
} else if (subType.compare("float") == 0) {
if (body.size() != sizeof(int32_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=float", sizeof(int32_t), body.size());
int32_t val = be32toh(*((int32_t*)body.data()));
_receivedSubTypeList.append(Json::Value(toHexStr<int32_t>(val, true, false)));
} else if (subType.compare("long") == 0) {
if (body.size() != sizeof(int64_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=long", sizeof(int64_t), body.size());
int64_t val = be64toh(*((int64_t*)body.data()));
_receivedSubTypeList.append(Json::Value(toHexStr<int64_t>(val)));
} else if (subType.compare("int") == 0) {
if (body.size() != sizeof(int32_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=int", sizeof(int32_t), body.size());
int32_t val = be32toh(*((int32_t*)body.data()));
_receivedSubTypeList.append(Json::Value(toHexStr<int32_t>(val)));
} else if (subType.compare("short") == 0) {
if (body.size() != sizeof(int16_t)) throw IncorrectMessageBodyLengthError("JmsReceiver::receiveJmsBytesMessage, subType=short", sizeof(int16_t), body.size());
int16_t val = be16toh(*((int16_t*)body.data()));
_receivedSubTypeList.append(Json::Value(toHexStr<int16_t>(val)));
} else if (subType.compare("string") == 0) {
// TODO: decode string size in first two bytes and check string size
_receivedSubTypeList.append(Json::Value(std::string(body).substr(2)));
} else {
throw qpidit::UnknownJmsMessageSubTypeError(subType);
}
}