12#ifndef CLASSDESC_JAVACLASS_SERIALISATION_H
13#define CLASSDESC_JAVACLASS_SERIALISATION_H
24 template <>
void dump(
dump_t& buf,
const string& d,
const u8& a)
26 template <>
void dump(
dump_t& buf,
const string& d,
const u4& a)
28 template <>
void dump(
dump_t& buf,
const string& d,
const u2& a)
30 template <>
void dump(
dump_t& buf,
const string& d,
const u1& a)
31 {buf << std::hex << int(a);}
45 void operator()(
classdesc::pack_t& buf,
const classdesc::string& d,
const std::string& a)
49 buf.packraw(a.c_str(),length);
57 void operator()(classdesc::unpack_t& buf,
const classdesc::string& d, U& a)
61 char *s=
new char[length];
62 buf.unpackraw(s,length);
63 a=std::string(s,length);
72 void operator()(classdesc::unpack_t& buf,
const classdesc::string& d, U& a)
75 for (
int i=0; i<8; i++)
79 a.v=(a.v<<8) | (0xFF&b);
90 for (
int i=7; i>=0; i--)
92 classdesc::u1 b = a.v >> 8*i;
102 void operator()(classdesc::unpack_t& buf,
const classdesc::string& d, U& a)
105 for (
int i=0; i<4; i++)
109 a.v=(a.v<<8) | (0xFF&b);
119 for (
int i=3; i>=0; i--)
121 classdesc::u1 b = a.v >> 8*i;
130 void operator()(classdesc::unpack_t& buf,
const classdesc::string& d,
classdesc::u2& a)
132 classdesc::u1 b1, b2;
135 a=(b1<<8)| (0xFF & b2);
144 classdesc::u1 b1=a.v>>8, b2=a.v;
159 case JVM_CONSTANT_Class:
160 case JVM_CONSTANT_String:
161 pack(buf,d,a.get<
u2>());
break;
162 case JVM_CONSTANT_Fieldref:
163 case JVM_CONSTANT_Methodref:
164 case JVM_CONSTANT_InterfaceMethodref:
165 pack(buf,d,a.get<
Ref>());
break;
166 case JVM_CONSTANT_Integer:
167 case JVM_CONSTANT_Float:
168 pack(buf,d,a.get<
u4>());
break;
169 case JVM_CONSTANT_Long:
170 case JVM_CONSTANT_Double:
171 pack(buf,d,a.get<
u8>());
break;
172 case JVM_CONSTANT_NameAndType:
175 case JVM_CONSTANT_Utf8:
176 pack(buf,d,a.get<std::string>());
break;
184 void operator()(classdesc::unpack_t& buf,
const classdesc::string& d,
classdesc::cp_info& a)
191 case JVM_CONSTANT_Class:
192 case JVM_CONSTANT_String:
193 a.unpack<
u2>(buf,tag);
break;
194 case JVM_CONSTANT_Fieldref:
195 case JVM_CONSTANT_Methodref:
196 case JVM_CONSTANT_InterfaceMethodref:
197 a.unpack<
Ref>(buf,tag);
break;
198 case JVM_CONSTANT_Integer:
199 case JVM_CONSTANT_Float:
200 a.unpack<
u4>(buf,tag);
break;
201 case JVM_CONSTANT_Long:
202 case JVM_CONSTANT_Double:
203 a.unpack<
u8>(buf,tag);
break;
204 case JVM_CONSTANT_NameAndType:
207 case JVM_CONSTANT_Utf8:
208 a.unpack<std::string>(buf,tag);
break;
222 for (
int i=1; i<size; i++)
231 void operator()(
classdesc::pack_t& buf,
const classdesc::string& d, std::vector<classdesc::cp_info>& a)
235 for (
int i=1; i<size; i++)
246 pack(buf,d,a.attribute_name_index);
250 for (
size_t i=0; i<a.info.size(); i++)
251 pack(buf,d,a.info[i]);
260 unpack(buf,d,a.attribute_name_index);
262 unpack(buf,d,length);
264 a.info.resize(length);
265 for (
size_t i=0; i<a.info.size(); i++)
266 unpack(buf,d,a.info[i]);
276 pack(b1,
string(),*
this);
289 case JVM_CONSTANT_Class:
290 case JVM_CONSTANT_String:
291 dump(buf,d,a.get<
u2>());
break;
292 case JVM_CONSTANT_Fieldref:
293 case JVM_CONSTANT_Methodref:
294 case JVM_CONSTANT_InterfaceMethodref:
295 dump(buf,d,a.get<
Ref>());
break;
296 case JVM_CONSTANT_Integer:
297 dump(buf,d,a.get<
int>());
break;
298 case JVM_CONSTANT_Float:
299 dump(buf,d,a.get<
float>());
break;
300 case JVM_CONSTANT_Long:
301 dump(buf,d,a.get<
long long>());
break;
302 case JVM_CONSTANT_Double:
303 dump(buf,d,a.get<
double>());
break;
304 case JVM_CONSTANT_NameAndType:
307 case JVM_CONSTANT_Utf8:
308 dump(buf,d,a.get<std::string>());
break;
318 dump(targ,desc+
".attribute_name_index",arg.attribute_name_index);
319 int tab=format(targ, desc+
".info");
320 targ << std::setw(tab) <<
"";
321 for (u1 *c=&arg.info[0]; c!=&arg.info[0]+arg.info.size(); c++)
322 targ <<
" "<<std::setw(2)<<std::setfill(
'0')<<std::hex << int(*c);
323 targ<<std::setfill(
' ')<<std::endl;
328template <
class T>
void classdesc::cp_info::unpack(
pack_t& t, u1 tag) {
Definition javaClass.h:618
Definition dump_base.h:30
Definition pack_base.h:138
size_t size() const
size of buffer
Definition pack_base.h:170
const char * data() const
actual buffer
Definition pack_base.h:168
textual representation descriptor
Java classfile representation.
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition classdesc_access.h:20
Contains definitions related to classdesc functionality.
void dump(dump_t &o, const string &d, const T &a)
forward declare generic dump operation
Definition dump_epilogue.h:55
void pack(pack_t &targ, const string &desc, is_treenode dum, const T *const &arg)
serialise a tree (or DAG)
Definition pack_graph.h:28
void unpack(unpack_t &targ, const string &desc, is_treenode dum, T *&arg)
unserialise a tree.
Definition pack_graph.h:44
Definition javaClass.h:659
Definition javaClass.h:606
Definition javaClass.h:594
Definition javaClass.h:666
Definition javaClass.h:49
Definition javaClass.h:62
Definition javaClass.h:72
class to allow access to private members
Definition classdesc_access.h:21
class to allow access to private members
Definition classdesc_access.h:22