From 783ceaf951a0681696fd840b28efa0b824950d30 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Fri, 30 May 2008 02:05:04 +0000 Subject: [PATCH] Added optional maxLength param to validateAndEncode. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5143 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/ObjectMarshaller.as | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/as/com/threerings/util/ObjectMarshaller.as b/src/as/com/threerings/util/ObjectMarshaller.as index 79e0f172a..3ae22f799 100644 --- a/src/as/com/threerings/util/ObjectMarshaller.as +++ b/src/as/com/threerings/util/ObjectMarshaller.as @@ -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; } /**