You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2012/05/16 11:34:45 UTC

svn commit: r1339082 - in /incubator/celix/trunk/hessian: ./ private/ private/src/ private/test/ public/ public/include/

Author: abroekhuis
Date: Wed May 16 09:34:44 2012
New Revision: 1339082

URL: http://svn.apache.org/viewvc?rev=1339082&view=rev
Log:
Added hessian

Added:
    incubator/celix/trunk/hessian/
    incubator/celix/trunk/hessian/CMakeLists.txt
    incubator/celix/trunk/hessian/private/
    incubator/celix/trunk/hessian/private/src/
    incubator/celix/trunk/hessian/private/src/hessian_in.c
    incubator/celix/trunk/hessian/private/src/hessian_out.c
    incubator/celix/trunk/hessian/private/test/
    incubator/celix/trunk/hessian/private/test/test_hessian_out.c
    incubator/celix/trunk/hessian/private/test/test_service.h
    incubator/celix/trunk/hessian/private/test/test_service_proxy.c
    incubator/celix/trunk/hessian/private/test/test_service_skeleton.c
    incubator/celix/trunk/hessian/public/
    incubator/celix/trunk/hessian/public/include/
    incubator/celix/trunk/hessian/public/include/hessian_2.0.h
    incubator/celix/trunk/hessian/public/include/hessian_2.0_in.h
    incubator/celix/trunk/hessian/public/include/hessian_2.0_out.h
    incubator/celix/trunk/hessian/public/include/hessian_constants.h
    incubator/celix/trunk/hessian/test.c

Added: incubator/celix/trunk/hessian/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/CMakeLists.txt?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/CMakeLists.txt (added)
+++ incubator/celix/trunk/hessian/CMakeLists.txt Wed May 16 09:34:44 2012
@@ -0,0 +1,29 @@
+# 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_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("private/include")
+include_directories("public/include")
+
+add_library(hessian STATIC private/src/hessian_out private/src/hessian_in)
+target_link_libraries(hessian utils)
+
+include_directories(${CUNIT_INCLUDE_DIRS})
+add_executable(test_hessian_out private/test/test_hessian_out.c)
+target_link_libraries(test_hessian_out hessian ${CUNIT_LIBRARIES})
+
+run_test(test_hessian_out)

