[Red5commits] [1543] fixed deserialization of MixedArrays? and handle integer-only as well as mixed m
jbauch
luke at codegent.com
Wed Jan 24 10:51:55 EST 2007
fixed deserialization of MixedArrays? and handle integer-only as well as mixed mappings (Trac #109 and #195)
Timestamp: 11/15/06 18:13:13 EST (2 months ago)
Change: 1543
Author: jbauch
Files (see diff or trac for details):
doc/trunk/changelog.txt
java/io/trunk/src/org/red5/io/object/Deserializer.java
Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1543
Index: /java/io/trunk/src/org/red5/io/object/Deserializer.java
===================================================================
--- /java/io/trunk/src/org/red5/io/object/Deserializer.java (revision 1406)
+++ /java/io/trunk/src/org/red5/io/object/Deserializer.java (revision 1543)
@@ -23,4 +23,5 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -129,27 +130,24 @@
/**
- * Reads the input and returns a List.
- *
- * @param in
- * @return List
- */
- protected List readMixedArray(Input in) {
- if (log.isDebugEnabled()) {
- log.debug("read map");
- }
-
- int size = in.readStartMap();
-
- if (log.isDebugEnabled()) {
- log.debug("Read start mixed array: " + size);
- }
-
- final List result = new ArrayList(size);
- // Initialize array with null values
- for (int i = 0; i < size; i++) {
- result.add(null);
- }
-
- in.storeReference(result);
+ * Reads the input and returns a List or Map depending on
+ * the mixed array's keys.
+ *
+ * @param in
+ * @return List or Map
+ */
+ protected Object readMixedArray(Input in) {
+ if (log.isDebugEnabled()) {
+ log.debug("read mixed array");
+ }
+
+ // The maximum number used in this mixed array.
+ int maxNumber = in.readStartMap();
+ if (log.isDebugEnabled()) {
+ log.debug("Read start mixed array: " + maxNumber);
+ }
+
+ boolean allNumbers = true;
+ Object result;
+ final Map<Object, Object> mixedResult = new LinkedHashMap<Object, Object>(maxNumber);
while (in.hasMoreItems()) {
String key = in.readItemKey();
@@ -161,9 +159,29 @@
log.debug("item: " + item);
}
- result.set(Integer.parseInt(key), item);
+ try {
+ mixedResult.put(Integer.parseInt(key), item);
+ } catch (NumberFormatException err) {
+ mixedResult.put(key, item);
+ allNumbers = false;
+ }
if (in.hasMoreItems()) {
in.skipItemSeparator();
}
}
+
+ if (allNumbers) {
+ // MixedArray actually is a regular array
+ if (log.isDebugEnabled()) {
+ log.debug("mixed array is a regular array");
+ }
+ final List<Object> listResult = new ArrayList<Object>(maxNumber);
+ for (int i=0; i<maxNumber; i++) {
+ listResult.add(i, mixedResult.get(i));
+ }
+ result = listResult;
+ } else
+ result = mixedResult;
+
+ in.storeReference(result);
in.skipEndMap();
return result;
Index: /doc/trunk/changelog.txt
===================================================================
--- /doc/trunk/changelog.txt (revision 1541)
+++ /doc/trunk/changelog.txt (revision 1543)
@@ -21,4 +21,5 @@
- errors during "connect" are reported back to client through RTMPT
- fixed NPE in FlowControlService thread (Trac #175)
+- deserializing of mixed arrays now works in all cases (Trac #109, #195)
Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.
More information about the Red5commits
mailing list