| 838 | } |
| 839 | |
| 840 | int pn_message_encode(pn_message_t *msg, char *bytes, size_t *isize) |
| 841 | { |
| 842 | pn_rwbytes_t scratch = (pn_rwbytes_t){.size=*isize, .start=bytes}; |
| 843 | if (!pni_switch_to_raw_bytes(scratch, &msg->instructions_deprecated, &msg->instructions_raw)) { |
| 844 | return PN_OVERFLOW; |
| 845 | } |
| 846 | if (!pni_switch_to_raw_bytes(scratch, &msg->annotations_deprecated, &msg->annotations_raw)) { |
| 847 | return PN_OVERFLOW; |
| 848 | } |
| 849 | if (!pni_switch_to_raw_bytes(scratch, &msg->properties_deprecated, &msg->properties_raw)) { |
| 850 | return PN_OVERFLOW; |
| 851 | } |
| 852 | if (!pni_switch_to_raw_bytes(scratch, &msg->body_deprecated, &msg->body_raw)) { |
| 853 | return PN_OVERFLOW; |
| 854 | } |
| 855 | size_t remaining = *isize; |
| 856 | size_t total = 0; |
| 857 | |
| 858 | /* "DL[?o?B?I?o?I]" */ |
| 859 | size_t last_size = pn_amqp_encode_bytes_DLEQoQBQIQoQIe(bytes, remaining, HEADER, |
| 860 | msg->durable, msg->durable, |
| 861 | msg->priority!=HEADER_PRIORITY_DEFAULT, msg->priority, |
| 862 | (bool)msg->ttl, msg->ttl, |
| 863 | msg->first_acquirer, msg->first_acquirer, |
| 864 | (bool)msg->delivery_count, msg->delivery_count); |
| 865 | if (last_size > remaining) return PN_OVERFLOW; |
| 866 | |
| 867 | remaining -= last_size; |
| 868 | bytes += last_size; |
| 869 | total += last_size; |
| 870 | |
| 871 | |
| 872 | if (msg->instructions_raw.size>0) { |
| 873 | last_size = pn_amqp_encode_bytes_DLR(bytes, remaining, DELIVERY_ANNOTATIONS, msg->instructions_raw); |
| 874 | if (last_size > remaining) return PN_OVERFLOW; |
| 875 | |
| 876 | remaining -= last_size; |
| 877 | bytes += last_size; |
| 878 | total += last_size; |
| 879 | } |
| 880 | |
| 881 | if (msg->annotations_raw.size>0) { |
| 882 | last_size = pn_amqp_encode_bytes_DLR(bytes, remaining, MESSAGE_ANNOTATIONS, msg->annotations_raw); |
| 883 | if (last_size > remaining) return PN_OVERFLOW; |
| 884 | |
| 885 | remaining -= last_size; |
| 886 | bytes += last_size; |
| 887 | total += last_size; |
| 888 | } |
| 889 | |
| 890 | /* "DL[CzSSSCss?t?tS?IS]" */ |
| 891 | pn_atom_t id = pn_message_get_id(msg); |
| 892 | pn_atom_t correlation_id = pn_message_get_correlation_id(msg); |
| 893 | last_size = pn_amqp_encode_bytes_DLEazSSSassQtQtSQISe(bytes, remaining, PROPERTIES, |
| 894 | &id, |
| 895 | pn_string_size(msg->user_id), pn_string_get(msg->user_id), |
| 896 | pn_string_bytes(msg->address), |
| 897 | pn_string_bytes(msg->subject), |
no test coverage detected