You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2012/03/13 04:25:36 UTC
svn commit: r1299961 - in /qpid/proton/proton-c: Makefile
include/proton/message.h src/dispatcher/dispatcher.c src/message/
src/message/message.c src/proton.c
Author: rhs
Date: Tue Mar 13 03:25:36 2012
New Revision: 1299961
URL: http://svn.apache.org/viewvc?rev=1299961&view=rev
Log:
added simple message encoding
Added:
qpid/proton/proton-c/include/proton/message.h
qpid/proton/proton-c/src/message/ (with props)
qpid/proton/proton-c/src/message/message.c
Modified:
qpid/proton/proton-c/Makefile
qpid/proton/proton-c/src/dispatcher/dispatcher.c
qpid/proton/proton-c/src/proton.c
Modified: qpid/proton/proton-c/Makefile
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/Makefile?rev=1299961&r1=1299960&r2=1299961&view=diff
==============================================================================
--- qpid/proton/proton-c/Makefile (original)
+++ qpid/proton/proton-c/Makefile Tue Mar 13 03:25:36 2012
@@ -12,10 +12,11 @@ VALUE_HDR := include/proton/value.h
DISPATCHER_SRC := src/dispatcher/dispatcher.c
ENGINE_SRC := src/engine/engine.c
SASL_SRC := src/sasl/sasl.c
+MESSAGE_SRC := src/message/message.c
DRIVER_SRC := src/driver.c
SRCS := ${UTIL_SRC} ${VALUE_SRC} ${FRAMING_SRC} ${CODEC_SRC} ${PROTOCOL_SRC} \
- ${DISPATCHER_SRC} ${ENGINE_SRC} ${SASL_SRC} ${DRIVER_SRC}
+ ${DISPATCHER_SRC} ${ENGINE_SRC} ${SASL_SRC} ${MESSAGE_SRC} ${DRIVER_SRC}
OBJS := ${SRCS:.c=.o}
DEPS := ${OBJS:.o=.d}
HDRS := ${UTIL_HDR} ${VALUE_HDR} \
@@ -24,6 +25,7 @@ HDRS := ${UTIL_HDR} ${VALUE_HDR} \
src/protocol.h \
include/proton/engine.h \
include/proton/sasl.h \
+ include/proton/message.h \
src/codec/encodings.h
PROGRAMS := src/proton
Added: qpid/proton/proton-c/include/proton/message.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/message.h?rev=1299961&view=auto
==============================================================================
--- qpid/proton/proton-c/include/proton/message.h (added)
+++ qpid/proton/proton-c/include/proton/message.h Tue Mar 13 03:25:36 2012
@@ -0,0 +1,29 @@
+#ifndef _PROTON_MESSAGE_H
+#define _PROTON_MESSAGE_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <sys/types.h>
+
+ssize_t pn_message_data(char *dst, size_t available, char *src, size_t size);
+
+#endif /* message.h */
Modified: qpid/proton/proton-c/src/dispatcher/dispatcher.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/dispatcher/dispatcher.c?rev=1299961&r1=1299960&r2=1299961&view=diff
==============================================================================
--- qpid/proton/proton-c/src/dispatcher/dispatcher.c (original)
+++ qpid/proton/proton-c/src/dispatcher/dispatcher.c Tue Mar 13 03:25:36 2012
@@ -74,7 +74,7 @@ static void pn_trace(pn_dispatcher_t *di
if (size) {
fprintf(stderr, " (%zu) \"", size);
for (int i = 0; i < size; i++) {
- char c = payload[i];
+ uint8_t c = payload[i];
if (isprint(c)) {
fputc(c, stderr);
} else {
Propchange: qpid/proton/proton-c/src/message/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Mar 13 03:25:36 2012
@@ -0,0 +1 @@
+*.d
Added: qpid/proton/proton-c/src/message/message.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/message/message.c?rev=1299961&view=auto
==============================================================================
--- qpid/proton/proton-c/src/message/message.c (added)
+++ qpid/proton/proton-c/src/message/message.c Tue Mar 13 03:25:36 2012
@@ -0,0 +1,35 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <proton/message.h>
+#include <proton/codec.h>
+#include "../protocol.h"
+
+ssize_t pn_message_data(char *dst, size_t available, char *src, size_t size)
+{
+ char *pos = dst;
+ char *limit = pos + available;
+ int e;
+ if ((e = pn_write_descriptor(&pos, limit))) return e;
+ if ((e = pn_write_ulong(&pos, limit, 0x75))) return e;
+ if ((e = pn_write_binary(&pos, limit, size, src))) return e;
+ return pos - dst;
+}
Modified: qpid/proton/proton-c/src/proton.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/proton.c?rev=1299961&r1=1299960&r2=1299961&view=diff
==============================================================================
--- qpid/proton/proton-c/src/proton.c (original)
+++ qpid/proton/proton-c/src/proton.c Tue Mar 13 03:25:36 2012
@@ -21,9 +21,11 @@
#define _GNU_SOURCE
+#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <proton/driver.h>
+#include <proton/message.h>
#include <proton/value.h>
void print(pn_value_t value)
@@ -72,6 +74,18 @@ int value(int argc, char **argv)
return 0;
}
+void print_data(char *bytes, size_t size)
+{
+ for (int i = 0; i < size; i++)
+ {
+ uint8_t c = bytes[i];
+ if (isprint(c))
+ printf("%c", c);
+ else
+ printf("\\x%.2x", c);
+ }
+}
+
struct server_context {
int count;
};
@@ -109,6 +123,7 @@ void server_callback(pn_selectable_t *se
struct server_context *ctx = pn_selectable_context(sel);
char tagstr[1024];
char msg[1024];
+ char data[1024];
pn_endpoint_t *endpoint = pn_endpoint_head(conn, UNINIT, ACTIVE);
while (endpoint)
@@ -163,14 +178,15 @@ void server_callback(pn_selectable_t *se
pn_disposition(delivery, PN_ACCEPTED);
break;
} else {
- printf("%.*s", (int) n, msg);
+ print_data(msg, n);
}
}
printf("\"\n");
} else if (pn_writable(delivery)) {
pn_sender_t *sender = (pn_sender_t *) link;
sprintf(msg, "message body for %s", tagstr);
- pn_send(sender, msg, strlen(msg));
+ size_t n = pn_message_data(data, 1024, msg, strlen(msg));
+ pn_send(sender, data, n);
if (pn_advance(link)) {
printf("sent delivery: %s\n", tagstr);
char tagbuf[16];
@@ -242,6 +258,7 @@ void client_callback(pn_selectable_t *se
pn_connection_t *connection = pn_selectable_connection(sel);
char tagstr[1024];
char msg[1024];
+ char data[1024];
if (!ctx->init) {
ctx->init = true;
@@ -281,7 +298,8 @@ void client_callback(pn_selectable_t *se
if (pn_writable(delivery)) {
pn_sender_t *snd = (pn_sender_t *) link;
sprintf(msg, "message body for %s", tagstr);
- pn_send(snd, msg, strlen(msg));
+ ssize_t n = pn_message_data(data, 1024, msg, strlen(msg));
+ pn_send(snd, data, n);
if (pn_advance(link)) printf("sent delivery: %s\n", tagstr);
} else if (pn_readable(delivery)) {
printf("received delivery: %s\n", tagstr);
@@ -298,7 +316,7 @@ void client_callback(pn_selectable_t *se
}
break;
} else {
- printf("%.*s", (int) n, msg);
+ print_data(msg, n);
}
}
printf("\"\n");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org