Skip to content

Commit 57e200c

Browse files
committed
Better marshalling of enums
Still not fully equivalent to the Java output, but can be read again by javaobj
1 parent 7ae7033 commit 57e200c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

javaobj.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ class JavaObjectConstants(object):
364364
TC_LONGSTRING = 0x7C
365365
TC_PROXYCLASSDESC = 0x7D
366366
TC_ENUM = 0x7E
367-
TC_MAX = 0x7E
367+
# Ignore TC_MAX: we don't use it and it messes with TC_ENUM
368+
# TC_MAX = 0x7E
368369

369370
# classDescFlags
370371
SC_WRITE_METHOD = 0x01 # if SC_SERIALIZABLE
@@ -1223,8 +1224,23 @@ def write_enum(self, obj):
12231224
12241225
:param obj: A JavaEnum object
12251226
"""
1227+
# FIXME: the output doesn't have the same references as the real
1228+
# serializable form
12261229
self._writeStruct(">B", 1, (self.TC_ENUM,))
1227-
self.write_classdesc(obj.get_class())
1230+
1231+
try:
1232+
idx = self.references.index(obj)
1233+
except ValueError:
1234+
# New reference
1235+
self.references.append(obj)
1236+
logging.debug(
1237+
"*** Adding ref 0x%X for enum: %s",
1238+
len(self.references) - 1 + self.BASE_REFERENCE_IDX, obj)
1239+
1240+
self.write_classdesc(obj.get_class())
1241+
else:
1242+
self.write_reference(idx)
1243+
12281244
self.write_string(obj.constant)
12291245

12301246
def write_blockdata(self, obj, parent=None):
@@ -1433,7 +1449,7 @@ def _write_value(self, field_type, value):
14331449
if field_type == self.TYPE_BOOLEAN:
14341450
self._writeStruct(">B", 1, (1 if value else 0,))
14351451
elif field_type == self.TYPE_BYTE:
1436-
self._writeStruct(">B", 1, (value,))
1452+
self._writeStruct(">b", 1, (value,))
14371453
elif field_type == self.TYPE_SHORT:
14381454
self._writeStruct(">h", 1, (value,))
14391455
elif field_type == self.TYPE_INTEGER:

0 commit comments

Comments
 (0)