Added: incubator/celix/trunk/hessian/private/src/hessian_in.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/private/src/hessian_in.c?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/private/src/hessian_in.c (added)
+++ incubator/celix/trunk/hessian/private/src/hessian_in.c Wed May 16 09:34:44 2012
@@ -0,0 +1,483 @@
+/*
+ * hessian_in.c
+ *
+ *  Created on: Aug 1, 2011
+ *      Author: alexander
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "hessian_2.0.h"
+
+static int END_OF_DATA = -2;
+
+int hessian_parseChar(hessian_in_t in, char *c);
+int hessian_parseLong(hessian_in_t in, long *value);
+int hessian_parseInt16(hessian_in_t in, int *value);
+int hessian_parseInt(hessian_in_t in, int *value);
+
+char hessian_read(hessian_in_t in) {
+	return (in->buffer[in->offset++] & 0xFF);
+}
+
+int hessian_readBoolean(hessian_in_t in, bool *value) {
+	char tag = hessian_read(in);
+
+	switch (tag) {
+		case 'T':
+			*value = true;
+			break;
+		case 'F':
+		default:
+			*value = false;
+			break;
+	}
+
+	return 0;
+}
+
+int hessian_readInt(hessian_in_t in, int *value) {
+	unsigned char tag = hessian_read(in);
+
+	switch (tag) {
+		// direct integer
+		case 0x80: case 0x81: case 0x82: case 0x83:
+		case 0x84: case 0x85: case 0x86: case 0x87:
+		case 0x88: case 0x89: case 0x8a: case 0x8b:
+		case 0x8c: case 0x8d: case 0x8e: case 0x8f:
+
+		case 0x90: case 0x91: case 0x92: case 0x93:
+		case 0x94: case 0x95: case 0x96: case 0x97:
+		case 0x98: case 0x99: case 0x9a: case 0x9b:
+		case 0x9c: case 0x9d: case 0x9e: case 0x9f:
+
+		case 0xa0: case 0xa1: case 0xa2: case 0xa3:
+		case 0xa4: case 0xa5: case 0xa6: case 0xa7:
+		case 0xa8: case 0xa9: case 0xaa: case 0xab:
+		case 0xac: case 0xad: case 0xae: case 0xaf:
+
+		case 0xb0: case 0xb1: case 0xb2: case 0xb3:
+		case 0xb4: case 0xb5: case 0xb6: case 0xb7:
+		case 0xb8: case 0xb9: case 0xba: case 0xbb:
+		case 0xbc: case 0xbd: case 0xbe: case 0xbf:
+			*value = tag - INT_ZERO;
+			break;
+
+		/* byte int */
+		case 0xc0: case 0xc1: case 0xc2: case 0xc3:
+		case 0xc4: case 0xc5: case 0xc6: case 0xc7:
+		case 0xc8: case 0xc9: case 0xca: case 0xcb:
+		case 0xcc: case 0xcd: case 0xce: case 0xcf:
+			*value = ((tag - INT_BYTE_ZERO) << 8) + hessian_read(in);
+			break;
+
+		/* short int */
+		case 0xd0: case 0xd1: case 0xd2: case 0xd3:
+		case 0xd4: case 0xd5: case 0xd6: case 0xd7:
+			*value = ((tag - INT_SHORT_ZERO) << 16) + 256 * hessian_read(in) + hessian_read(in);
+			break;
+
+		case 'I':
+			hessian_readInt(in, value);
+			break;
+
+		default:
+			*value = 0;
+			break;
+	}
+
+	return 1;
+}
+
+int hessian_readLong(hessian_in_t in, long *value) {
+	unsigned char tag = hessian_read(in);
+
+	switch (tag) {
+		// direct long
+		case 0xd8: case 0xd9: case 0xda: case 0xdb:
+		case 0xdc: case 0xdd: case 0xde: case 0xdf:
+
+		case 0xe0: case 0xe1: case 0xe2: case 0xe3:
+		case 0xe4: case 0xe5: case 0xe6: case 0xe7:
+		case 0xe8: case 0xe9: case 0xea: case 0xeb:
+		case 0xec: case 0xed: case 0xee: case 0xef:
+			*value = tag - LONG_ZERO;
+			break;
+
+		/* byte long */
+		case 0xf0: case 0xf1: case 0xf2: case 0xf3:
+		case 0xf4: case 0xf5: case 0xf6: case 0xf7:
+		case 0xf8: case 0xf9: case 0xfa: case 0xfb:
+		case 0xfc: case 0xfd: case 0xfe: case 0xff:
+			*value = ((tag - LONG_BYTE_ZERO) << 8) + hessian_read(in);
+			break;
+
+		/* short long */
+		case 0x38: case 0x39: case 0x3a: case 0x3b:
+		case 0x3c: case 0x3d: case 0x3e: case 0x3f:
+			*value = ((tag - LONG_SHORT_ZERO) << 16) + 256
+					* hessian_read(in) + hessian_read(in);
+			break;
+
+		case 'L':
+			hessian_parseLong(in, value);
+			break;
+		default:
+			return 0l;
+	}
+
+	return 0;
+}
+
+int hessian_readDouble(hessian_in_t in, double *value) {
+	unsigned char tag = hessian_read(in);
+
+	long l;
+	int i;
+	double *d;
+	switch (tag) {
+		case 0x67:
+			*value = 0;
+			break;
+	    case 0x68:
+	    	*value = 1;
+	    	break;
+	    case 0x69:
+	    	*value = (double) hessian_read(in);
+	    	break;
+	    case 0x6a:
+	    	*value = (short) (256 * hessian_read(in) + hessian_read(in));
+	    	break;
+	    case 0x6b:
+	    	hessian_parseInt(in, &i);
+
+	    	*value = (double) *((float *) &i);
+	    	break;
+	    case 'D':
+	    	hessian_parseLong(in, &l);
+
+	    	d = (double *) &l;
+
+	    	*value = *d;
+	    	break;
+	}
+
+	return 0;
+}
+
+int hessian_readUTCDate(hessian_in_t in, long *value) {
+	unsigned char tag = hessian_read(in);
+
+	if (tag == 'd') {
+		hessian_parseLong(in, value);
+	}
+
+	return 0;
+}
+
+int hessian_readNull(hessian_in_t in) {
+	unsigned char tag = hessian_read(in);
+
+	switch (tag) {
+		case 'N':
+			break;
+		default:
+			break;
+	}
+
+	return 0;
+}
+
+int hessian_readChar(hessian_in_t in, char *value) {
+	char *readC;
+	unsigned int read;
+	hessian_readNString(in, 0, 1, &readC, &read);
+	*value = readC[0];
+
+	return 0;
+}
+
+int hessian_readString(hessian_in_t in, char **value, unsigned int *readLength) {
+	return hessian_readNString(in, 0, -1, value, readLength);
+}
+
+int hessian_readNString(hessian_in_t in, int offset, int length, char **value, unsigned int *readLength) {
+	*readLength = 0;
+
+	bool done = false;
+	if (in->chunkLength == END_OF_DATA) {
+		done = true;
+	} else if (in->chunkLength == 0) {
+		unsigned char tag = hessian_read(in);
+
+		switch (tag) {
+			case 'N':
+				in->chunkLength = 0;
+				in->lastChunk = true;
+				break;
+			case 'S':
+			case 's':
+				in->lastChunk = tag == 'S';
+				hessian_parseInt16(in, &(in->chunkLength));
+				break;
+
+			case 0x00: case 0x01: case 0x02: case 0x03:
+			case 0x04: case 0x05: case 0x06: case 0x07:
+			case 0x08: case 0x09: case 0x0a: case 0x0b:
+			case 0x0c: case 0x0d: case 0x0e: case 0x0f:
+
+			case 0x10: case 0x11: case 0x12: case 0x13:
+			case 0x14: case 0x15: case 0x16: case 0x17:
+			case 0x18: case 0x19: case 0x1a: case 0x1b:
+			case 0x1c: case 0x1d: case 0x1e: case 0x1f:
+				in->chunkLength = tag - 0x00;
+				in->lastChunk = true;
+				break;
+
+			case 0x30: case 0x31: case 0x32: case 0x33:
+				in->chunkLength = (tag - 0x30) * 256 + hessian_read(in);
+				in->lastChunk = true;
+				break;
+
+			default:
+				in->chunkLength = 0;
+				in->lastChunk = true;
+				break;
+		}
+	}
+
+	while (!done) {
+		unsigned int newSize = *readLength + in->chunkLength + 1;
+		*value = realloc(*value, sizeof(char) * (*readLength + in->chunkLength + 1));
+
+		if (in->chunkLength > 0) {
+			char c;
+			hessian_parseChar(in, &c);
+			(*value)[(*readLength) + offset] = c;
+			(*value)[(*readLength) + offset + 1] = '\0';
+			in->chunkLength--;
+			(*readLength)++;
+			length--;
+
+			if (length == 0) {
+				done = true;
+			}
+
+		} else if (in->lastChunk) {
+			done = true;
+			if (*readLength != 0) {
+				in->chunkLength = END_OF_DATA;
+			}
+		} else {
+			unsigned char tag = hessian_read(in);
+			switch (tag) {
+				case 'S':
+				case 's':
+					done = tag == 'S';
+
+					hessian_parseInt16(in, &in->chunkLength);
+					break;
+
+				case 0x00: case 0x01: case 0x02: case 0x03:
+				case 0x04: case 0x05: case 0x06: case 0x07:
+				case 0x08: case 0x09: case 0x0a: case 0x0b:
+				case 0x0c: case 0x0d: case 0x0e: case 0x0f:
+
+				case 0x10: case 0x11: case 0x12: case 0x13:
+				case 0x14: case 0x15: case 0x16: case 0x17:
+				case 0x18: case 0x19: case 0x1a: case 0x1b:
+				case 0x1c: case 0x1d: case 0x1e: case 0x1f:
+					in->chunkLength = tag - 0x00;
+					in->lastChunk = true;
+					break;
+
+				case 0x30: case 0x31: case 0x32: case 0x33:
+					in->chunkLength = (tag - 0x30) * 256 + hessian_read(in);
+					in->lastChunk = true;
+					break;
+
+				default:
+					in->chunkLength = 0;
+					in->lastChunk = true;
+				break;
+			}
+		}
+	}
+
+	if (in->lastChunk && in->chunkLength == 0) {
+		in->chunkLength = END_OF_DATA;
+	}
+
+	return 0;
+}
+
+int hessian_readByte(hessian_in_t in, unsigned char *value) {
+	unsigned char *readC;
+	unsigned int read;
+	hessian_readNBytes(in, 0, 1, &readC, &read);
+	*value = readC[0];
+
+	return 0;
+}
+
+int hessian_readBytes(hessian_in_t in, unsigned char **value, unsigned int *readLength) {
+	return hessian_readNBytes(in, 0, -1, value, readLength);
+}
+
+int hessian_readNBytes(hessian_in_t in, int offset, int length, unsigned char **value, unsigned int *readLength) {
+	*readLength = 0;
+
+	bool done = false;
+	if (in->chunkLength == END_OF_DATA) {
+		done = true;
+	} else if (in->chunkLength == 0) {
+		unsigned char tag = hessian_read(in);
+
+		switch (tag) {
+			case 'N':
+				in->chunkLength = 0;
+				in->lastChunk = true;
+				break;
+			case 'B':
+			case 'b':
+				in->lastChunk = tag == 'B';
+				hessian_parseInt16(in, &(in->chunkLength));
+				break;
+
+			case 0x20: case 0x21: case 0x22: case 0x23:
+			case 0x24: case 0x25: case 0x26: case 0x27:
+			case 0x28: case 0x29: case 0x2a: case 0x2b:
+			case 0x2c: case 0x2d: case 0x2e: case 0x2f:
+				in->chunkLength = tag - 0x20;
+				in->lastChunk = true;
+				break;
+
+			default:
+				in->chunkLength = 0;
+				in->lastChunk = true;
+				break;
+		}
+	}
+
+	while (!done) {
+		unsigned int newSize = *readLength + in->chunkLength;
+		*value = realloc(*value, sizeof(char) * (*readLength + in->chunkLength));
+
+		if (in->chunkLength > 0) {
+			unsigned char c = hessian_read(in);
+			(*value)[(*readLength) + offset] = c;
+			in->chunkLength--;
+			(*readLength)++;
+			length--;
+
+			if (length == 0) {
+				done = true;
+			}
+
+		} else if (in->lastChunk) {
+			done = true;
+			if (*readLength != 0) {
+				in->chunkLength = END_OF_DATA;
+			}
+		} else {
+			unsigned char tag = hessian_read(in);
+			switch (tag) {
+				case 'B':
+				case 'b':
+					done = tag == 'S';
+
+					hessian_parseInt16(in, &in->chunkLength);
+					break;
+
+				case 0x20: case 0x21: case 0x22: case 0x23:
+				case 0x24: case 0x25: case 0x26: case 0x27:
+				case 0x28: case 0x29: case 0x2a: case 0x2b:
+				case 0x2c: case 0x2d: case 0x2e: case 0x2f:
+					in->chunkLength = tag - 0x20;
+					in->lastChunk = true;
+					break;
+
+				default:
+					in->chunkLength = 0;
+					in->lastChunk = true;
+				break;
+			}
+		}
+	}
+
+	if (in->lastChunk && in->chunkLength == 0) {
+		in->chunkLength = END_OF_DATA;
+	}
+
+	return 0;
+}
+
+int hessian_parseChar(hessian_in_t in, char *c) {
+	unsigned char ch = hessian_read(in);
+
+	if (ch < 0x80) {
+		*c = ch;
+	} else if ((ch & 0xe0) == 0xc0) {
+		char ch1 = hessian_read(in);
+
+		*c = ((ch & 0x1f) << 6) + (ch1 & 0x3f);
+	} else if ((ch & 0xf0) == 0xe0) {
+		char ch1 = hessian_read(in);
+		char ch2 = hessian_read(in);
+
+		*c = ((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f);
+	} else {
+		*c = '\0';
+	}
+
+	return 0;
+}
+
+int hessian_parseInt16(hessian_in_t in, int *value) {
+	int b16 = hessian_read(in) & 0xFF;
+	int b8 = hessian_read(in) & 0xFF;
+
+	*value = (b16 << 8)
+			+ b8;
+
+	return 0;
+}
+
+int hessian_parseInt(hessian_in_t in, int *value) {
+	int b32 = hessian_read(in) & 0xFF;
+	int b24 = hessian_read(in) & 0xFF;
+	int b16 = hessian_read(in) & 0xFF;
+	int b8 = hessian_read(in) & 0xFF;
+
+	*value = (b32 << 24)
+			+ (b24 << 16)
+			+ (b16 << 8)
+			+ b8;
+
+	return 0;
+}
+
+int hessian_parseLong(hessian_in_t in, long *value) {
+	long b64 = hessian_read(in) & 0xFF;
+	long b56 = hessian_read(in) & 0xFF;
+	long b48 = hessian_read(in) & 0xFF;
+	long b40 = hessian_read(in) & 0xFF;
+	long b32 = hessian_read(in) & 0xFF;
+	long b24 = hessian_read(in) & 0xFF;
+	long b16 = hessian_read(in) & 0xFF;
+	long b8 = hessian_read(in) & 0xFF;
+
+	long v = (b64 << 56)
+			+ (b56 << 48)
+			+ (b48 << 40)
+			+ (b40 << 32)
+			+ (b32 << 24)
+			+ (b24 << 16)
+			+ (b16 << 8)
+			+ b8;
+
+	*value = v;
+
+	return 0;
+}

Added: incubator/celix/trunk/hessian/private/src/hessian_out.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/private/src/hessian_out.c?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/private/src/hessian_out.c (added)
+++ incubator/celix/trunk/hessian/private/src/hessian_out.c Wed May 16 09:34:44 2012
@@ -0,0 +1,382 @@
+/*
+ * hessian.c
+ *
+ *  Created on: Jul 31, 2011
+ *      Author: alexander
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "hessian_2.0.h"
+
+void hessian_ensureCapacity(hessian_out_t obj, int capacity);
+
+int hessian_printString(hessian_out_t out, char *value);
+int hessian_printNString(hessian_out_t out, char *value, int offset, int length);
+
+int hessian_writeType(hessian_out_t out, char *type);
+
+int hessian_write(hessian_out_t out, unsigned char byte);
+int hessian_writeP(hessian_out_t out, unsigned char *byte);
+
+int hessian_writeBoolean(hessian_out_t out, bool value) {
+	hessian_ensureCapacity(out, out->offset + 1);
+
+	if (value) {
+		char c = 'T';
+		hessian_writeP(out, &c);
+	} else {
+		out->buffer[out->offset++] = 'F';
+		out->length++;
+	}
+
+	return 0;
+}
+
+int hessian_writeInt(hessian_out_t out, int value) {
+	hessian_ensureCapacity(out, out->offset + 5);
+
+	if (INT_DIRECT_MIN <= value && value <= INT_DIRECT_MAX)
+		hessian_write(out, (char) (value + INT_ZERO));
+	else if (INT_BYTE_MIN <= value && value <= INT_BYTE_MAX) {
+		hessian_write(out, (char) (INT_BYTE_ZERO + (value >> 8)));
+		hessian_write(out, (char) (value));
+	} else if (INT_SHORT_MIN <= value && value <= INT_SHORT_MAX) {
+		hessian_write(out, (char)(INT_SHORT_ZERO + (value >> 16)));
+		hessian_write(out, (char)(value >> 8));
+		hessian_write(out, (char)(value));
+	} else {
+		hessian_write(out, (char)('I'));
+		hessian_write(out, (char)(value >> 24));
+		hessian_write(out, (char)(value >> 16));
+		hessian_write(out, (char)(value >> 8));
+		hessian_write(out, (char)(value));
+	}
+
+	return 0;
+}
+
+int hessian_writeLong(hessian_out_t out, long value) {
+	hessian_ensureCapacity(out, out->offset + 9);
+
+	if (LONG_DIRECT_MIN <= value && value <= LONG_DIRECT_MAX) {
+		hessian_write(out, (char)(value + LONG_ZERO));
+	} else if (LONG_BYTE_MIN <= value && value <= LONG_BYTE_MAX) {
+		hessian_write(out, (char)(LONG_BYTE_ZERO + (value >> 8)));
+		hessian_write(out, (char)(value));
+	} else if (LONG_SHORT_MIN <= value && value <= LONG_SHORT_MAX) {
+		hessian_write(out, (char)(LONG_SHORT_ZERO + (value >> 16)));
+		hessian_write(out, (char)(value >> 8));
+		hessian_write(out, (char)(value));
+	} else if (-0x80000000L <= value && value <= 0x7fffffffL) {
+		hessian_write(out, (char) LONG_INT);
+		hessian_write(out, (char)(value >> 24));
+		hessian_write(out, (char)(value >> 16));
+		hessian_write(out, (char)(value >> 8));
+		hessian_write(out, (char)(value));
+	} else {
+		hessian_write(out, (char) 'L');
+		hessian_write(out, (char)(value >> 56));
+		hessian_write(out, (char)(value >> 48));
+		hessian_write(out, (char)(value >> 40));
+		hessian_write(out, (char)(value >> 32));
+		hessian_write(out, (char)(value >> 24));
+		hessian_write(out, (char)(value >> 16));
+		hessian_write(out, (char)(value >> 8));
+		hessian_write(out, (char)(value));
+	}
+
+	return 0;
+}
+
+int hessian_writeDouble(hessian_out_t out, double value) {
+	hessian_ensureCapacity(out, out->offset + 9);
+
+	int intValue = (int) value;
+
+	if (intValue == value) {
+		if (intValue == 0) {
+			hessian_write(out, (char) DOUBLE_ZERO);
+		} else if (intValue == 1) {
+			hessian_write(out, (char) DOUBLE_ONE);
+		} else if (-0x80 <= intValue && intValue < 0x80) {
+			hessian_write(out, (char) DOUBLE_BYTE);
+			hessian_write(out, (char) intValue);
+		} else if (-0x8000 <= intValue && intValue < 0x8000) {
+			hessian_write(out, (char) DOUBLE_SHORT);
+			hessian_write(out, (char) ((intValue >> 8) & 0xFF));
+			hessian_write(out, (char) (intValue & 0xFF));
+		}
+	} else {
+		float f = (float) value;
+
+		if (f == value) {
+			float f = value;
+			int bits = *((int *) &f);
+
+			hessian_write(out, (char)(DOUBLE_FLOAT));
+			hessian_write(out, (char)(bits >> 24));
+			hessian_write(out, (char)(bits >> 16));
+			hessian_write(out, (char)(bits >> 8));
+			hessian_write(out, (char)(bits));
+		} else {
+			long bits = *((long *) &value);
+
+			hessian_write(out, (char) 'D');
+			hessian_write(out, (char)(bits >> 56) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits >> 48) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits >> 40) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits >> 32) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits >> 24) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits >> 16) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits >> 8) & 0x00000000000000FF);
+			hessian_write(out, (char)(bits) & 0x00000000000000FF);
+		}
+	}
+
+	return 0;
+}
+
+int hessian_writeUTCDate(hessian_out_t out, long value) {
+	hessian_ensureCapacity(out, out->offset + 9);
+
+	hessian_write(out, (int) ('d'));
+	hessian_write(out, ((int) (value >> 56)));
+	hessian_write(out, ((int) (value >> 48)));
+	hessian_write(out, ((int) (value >> 40)));
+	hessian_write(out, ((int) (value >> 32)));
+	hessian_write(out, ((int) (value >> 24)));
+	hessian_write(out, ((int) (value >> 16)));
+	hessian_write(out, ((int) (value >> 8)));
+	hessian_write(out, ((int) (value)));
+
+	return 0;
+}
+
+int hessian_writeNull(hessian_out_t out) {
+	hessian_ensureCapacity(out, out->offset + 1);
+
+	hessian_write(out, (int) ('N'));
+
+	return 0;
+}
+
+int hessian_writeString(hessian_out_t out, char *value) {
+	int length = strlen(value);
+	return hessian_writeNString(out, value, 0, length);
+}
+
+int hessian_writeNString(hessian_out_t out, char *value, int offset, int length) {
+	if (value == NULL) {
+		hessian_writeNull(out);
+	} else {
+		while (length > 0x8000) {
+			int sublen = 0x8000;
+
+			// chunk can't end in high surrogate
+			int tail = value[offset + sublen - 1];
+
+			if (0xd800 <= tail && tail <= 0xdbff)
+				sublen--;
+
+			hessian_ensureCapacity(out, out->offset + 3);
+
+			hessian_write(out, (int) 's');
+			hessian_write(out, (int)(sublen >> 8));
+			hessian_write(out, (int)(sublen));
+
+			hessian_printNString(out, value, offset, sublen);
+
+			length -= sublen;
+			offset += sublen;
+		}
+
+		if (length <= STRING_DIRECT_MAX) {
+			hessian_ensureCapacity(out, out->offset + 2);
+
+			hessian_write(out, (int)(STRING_DIRECT + length));
+		} else {
+			hessian_ensureCapacity(out, out->offset + 3);
+
+			hessian_write(out, (int)('S'));
+			hessian_write(out, (int)(length >> 8));
+			hessian_write(out, (int)(length));
+		}
+
+		hessian_printNString(out, value, offset, length);
+	}
+
+	return 0;
+}
+
+int hessian_writeBytes(hessian_out_t out, unsigned char value[], int length) {
+	return hessian_writeNBytes(out, value, 0, length);
+}
+
+int hessian_writeNBytes(hessian_out_t out, unsigned char value[], int offset, int length) {
+	if (value == NULL) {
+		hessian_writeNull(out);
+	} else {
+		while (length > 0x8000) {
+			int sublen = 0x8000;
+
+			hessian_ensureCapacity(out, out->offset + 3);
+
+			hessian_write(out, (int) 'b');
+			hessian_write(out, (int)(sublen >> 8));
+			hessian_write(out, (int) sublen);
+
+			hessian_ensureCapacity(out, out->offset + sublen);
+			memcpy(out->buffer+out->offset, value+offset, sublen);
+			out->offset += sublen;
+
+			length -= sublen;
+			offset += sublen;
+		}
+
+		if (length < 0x10) {
+			hessian_ensureCapacity(out, out->offset + 1);
+			hessian_write(out, (int)(BYTES_DIRECT + length));
+		} else {
+			hessian_ensureCapacity(out, out->offset + 3);
+			hessian_write(out, (int) 'B');
+			hessian_write(out, (int)(length >> 8));
+			hessian_write(out, (int)(length));
+		}
+
+		hessian_ensureCapacity(out, out->offset + length);
+		memcpy(out->buffer+out->offset, value+offset, length);
+
+		out->offset += length;
+	}
+
+	return 0;
+}
+
+int hessian_writeListBegin(hessian_out_t out, int length, char *type) {
+	hessian_ensureCapacity(out, out->offset + 1);
+	if (length < 0) {
+		if (type != NULL) {
+			hessian_write(out, (char) BC_LIST_VARIABLE);
+			hessian_writeType(out, type);
+		} else {
+			hessian_write(out, (char) BC_LIST_VARIABLE_UNTYPED);
+		}
+
+		return true;
+	} else if (length <= LIST_DIRECT_MAX) {
+		if (type != NULL) {
+			hessian_write(out, (char)(BC_LIST_DIRECT + length));
+			hessian_writeType(out, type);
+		} else {
+			hessian_write(out, (char)(BC_LIST_DIRECT_UNTYPED + length));
+		}
+
+		return false;
+	} else {
+		if (type != NULL) {
+			hessian_write(out, (char) BC_LIST_FIXED);
+			hessian_writeType(out, type);
+		} else {
+			hessian_write(out, (char) BC_LIST_FIXED_UNTYPED);
+		}
+
+		hessian_writeInt(out, length);
+
+		return false;
+	}
+
+	return 0;
+}
+
+int hessian_writeListEnd(hessian_out_t out) {
+	hessian_ensureCapacity(out, out->offset + 1);
+	hessian_write(out, (char) BC_END);
+
+	return 0;
+}
+
+int hessian_writeType(hessian_out_t out, char *type) {
+	int len = strlen(type);
+	if (len == 0) {
+		return 1;
+	}
+
+	// Do something with refs here
+	return hessian_writeString(out, type);
+}
+
+int hessian_startCall(hessian_out_t out, char *method, int length) {
+	hessian_ensureCapacity(out, out->offset + 1);
+	hessian_write(out, 'C');
+
+	hessian_writeString(out, method);
+	hessian_writeInt(out, length);
+
+	return 0;
+}
+
+int hessian_completeCall(hessian_out_t out) {
+	return 0;
+}
+
+int hessian_printString(hessian_out_t out, char *value) {
+	return hessian_printNString(out, value, 0, strlen(value));
+}
+
+int hessian_printNString(hessian_out_t out, char *value, int offset, int length) {
+	hessian_ensureCapacity(out, out->offset + length);
+
+	for (int i = 0; i < length; i++) {
+		int ch = value[i + offset];
+
+		if (ch < 0x80) {
+			hessian_write(out, (int)(ch));
+			out->length++;
+		} else if (ch < 0x800) {
+			hessian_write(out, (int)(0xc0 + ((ch >> 6) & 0x1f)));
+			out->length++;
+			hessian_write(out, (int)(0x80 + (ch & 0x3f)));
+			out->length++;
+		} else {
+			hessian_write(out, (int)(0xe0 + ((ch >> 12) & 0xf)));
+			out->length++;
+			hessian_write(out, (int)(0x80 + ((ch >> 6) & 0x3f)));
+			out->length++;
+			hessian_write(out, (int)(0x80 + (ch & 0x3f)));
+			out->length++;
+		}
+	}
+
+	return 0;
+}
+
+void hessian_ensureCapacity(hessian_out_t obj, int capacity) {
+	char *newArray;
+	int oldCapacity;
+	oldCapacity = obj->capacity;
+	if (capacity > oldCapacity) {
+		int newCapacity = (oldCapacity * 3) / 2 + 1;
+		if (newCapacity < capacity) {
+			newCapacity = capacity;
+		}
+		newArray = (char *) realloc(obj->buffer, sizeof(char *) * newCapacity);
+		obj->capacity = newCapacity;
+		obj->buffer = newArray;
+	}
+}
+
+int hessian_write(hessian_out_t out, unsigned char byte) {
+	out->buffer[out->offset++] = byte;
+	out->length++;
+
+	return 0;
+}
+
+int hessian_writeP(hessian_out_t out, unsigned char *byte) {
+	out->buffer[out->offset++] = *byte;
+	out->length++;
+
+	return 0;
+}

Added: incubator/celix/trunk/hessian/private/test/test_hessian_out.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/private/test/test_hessian_out.c?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/private/test/test_hessian_out.c (added)
+++ incubator/celix/trunk/hessian/private/test/test_hessian_out.c Wed May 16 09:34:44 2012
@@ -0,0 +1,77 @@
+/*
+ * test_hessian_out.c
+ *
+ *  Created on: Aug 4, 2011
+ *      Author: alexander
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <Automated.h>
+
+#include "hessian_2.0_out.h"
+
+hessian_out_t out;
+
+int setup() {
+	out = malloc(sizeof(*out));
+
+	return 0;
+}
+
+void test_hessian_writeBoolean() {
+	out = malloc(sizeof(*out));
+
+	hessian_writeBoolean(out, true);
+
+	CU_ASSERT_EQUAL(out->length, 1);
+	CU_ASSERT_EQUAL(out->buffer[0], 'T');
+}
+
+void test_hessian_writeInt() {
+	out = malloc(sizeof(*out));
+
+	hessian_writeInt(out, 0);
+
+	unsigned char c1 = out->buffer[0];
+	unsigned char expect = 0x90;
+	CU_ASSERT_EQUAL(out->length, 1);
+	CU_ASSERT_EQUAL(c1, expect);
+
+	hessian_writeInt(out, -256);
+
+	unsigned char c2[] =  { out->buffer[1], out->buffer[2] };
+	unsigned char expect2[] = { 0xC7, 0x00 };
+	CU_ASSERT_EQUAL(out->length, 3);
+	// CU_ASSERT_EQUAL(c2, expect2);
+}
+
+int main (int argc, char** argv) {
+	CU_pSuite pSuite = NULL;
+
+	/* initialize the CUnit test registry */
+	if (CUE_SUCCESS != CU_initialize_registry())
+	  return CU_get_error();
+
+	/* add a suite to the registry */
+	pSuite = CU_add_suite("Hessian output", setup, NULL);
+	if (NULL == pSuite) {
+	  CU_cleanup_registry();
+	  return CU_get_error();
+	}
+
+	/* add the tests to the suite */
+	if (
+			NULL == CU_add_test(pSuite, "test boolean", test_hessian_writeBoolean)
+			|| NULL == CU_add_test(pSuite, "test int", test_hessian_writeInt)
+		) {
+		CU_cleanup_registry();
+		return CU_get_error();
+	}
+
+	CU_set_output_filename(argv[1]);
+	CU_list_tests_to_file();
+	CU_automated_run_tests();
+	CU_cleanup_registry();
+	return CU_get_error();
+}

