12 #ifndef JAVACLASS_SERIALISATION_H 13 #define 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);}
44 void operator()(
classdesc::pack_t& buf,
const classdesc::string& d,
const std::string& a)
48 buf.packraw(a.c_str(),length);
60 char *s=
new char[length];
61 buf.unpackraw(s,length);
62 a=std::string(s,length);
75 for (
int i=0; i<length; i++)
89 for (
int i=0; i<length; i++)
101 for (
int i=0; i<8; i++)
105 a.v=(a.v<<8) | (0xFF&b);
116 for (
int i=7; i>=0; i--)
118 classdesc::u1 b = a.v >> 8*i;
131 for (
int i=0; i<4; i++)
135 a.v=(a.v<<8) | (0xFF&b);
145 for (
int i=3; i>=0; i--)
147 classdesc::u1 b = a.v >> 8*i;
158 classdesc::u1 b1, b2;
161 a=(b1<<8)| (0xFF & b2);
170 classdesc::u1 b1=a.v>>8, b2=a.v;
185 case JVM_CONSTANT_Class:
186 case JVM_CONSTANT_String:
187 pack(buf,d,a.get<
u2>());
break;
188 case JVM_CONSTANT_Fieldref:
189 case JVM_CONSTANT_Methodref:
190 case JVM_CONSTANT_InterfaceMethodref:
191 pack(buf,d,a.get<
Ref>());
break;
192 case JVM_CONSTANT_Integer:
193 case JVM_CONSTANT_Float:
194 pack(buf,d,a.get<
u4>());
break;
195 case JVM_CONSTANT_Long:
196 case JVM_CONSTANT_Double:
197 pack(buf,d,a.get<
u8>());
break;
198 case JVM_CONSTANT_NameAndType:
201 case JVM_CONSTANT_Utf8:
202 pack(buf,d,a.get<std::string>());
break;
217 case JVM_CONSTANT_Class:
218 case JVM_CONSTANT_String:
219 a.unpack<
u2>(buf,tag);
break;
220 case JVM_CONSTANT_Fieldref:
221 case JVM_CONSTANT_Methodref:
222 case JVM_CONSTANT_InterfaceMethodref:
223 a.unpack<
Ref>(buf,tag);
break;
224 case JVM_CONSTANT_Integer:
225 case JVM_CONSTANT_Float:
226 a.unpack<
u4>(buf,tag);
break;
227 case JVM_CONSTANT_Long:
228 case JVM_CONSTANT_Double:
229 a.unpack<
u8>(buf,tag);
break;
230 case JVM_CONSTANT_NameAndType:
233 case JVM_CONSTANT_Utf8:
234 a.unpack<std::string>(buf,tag);
break;
248 for (
int i=1; i<size; i++)
257 void operator()(
classdesc::pack_t& buf,
const classdesc::string& d, std::vector<classdesc::cp_info>& a)
261 for (
int i=1; i<size; i++)
272 pack(buf,d,a.attribute_name_index);
276 for (
size_t i=0; i<a.info.size(); i++)
277 pack(buf,d,a.info[i]);
286 unpack(buf,d,a.attribute_name_index);
290 a.info.resize(length);
291 for (
size_t i=0; i<a.info.size(); i++)
302 pack(b1,
string(),*
this);
315 case JVM_CONSTANT_Class:
316 case JVM_CONSTANT_String:
317 dump(buf,d,a.get<
u2>());
break;
318 case JVM_CONSTANT_Fieldref:
319 case JVM_CONSTANT_Methodref:
320 case JVM_CONSTANT_InterfaceMethodref:
321 dump(buf,d,a.get<
Ref>());
break;
322 case JVM_CONSTANT_Integer:
323 dump(buf,d,a.get<
int>());
break;
324 case JVM_CONSTANT_Float:
325 dump(buf,d,a.get<
float>());
break;
326 case JVM_CONSTANT_Long:
327 dump(buf,d,a.get<
long long>());
break;
328 case JVM_CONSTANT_Double:
329 dump(buf,d,a.get<
double>());
break;
330 case JVM_CONSTANT_NameAndType:
333 case JVM_CONSTANT_Utf8:
334 dump(buf,d,a.get<std::string>());
break;
344 dump(targ,desc+
".attribute_name_index",arg.attribute_name_index);
345 int tab=format(targ, desc+
".info");
346 targ << std::setw(tab) <<
"";
347 for (u1 *c=&arg.info[0]; c!=&arg.info[0]+arg.info.size(); c++)
348 targ <<
" "<<std::setw(2)<<std::setfill(
'0')<<std::hex << int(*c);
349 targ<<std::setfill(
' ')<<std::endl;
354 template <
class T>
void classdesc::cp_info::unpack(
pack_t& t, u1 tag) {
Definition: javaClass.h:67
Java classfile representation.
size_t size() const
size of buffer
Definition: pack_base.h:154
Definition: javaClass.h:643
class to allow access to private members
Definition: classdesc_access.h:21
textual representation descriptor
Definition: javaClass.h:579
class to allow access to private members
Definition: classdesc_access.h:22
Definition: javaClass.h:603
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 dump(dump_t &o, const string &d, const T &a)
forward declare generic dump operation
Definition: dump_epilogue.h:55
const char * data() const
actual buffer
Definition: pack_base.h:152
Definition: dump_base.h:29
Definition: javaClass.h:45
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
Definition: pack_base.h:124
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
Definition: javaClass.h:57
Definition: javaClass.h:591
void unpack(unpack_t &targ, const string &desc, is_treenode dum, T *&arg)
unserialise a tree.
Definition: pack_graph.h:44