summaryrefslogtreecommitdiff
path: root/src/main/include/log4cxx/helpers/objectoutputstream.h
blob: 718307b5b96a4c7b73b75f3ad0b9b2ca2ed81867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * 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.
 */

#ifndef _LOG4CXX_HELPERS_OBJECTOUTPUTSTREAM_H
#define _LOG4CXX_HELPERS_OBJECTOUTPUTSTREAM_H

#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/mdc.h>
#include <log4cxx/helpers/outputstream.h>
#include <log4cxx/helpers/charsetencoder.h>

namespace log4cxx
{
	namespace helpers
	{
		/**
		 *  Emulates java serialization.
		 */
		class LOG4CXX_EXPORT ObjectOutputStream : public ObjectImpl
		{
			public:
				DECLARE_ABSTRACT_LOG4CXX_OBJECT(ObjectOutputStream)
				BEGIN_LOG4CXX_CAST_MAP()
						LOG4CXX_CAST_ENTRY(ObjectOutputStream)
				END_LOG4CXX_CAST_MAP()

				ObjectOutputStream(OutputStreamPtr os, Pool& p);
				virtual ~ObjectOutputStream();

				void close(Pool& p);
				void flush(Pool& p);
				void writeObject(const LogString&, Pool& p);
				void writeUTFString(const std::string&, Pool& p);
				void writeObject(const MDC::Map& mdc, Pool& p);
				void writeInt(int val, Pool& p);
				void writeLong(log4cxx_time_t val, Pool& p);
				void writeProlog(const	char*	className,
										int		classDescIncrement,
										char*	bytes,
										size_t	len,
										Pool&	p);
				void writeNull(Pool& p);

				enum { STREAM_MAGIC		= 0xACED };
				enum { STREAM_VERSION	= 5 };
				enum
				{
					TC_NULL			= 0x70,
					TC_REFERENCE	= 0x71,
					TC_CLASSDESC	= 0x72,
					TC_OBJECT		= 0x73,
					TC_STRING		= 0x74,
					TC_ARRAY		= 0x75,
					TC_CLASS		= 0x76,
					TC_BLOCKDATA	= 0x77,
					TC_ENDBLOCKDATA	= 0x78
				};
				enum
				{
					SC_WRITE_METHOD	= 0x01,
					SC_SERIALIZABLE	= 0x02
				};

				void writeByte(char val, Pool& p);
				void writeBytes(const char* bytes, size_t len, Pool& p);

			private:
				ObjectOutputStream(const ObjectOutputStream&);
				ObjectOutputStream& operator=(const ObjectOutputStream&);

				OutputStreamPtr os;
				log4cxx::helpers::CharsetEncoderPtr utf8Encoder;
				unsigned int objectHandle;
				typedef std::map<std::string, unsigned int> ClassDescriptionMap;
				ClassDescriptionMap* classDescriptions;
		};

		LOG4CXX_PTR_DEF(ObjectOutputStream);
	} // namespace helpers

} //namespace log4cxx

#endif //_LOG4CXX_HELPERS_OUTPUTSTREAM_H