Added: incubator/celix/trunk/hessian/private/test/test_service.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/private/test/test_service.h?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/private/test/test_service.h (added)
+++ incubator/celix/trunk/hessian/private/test/test_service.h Wed May 16 09:34:44 2012
@@ -0,0 +1,16 @@
+/*
+ * test_service.h
+ *
+ *  Created on: Aug 5, 2011
+ *      Author: alexander
+ */
+
+#ifndef TEST_SERVICE_H_
+#define TEST_SERVICE_H_
+
+typedef struct test_service *test_service_t;
+
+void testService_sayHello(test_service_t testService, char *message);
+
+
+#endif /* TEST_SERVICE_H_ */

Added: incubator/celix/trunk/hessian/private/test/test_service_proxy.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/private/test/test_service_proxy.c?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/private/test/test_service_proxy.c (added)
+++ incubator/celix/trunk/hessian/private/test/test_service_proxy.c Wed May 16 09:34:44 2012
@@ -0,0 +1,16 @@
+/*
+ * test_encoder.c
+ *
+ *  Created on: Aug 5, 2011
+ *      Author: alexander
+ */
+
+#include "hessian_2.0_out.h"
+
+void testServiceProxy_sayHello(char *message) {
+	hessian_out_t out = malloc(sizeof(*out));
+
+	hessian_writeString(out, message);
+
+	// tcp send out->buffer;
+}

