Added optional maxLength param to validateAndEncode.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5143 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Bruno Garcia
2008-05-30 02:05:04 +00:00
parent 7ac8aa5583
commit 783ceaf951
+10 -2
View File
@@ -77,11 +77,19 @@ public class ObjectMarshaller
/**
* Validate the value and encode it. Arrays are not broken-up.
* @param maxLength The maximum size of the data after encoding,
* or -1 if no size restriction.
*/
public static function validateAndEncode (obj :Object) :ByteArray
public static function validateAndEncode (obj :Object, maxLength :int = -1) :ByteArray
{
validateValue(obj);
return encode(obj, false) as ByteArray;
var data :ByteArray = encode(obj, false) as ByteArray;
if (maxLength >= 0 && data != null && data.length > maxLength) {
throw new ArgumentError("Cannot encode data of size " + data.length + " bytes. May be at most " + maxLength + " bytes.");
}
return data;
}
/**