void DataReader::readList(pn_data_t* data, const qpid::amqp::Descriptor* descriptor) { size_t count = pn_data_get_list(data); reader.onStartList(count, qpid::amqp::CharSequence(), descriptor); pn_data_enter(data); for (size_t i = 0; i < count && pn_data_next(data); ++i) { read(data); } pn_data_exit(data); reader.onEndList(count, descriptor); }
mama_status qpidBridgeMsgCodec_unpack (msgBridge bridgeMessage, mamaMsg target, pn_message_t* protonMessage) { pn_data_t* properties = NULL; pn_data_t* body = NULL; mama_status status = MAMA_STATUS_OK; qpidMsgType type = QPID_MSG_PUB_SUB; pn_bytes_t prop; pn_atom_t firstAtom; if (NULL == bridgeMessage || NULL == protonMessage) { return MAMA_STATUS_NULL_ARG; } /* grab the body */ body = pn_message_body (protonMessage); /* Ensure position is at the start */ pn_data_rewind (body); /* Skip over the initial null atom */ pn_data_next (body); /* Grab the first atom and see what it is - PN_LIST = qpid */ firstAtom = pn_data_get_atom (body); /* If this is a proton message */ if (PN_LIST == firstAtom.type) { status = mamaMsgImpl_setMsgBuffer (target, (void*) protonMessage, sizeof (pn_message_t*), MAMA_PAYLOAD_QPID); } /* If this looks like another MAMA payload type */ else if (PN_BINARY == firstAtom.type) { mamaPayloadType payloadType = MAMA_PAYLOAD_UNKNOWN; if (firstAtom.u.as_bytes.size == 0) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaMsgImpl_unpack(): " "Binary blob of zero length found - not processing"); return MAMA_STATUS_INVALID_ARG; } /* The payload type is the first character */ payloadType = (mamaPayloadType) firstAtom.u.as_bytes.start[0]; /* Use byte buffer to populate MAMA message */ status = mamaMsgImpl_setMsgBuffer ( target, (void*) firstAtom.u.as_bytes.start, (mama_size_t) firstAtom.u.as_bytes.size, payloadType); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaMsgImpl_unpack(): " "Could not set msg buffer. Cannot unpack (%s).", mamaStatus_stringForStatus (status)); return status; } } /* If this looks like something we cannot handle */ else { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaMsgImpl_unpack(): " "Unable to unpack data received: incompatible format %s", pn_type_name (firstAtom.type)); } /* Get the properties */ properties = pn_message_properties (protonMessage); /* Ensure position is at the start */ pn_data_rewind (properties); /* Skip over the initial null atom */ pn_data_next (properties); /* Main container should be a list to allow expansion */ pn_data_get_list (properties); pn_data_enter (properties); /* Get the message type out */ pn_data_next (properties); type = (qpidMsgType) pn_data_get_ubyte (properties); qpidBridgeMamaMsgImpl_setMsgType (bridgeMessage, type); switch (type) { case QPID_MSG_INBOX_REQUEST: /* Move onto inbox name and extract / copy */ pn_data_next (properties); prop = pn_data_get_string (properties); status = qpidBridgeMamaMsgImpl_setInboxName (bridgeMessage, prop.start); if (MAMA_STATUS_OK != status) { return status; } /* Move onto reply to url and extract / copy */ pn_data_next (properties); prop = pn_data_get_string (properties); status = qpidBridgeMamaMsgImpl_setReplyTo (bridgeMessage, prop.start); if (MAMA_STATUS_OK != status) { return status; } break; case QPID_MSG_INBOX_RESPONSE: /* Move onto target subject and extract / copy */ pn_data_next (properties); prop = pn_data_get_string (properties); status = qpidBridgeMamaMsgImpl_setTargetSubject (bridgeMessage, prop.start); if (MAMA_STATUS_OK != status) { return status; } break; /* The following message types require no further meta data */ case QPID_MSG_TERMINATE: case QPID_MSG_SUB_REQUEST: case QPID_MSG_PUB_SUB: default: break; } pn_data_exit (properties); return status; }