Skip to content

Commit

Permalink
Better marshalling of enums
Browse files Browse the repository at this point in the history
Still not fully equivalent to the Java output, but can be read again by javaobj
  • Loading branch information
tcalmant committed Sep 9, 2016
1 parent 7ae7033 commit 57e200c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions javaobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ class JavaObjectConstants(object):
TC_LONGSTRING = 0x7C
TC_PROXYCLASSDESC = 0x7D
TC_ENUM = 0x7E
TC_MAX = 0x7E
# Ignore TC_MAX: we don't use it and it messes with TC_ENUM
# TC_MAX = 0x7E

# classDescFlags
SC_WRITE_METHOD = 0x01 # if SC_SERIALIZABLE
Expand Down Expand Up @@ -1223,8 +1224,23 @@ def write_enum(self, obj):
:param obj: A JavaEnum object
"""
# FIXME: the output doesn't have the same references as the real
# serializable form
self._writeStruct(">B", 1, (self.TC_ENUM,))
self.write_classdesc(obj.get_class())

try:
idx = self.references.index(obj)
except ValueError:
# New reference
self.references.append(obj)
logging.debug(
"*** Adding ref 0x%X for enum: %s",
len(self.references) - 1 + self.BASE_REFERENCE_IDX, obj)

self.write_classdesc(obj.get_class())
else:
self.write_reference(idx)

self.write_string(obj.constant)

def write_blockdata(self, obj, parent=None):
Expand Down Expand Up @@ -1433,7 +1449,7 @@ def _write_value(self, field_type, value):
if field_type == self.TYPE_BOOLEAN:
self._writeStruct(">B", 1, (1 if value else 0,))
elif field_type == self.TYPE_BYTE:
self._writeStruct(">B", 1, (value,))
self._writeStruct(">b", 1, (value,))
elif field_type == self.TYPE_SHORT:
self._writeStruct(">h", 1, (value,))
elif field_type == self.TYPE_INTEGER:
Expand Down

0 comments on commit 57e200c

Please sign in to comment.