Added: incubator/celix/trunk/hessian/private/test/test_service_skeleton.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/private/test/test_service_skeleton.c?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/private/test/test_service_skeleton.c (added)
+++ incubator/celix/trunk/hessian/private/test/test_service_skeleton.c Wed May 16 09:34:44 2012
@@ -0,0 +1,31 @@
+/*
+ * test_sercice_skeleton.c
+ *
+ *  Created on: Aug 5, 2011
+ *      Author: alexander
+ */
+
+#include "hessian_2.0_in.h"
+
+void testServiceSkeleton_sayHello(hessian_in_t in);
+
+void testServiceSkeleton_handleData(hessian_in_t in) {
+	char *method = NULL;
+	hessian_readCall(in, &method);
+
+	switch (method) {
+		case "sayHello":
+			testServiceSkeleton_sayHello(in);
+			break;
+		default:
+			break;
+	}
+}
+
+void testServiceSkeleton_sayHello(hessian_in_t in) {
+	char *message = NULL;
+	int read;
+	hessian_readString(in, &message, &read);
+
+	testService_sayHello(NULL, message);
+}

Added: incubator/celix/trunk/hessian/public/include/hessian_2.0.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/public/include/hessian_2.0.h?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/public/include/hessian_2.0.h (added)
+++ incubator/celix/trunk/hessian/public/include/hessian_2.0.h Wed May 16 09:34:44 2012
@@ -0,0 +1,27 @@
+/*
+ * hessian_2.0.h
+ *
+ *  Created on: Aug 1, 2011
+ *      Author: alexander
+ */
+
+#ifndef HESSIAN_2_0_H_
+#define HESSIAN_2_0_H_
+
+#include "hessian_2.0_in.h"
+#include "hessian_2.0_out.h"
+
+#include "hessian_constants.h"
+
+struct hessian {
+	long offset;
+	long length;
+	long capacity;
+
+	unsigned char *buffer;
+
+	bool lastChunk;
+	unsigned int chunkLength;
+};
+
+#endif /* HESSIAN_2_0_H_ */

Added: incubator/celix/trunk/hessian/public/include/hessian_2.0_in.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/public/include/hessian_2.0_in.h?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/public/include/hessian_2.0_in.h (added)
+++ incubator/celix/trunk/hessian/public/include/hessian_2.0_in.h Wed May 16 09:34:44 2012
@@ -0,0 +1,31 @@
+/*
+ * hessian_2.0_in.h
+ *
+ *  Created on: Aug 1, 2011
+ *      Author: alexander
+ */
+
+#ifndef HESSIAN_2_0_IN_H_
+#define HESSIAN_2_0_IN_H_
+
+#include <stdbool.h>
+
+#include "hessian_2.0.h"
+
+typedef struct hessian * hessian_in_t;
+
+int hessian_readBoolean(hessian_in_t in, bool *value);
+int hessian_readInt(hessian_in_t in, int *value);
+int hessian_readLong(hessian_in_t in, long *value);
+int hessian_readDouble(hessian_in_t in, double *value);
+int hessian_readUTCDate(hessian_in_t in, long *value);
+int hessian_readNull(hessian_in_t in);
+int hessian_readChar(hessian_in_t in, char *value);
+int hessian_readString(hessian_in_t in, char **value, unsigned int *readLength);
+int hessian_readNString(hessian_in_t in, int offset, int length, char **value, unsigned int *readLength);
+int hessian_readByte(hessian_in_t in, unsigned char *value);
+int hessian_readBytes(hessian_in_t in, unsigned char **value, unsigned int *readLength);
+int hessian_readNBytes(hessian_in_t in, int offset, int length, unsigned char **value, unsigned int *readLength);
+
+
+#endif /* HESSIAN_2_0_IN_H_ */

Added: incubator/celix/trunk/hessian/public/include/hessian_2.0_out.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/public/include/hessian_2.0_out.h?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/public/include/hessian_2.0_out.h (added)
+++ incubator/celix/trunk/hessian/public/include/hessian_2.0_out.h Wed May 16 09:34:44 2012
@@ -0,0 +1,42 @@
+/*
+ * hessian_2.0.h
+ *
+ *  Created on: Jul 31, 2011
+ *      Author: alexander
+ */
+
+#ifndef HESSIAN_2_0_OUT_H_
+#define HESSIAN_2_0_OUT_H_
+
+#include <stdbool.h>
+
+#include "linkedlist.h"
+#include "array_list.h"
+#include "hessian_2.0.h"
+
+typedef struct hessian * hessian_out_t;
+
+int hessian_writeBoolean(hessian_out_t out, bool value);
+int hessian_writeInt(hessian_out_t out, int value);
+int hessian_writeLong(hessian_out_t out, long value);
+int hessian_writeDouble(hessian_out_t out, double value);
+int hessian_writeUTCDate(hessian_out_t out, long value);
+int hessian_writeNull(hessian_out_t out);
+int hessian_writeString(hessian_out_t out, char *value);
+int hessian_writeNString(hessian_out_t out, char *value, int offset, int length);
+int hessian_writeBytes(hessian_out_t out, unsigned char value[], int length);
+int hessian_writeNBytes(hessian_out_t out, unsigned char value[], int offset, int length);
+
+int hessian_writeListBegin(hessian_out_t out, int size, char *type);
+int hessian_writeListEnd(hessian_out_t out);
+
+int hessian_writeObjectBegin(hessian_out_t out, char *type);
+int hessian_writeObjectDefinition(hessian_out_t out, char **fieldNames, int fields);
+int hessian_writeObjectEnd(hessian_out_t out);
+
+int hessian_startCall(hessian_out_t out, char *method, int length);
+int hessian_completeCall(hessian_out_t out);
+
+
+
+#endif /* HESSIAN_2_0_OUT_H_ */

Added: incubator/celix/trunk/hessian/public/include/hessian_constants.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/public/include/hessian_constants.h?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/public/include/hessian_constants.h (added)
+++ incubator/celix/trunk/hessian/public/include/hessian_constants.h Wed May 16 09:34:44 2012
@@ -0,0 +1,66 @@
+/*
+ * hessian_constants.h
+ *
+ *  Created on: Jul 31, 2011
+ *      Author: alexander
+ */
+
+#ifndef HESSIAN_CONSTANTS_H_
+#define HESSIAN_CONSTANTS_H_
+
+static int INT_DIRECT_MIN = -0x10;
+static int INT_DIRECT_MAX = 0x2f;
+static int INT_ZERO = 0x90;
+
+static int INT_BYTE_MIN = -0x800;
+static int INT_BYTE_MAX = 0x7ff;
+static int INT_BYTE_ZERO = 0xc8;
+
+static int INT_SHORT_MIN = -0x40000;
+static int INT_SHORT_MAX = 0x3ffff;
+static int INT_SHORT_ZERO = 0xd4;
+
+static long LONG_DIRECT_MIN = -0x08;
+static long LONG_DIRECT_MAX =  0x0f;
+static int LONG_ZERO = 0xe0;
+
+static long LONG_BYTE_MIN = -0x800;
+static long LONG_BYTE_MAX =  0x7ff;
+static int LONG_BYTE_ZERO = 0xf8;
+
+static int LONG_SHORT_MIN = -0x40000;
+static int LONG_SHORT_MAX = 0x3ffff;
+static int LONG_SHORT_ZERO = 0x3c;
+
+static int STRING_DIRECT_MAX = 0x1f;
+static int STRING_DIRECT = 0x00;
+
+static int BYTES_DIRECT_MAX = 0x0f;
+static int BYTES_DIRECT = 0x20;
+  // 0x30-0x37 is reserved
+
+static int LONG_INT = 0x77;
+
+static int DOUBLE_ZERO = 0x67;
+static int DOUBLE_ONE = 0x68;
+static int DOUBLE_BYTE = 0x69;
+static int DOUBLE_SHORT = 0x6a;
+static int DOUBLE_FLOAT = 0x6b;
+
+static int BC_END = 'Z';
+
+static int BC_LIST_VARIABLE = 0x55;
+static int BC_LIST_FIXED = 'V';
+static int BC_LIST_VARIABLE_UNTYPED = 0x57;
+static int BC_LIST_FIXED_UNTYPED = 0x58;
+
+static int BC_LIST_DIRECT = 0x70;
+static int BC_LIST_DIRECT_UNTYPED = 0x78;
+static int LIST_DIRECT_MAX = 0x7;
+
+static int REF_BYTE = 0x4a;
+static int REF_SHORT = 0x4b;
+
+static int TYPE_REF = 0x75;
+
+#endif /* HESSIAN_CONSTANTS_H_ */

Added: incubator/celix/trunk/hessian/test.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hessian/test.c?rev=1339082&view=auto
==============================================================================
--- incubator/celix/trunk/hessian/test.c (added)
+++ incubator/celix/trunk/hessian/test.c Wed May 16 09:34:44 2012
@@ -0,0 +1,74 @@
+/*
+ * test.c
+ *
+ *  Created on: Jul 31, 2011
+ *      Author: alexander
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "hessian_2.0_out.h"
+#include "hessian_2.0_in.h"
+
+int main(int argc, char **argv) {
+	hessian_out_t out = malloc(sizeof(*out));
+
+//	hessian_writeDouble(out, 12.25);
+//	hessian_writeUTCDate(out, 894621091000l);
+//	hessian_writeLong(out, 1324123l);
+//	hessian_writeString(out, "hello");
+	unsigned char b[22];
+	int i = 0;
+	b[i++] = 'a';b[i++] = 'b';b[i++] = 'c';b[i++] = 'd';b[i++] = 'e';b[i++] = 'f';b[i++] = 'g';b[i++] = 'h';b[i++] = 'i';b[i++] = 'j';b[i++] = 'k';
+	b[i++] = 'l';b[i++] = 'm';b[i++] = 'n';b[i++] = 'o';b[i++] = 'p';b[i++] = 'q';b[i++] = 'r';b[i++] = 's';b[i++] = 't';b[i++] = 'u';b[i++] = 'v';
+
+	hessian_writeBytes(out, b, 22);
+//	hessian_writeListBegin(out, 1, "string");
+//	hessian_writeString(out, "test");
+//	hessian_writeListEnd(out);
+
+	//4832798725635008448
+
+	double d = 81273459184.123;
+	char *langeString = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
+			"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
+
+//	printf("Stringl: %d\n", strlen(langeString));
+
+//	hessian_writeString(out, langeString);
+
+
+	for (i = 0; i < out->offset; i++) {
+		printf("%X ", out->buffer[i]);
+	}
+	printf("\n");
+
+
+	FILE *fp = fopen("mybinfile.ttt", "wb");
+
+	//the string length + 1 for the null terminator
+	fwrite(out->buffer, sizeof(char), out->offset, fp);
+
+	fclose(fp);
+
+	out->offset = 0;
+	unsigned char *rb = NULL;
+	int read;
+	rb = NULL;
+	hessian_readNBytes(out, 0, 10, &rb, &read);
+	printf("Read: %s\n", rb);
+	char ch;
+	hessian_readByte(out, &ch);
+	printf("Read: %c\n", ch);
+	hessian_readByte(out, &ch);
+		printf("Read: %c\n", ch);
+		hessian_readByte(out, &ch);
+			printf("Read: %c\n", ch);
+			hessian_readByte(out, &ch);
+				printf("Read: %c\n", ch);
+				rb = NULL;
+					hessian_readNBytes(out, 0, 10, &rb, &read);
+					printf("Read: %s\n", rb);
+	printf("Read: %d\n", read);
+}
+