diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2008-07-20 22:24:30 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2008-07-20 22:24:30 +0000 |
commit | 005101b7b1e7579b899c8a379f4516309e164c09 (patch) | |
tree | f5b1e9e51faa95d6957f05c3ba6dc6daa9fa02d2 /src/main/java | |
parent | 1b2638b5df6d11eef4d3a9bb81e7dd4307db0612 (diff) |
Added normalization option for BigDecimal properties.
Diffstat (limited to 'src/main/java')
3 files changed, 118 insertions, 69 deletions
diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index e88ba39..0eee3de 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -2732,7 +2732,7 @@ public final class StorableGenerator<S extends Storable> { LocalVariable encodedVar;
try {
- encodedVar = encoder.buildSerialEncoding(b, null);
+ encodedVar = encoder.buildSerialEncoding(b, null, null);
} catch (SupportException e) {
CodeBuilderUtil.throwException(b, SupportException.class, e.getMessage());
return;
@@ -2780,7 +2780,7 @@ public final class StorableGenerator<S extends Storable> { GenericEncodingStrategy<S> encoder = new GenericEncodingStrategy<S>(mStorableType, null);
try {
- encoder.buildSerialDecoding(b, null, encodedVar);
+ encoder.buildSerialDecoding(b, null, null, encodedVar);
} catch (SupportException e) {
CodeBuilderUtil.throwException(b, SupportException.class, e.getMessage());
return;
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java index c5417c4..e7a8ff9 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java @@ -25,6 +25,7 @@ import java.math.BigInteger; import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -68,6 +69,26 @@ import com.amazon.carbonado.info.StorablePropertyAdapter; * @author Brian S O'Neill
*/
public class GenericEncodingStrategy<S extends Storable> {
+ /**
+ * Defines extra encoding options.
+ *
+ * @since 1.2
+ */
+ public static enum Option {
+ /**
+ * Access properties by public methods instead of protected fields.
+ * Option should be used if class being generated doesn't have access
+ * to these fields.
+ */
+ USE_METHODS,
+
+ /**
+ * Property values such as BigDecimal are normalized before being
+ * encoded.
+ */
+ NORMALIZE,
+ }
+
private static enum Mode { KEY, DATA, SERIAL }
private final Class<S> mType;
@@ -144,9 +165,7 @@ public class GenericEncodingStrategy<S extends Storable> { * of a Storable instance.
* @param adapterInstanceClass class containing static references to
* adapter instances - defaults to instanceVar
- * @param useReadMethods when true, access properties by public read
- * methods instead of protected fields - should be used if class being
- * generated doesn't have access to these fields
+ * @param options optional encoding options
* @param partialStartVar optional variable for supporting partial key
* generation. It must be an int, whose runtime value must be less than the
* properties array length. It marks the range start of the partial
@@ -167,7 +186,7 @@ public class GenericEncodingStrategy<S extends Storable> { OrderedProperty<S>[] properties,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
- boolean useReadMethods,
+ EnumSet<Option> options,
LocalVariable partialStartVar,
LocalVariable partialEndVar)
throws SupportException
@@ -176,7 +195,7 @@ public class GenericEncodingStrategy<S extends Storable> { return buildEncoding(Mode.KEY, assembler,
extractProperties(properties), extractDirections(properties),
instanceVar, adapterInstanceClass,
- useReadMethods,
+ options,
-1, // no generation support
partialStartVar, partialEndVar);
}
@@ -194,9 +213,7 @@ public class GenericEncodingStrategy<S extends Storable> { * of a Storable instance.
* @param adapterInstanceClass class containing static references to
* adapter instances - defaults to instanceVar
- * @param useWriteMethods when true, set properties by public write
- * methods instead of protected fields - should be used if class being
- * generated doesn't have access to these fields
+ * @param options optional encoding options
* @param encodedVar required variable, which must be a byte array. At
* runtime, it references an encoded key.
*
@@ -208,14 +225,14 @@ public class GenericEncodingStrategy<S extends Storable> { OrderedProperty<S>[] properties,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
- boolean useWriteMethods,
+ EnumSet<Option> options,
LocalVariable encodedVar)
throws SupportException
{
properties = ensureKeyProperties(properties);
buildDecoding(Mode.KEY, assembler,
extractProperties(properties), extractDirections(properties),
- instanceVar, adapterInstanceClass, useWriteMethods,
+ instanceVar, adapterInstanceClass, options,
-1, null, // no generation support
encodedVar);
}
@@ -235,8 +252,7 @@ public class GenericEncodingStrategy<S extends Storable> { * of a Storable instance.
* @param adapterInstanceClass class containing static references to
* adapter instances - defaults to instanceVar
- * @param useReadMethods when true, access properties by public read
- * methods instead of protected fields
+ * @param options optional encoding options
* @param generation when non-negative, write a storable layout generation
* value in one or four bytes. Generation 0..127 is encoded in one byte, and
* 128..max is encoded in four bytes, with the most significant bit set.
@@ -251,7 +267,7 @@ public class GenericEncodingStrategy<S extends Storable> { StorableProperty<S>[] properties,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
- boolean useReadMethods,
+ EnumSet<Option> options,
int generation)
throws SupportException
{
@@ -259,7 +275,7 @@ public class GenericEncodingStrategy<S extends Storable> { return buildEncoding(Mode.DATA, assembler,
properties, null,
instanceVar, adapterInstanceClass,
- useReadMethods, generation, null, null);
+ options, generation, null, null);
}
/**
@@ -275,9 +291,7 @@ public class GenericEncodingStrategy<S extends Storable> { * of a Storable instance.
* @param adapterInstanceClass class containing static references to
* adapter instances - defaults to instanceVar
- * @param useWriteMethods when true, set properties by public write
- * methods instead of protected fields - should be used if class being
- * generated doesn't have access to these fields
+ * @param options optional encoding options
* @param generation when non-negative, decoder expects a storable layout
* generation value to match this value. Otherwise, it throws a
* CorruptEncodingException.
@@ -297,7 +311,7 @@ public class GenericEncodingStrategy<S extends Storable> { StorableProperty<S>[] properties,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
- boolean useWriteMethods,
+ EnumSet<Option> options,
int generation,
Label altGenerationHandler,
LocalVariable encodedVar)
@@ -305,7 +319,7 @@ public class GenericEncodingStrategy<S extends Storable> { {
properties = ensureDataProperties(properties);
buildDecoding(Mode.DATA, assembler, properties, null,
- instanceVar, adapterInstanceClass, useWriteMethods,
+ instanceVar, adapterInstanceClass, options,
generation, altGenerationHandler, encodedVar);
}
@@ -316,17 +330,19 @@ public class GenericEncodingStrategy<S extends Storable> { * @param assembler code assembler to receive bytecode instructions
* @param properties specific properties to decode, defaults to all
* properties if null
+ * @param options optional encoding options
* @return local variable referencing a byte array with encoded data
* @throws SupportException if any property type is not supported
* @since 1.2
*/
public LocalVariable buildSerialEncoding(CodeAssembler assembler,
- StorableProperty<S>[] properties)
+ StorableProperty<S>[] properties,
+ EnumSet<Option> options)
throws SupportException
{
properties = ensureAllProperties(properties);
return buildEncoding
- (Mode.SERIAL, assembler, properties, null, null, null, false, -1, null, null);
+ (Mode.SERIAL, assembler, properties, null, null, null, options, -1, null, null);
}
/**
@@ -336,6 +352,7 @@ public class GenericEncodingStrategy<S extends Storable> { * @param assembler code assembler to receive bytecode instructions
* @param properties specific properties to decode, defaults to all
* properties if null
+ * @param options optional encoding options
* @param encodedVar required variable, which must be a byte array. At
* runtime, it references encoded data.
* @throws SupportException if any property type is not supported
@@ -344,12 +361,13 @@ public class GenericEncodingStrategy<S extends Storable> { */
public void buildSerialDecoding(CodeAssembler assembler,
StorableProperty<S>[] properties,
+ EnumSet<Option> options,
LocalVariable encodedVar)
throws SupportException
{
properties = ensureAllProperties(properties);
buildDecoding
- (Mode.SERIAL, assembler, properties, null, null, null, false, -1, null, encodedVar);
+ (Mode.SERIAL, assembler, properties, null, null, null, options, -1, null, encodedVar);
}
/**
@@ -618,7 +636,7 @@ public class GenericEncodingStrategy<S extends Storable> { Direction[] directions,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
- boolean useReadMethods,
+ EnumSet<Option> options,
int generation,
LocalVariable partialStartVar,
LocalVariable partialEndVar)
@@ -697,7 +715,7 @@ public class GenericEncodingStrategy<S extends Storable> { // property is optional, then a byte prefix is needed to
// identify a null reference.
- loadPropertyValue(a, info, 0, useReadMethods,
+ loadPropertyValue(a, info, 0, options,
instanceVar, adapterInstanceClass, partialStartVar);
boolean descending = mode == Mode.KEY
@@ -785,7 +803,10 @@ public class GenericEncodingStrategy<S extends Storable> { hasVariableLength = true;
}
- if (info.getPropertyType() == info.getStorageType()) {
+ if (info.getPropertyType() == info.getStorageType() &&
+ // BigDecimal is adapted in this method, to strip trailing zeros.
+ info.getPropertyType() != TypeDesc.forClass(BigDecimal.class))
+ {
// Property won't be adapted, so loading it twice is no big deal.
continue;
}
@@ -940,7 +961,7 @@ public class GenericEncodingStrategy<S extends Storable> { } else {
// Load property to test for null.
loadPropertyValue(stashedProperties, stashedFromInstances,
- a, info, i, useReadMethods,
+ a, info, i, options,
instanceVar, adapterInstanceClass, partialStartVar);
Label isNull = a.createLabel();
@@ -972,7 +993,7 @@ public class GenericEncodingStrategy<S extends Storable> { propType.toClass() == BigDecimal.class)
{
loadPropertyValue(stashedProperties, stashedFromInstances,
- a, info, i, useReadMethods,
+ a, info, i, options,
instanceVar, adapterInstanceClass, partialStartVar);
String methodName;
@@ -1158,7 +1179,7 @@ public class GenericEncodingStrategy<S extends Storable> { boolean fromInstance = loadPropertyValue
(stashedProperties, stashedFromInstances,
- a, info, i, useReadMethods,
+ a, info, i, options,
instanceVar, adapterInstanceClass, partialStartVar);
TypeDesc propType = info.getStorageType();
@@ -1258,8 +1279,7 @@ public class GenericEncodingStrategy<S extends Storable> { * @param info info for property to load
* @param ordinal zero-based property ordinal, used only if instanceVar
* refers to an object array.
- * @param useReadMethod when true, access property by public read method
- * instead of protected field
+ * @param options optional encoding options
* @param instanceVar local variable referencing Storable instance,
* defaults to "this" if null. If variable type is an Object array, then
* property values are read from the runtime value of this array instead
@@ -1277,7 +1297,7 @@ public class GenericEncodingStrategy<S extends Storable> { Boolean[] stashedFromInstances,
CodeAssembler a,
StorablePropertyInfo info, int ordinal,
- boolean useReadMethod,
+ EnumSet<Option> options,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
LocalVariable partialStartVar)
@@ -1288,7 +1308,7 @@ public class GenericEncodingStrategy<S extends Storable> { }
boolean fromInstance = loadPropertyValue
- (a, info, ordinal, useReadMethod, instanceVar, adapterInstanceClass, partialStartVar);
+ (a, info, ordinal, options, instanceVar, adapterInstanceClass, partialStartVar);
if (stashedProperties != null) {
LocalVariable propVar = stashedProperties[ordinal];
@@ -1309,8 +1329,7 @@ public class GenericEncodingStrategy<S extends Storable> { * @param info info for property to load
* @param ordinal zero-based property ordinal, used only if instanceVar
* refers to an object array.
- * @param useReadMethod when true, access property by public read method
- * instead of protected field
+ * @param options optional encoding options
* @param instanceVar local variable referencing Storable instance,
* defaults to "this" if null. If variable type is an Object array, then
* property values are read from the runtime value of this array instead
@@ -1326,7 +1345,7 @@ public class GenericEncodingStrategy<S extends Storable> { */
protected boolean loadPropertyValue(CodeAssembler a,
StorablePropertyInfo info, int ordinal,
- boolean useReadMethod,
+ EnumSet<Option> options,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
LocalVariable partialStartVar)
@@ -1337,9 +1356,11 @@ public class GenericEncodingStrategy<S extends Storable> { final boolean isObjectArrayInstanceVar = instanceVar != null
&& instanceVar.getType() == TypeDesc.forClass(Object[].class);
+ final boolean useMethod = options != null && options.contains(Option.USE_METHODS);
+
final boolean useAdapterInstance = adapterInstanceClass != null
&& info.getToStorageAdapter() != null
- && (useReadMethod || isObjectArrayInstanceVar);
+ && (useMethod || isObjectArrayInstanceVar);
if (useAdapterInstance) {
// Push adapter instance to stack to be used later.
@@ -1352,7 +1373,7 @@ public class GenericEncodingStrategy<S extends Storable> { if (instanceVar == null) {
a.loadThis();
- if (useReadMethod) {
+ if (useMethod) {
info.addInvokeReadMethod(a);
} else {
// Access property value directly from protected field of "this".
@@ -1365,7 +1386,7 @@ public class GenericEncodingStrategy<S extends Storable> { }
} else if (!isObjectArrayInstanceVar) {
a.loadLocal(instanceVar);
- if (useReadMethod) {
+ if (useMethod) {
info.addInvokeReadMethod(a, instanceVar.getType());
} else {
// Access property value directly from protected field of
@@ -1399,6 +1420,18 @@ public class GenericEncodingStrategy<S extends Storable> { if (useAdapterInstance) {
// Invoke adapter method on instance pushed earlier.
a.invoke(info.getToStorageAdapter());
+ } else {
+ if (options != null && options.contains(Option.NORMALIZE)) {
+ TypeDesc bdType = TypeDesc.forClass(BigDecimal.class);
+ if (type == bdType) {
+ // Normalize by stripping trailing zeros.
+ a.dup();
+ Label isNull = a.createLabel();
+ a.ifNullBranch(isNull, true);
+ a.invokeVirtual(bdType, "stripTrailingZeros", bdType, null);
+ isNull.setLocation();
+ }
+ }
}
return !isObjectArrayInstanceVar;
@@ -1798,7 +1831,7 @@ public class GenericEncodingStrategy<S extends Storable> { Direction[] directions,
LocalVariable instanceVar,
Class<?> adapterInstanceClass,
- boolean useWriteMethods,
+ EnumSet<Option> options,
int generation,
Label altGenerationHandler,
LocalVariable encodedVar)
@@ -1903,7 +1936,7 @@ public class GenericEncodingStrategy<S extends Storable> { // Just store raw property value.
}
- storePropertyValue(a, info, useWriteMethods, instanceVar, adapterInstanceClass);
+ storePropertyValue(a, info, options, instanceVar, adapterInstanceClass);
return;
}
}
@@ -2117,7 +2150,7 @@ public class GenericEncodingStrategy<S extends Storable> { storePropertyLocation.setLocation();
- storePropertyValue(a, info, useWriteMethods, instanceVar, adapterInstanceClass);
+ storePropertyValue(a, info, options, instanceVar, adapterInstanceClass);
nextPropertyLocation.setLocation();
}
@@ -2337,8 +2370,7 @@ public class GenericEncodingStrategy<S extends Storable> { * array must also be on the operand stack.
*
* @param info info for property to store to
- * @param useWriteMethod when true, set property by public write method
- * instead of protected field
+ * @param options optional encoding options
* @param instanceVar local variable referencing Storable instance,
* defaults to "this" if null. If variable type is an Object array, then
* property values are written to the runtime value of this array instead
@@ -2348,7 +2380,7 @@ public class GenericEncodingStrategy<S extends Storable> { * @see #pushDecodingInstanceVar pushDecodingInstanceVar
*/
protected void storePropertyValue(CodeAssembler a, StorablePropertyInfo info,
- boolean useWriteMethod,
+ EnumSet<Option> options,
LocalVariable instanceVar,
Class<?> adapterInstanceClass) {
TypeDesc type = info.getPropertyType();
@@ -2357,9 +2389,11 @@ public class GenericEncodingStrategy<S extends Storable> { boolean isObjectArrayInstanceVar = instanceVar != null
&& instanceVar.getType() == TypeDesc.forClass(Object[].class);
+ final boolean useMethod = options != null && options.contains(Option.USE_METHODS);
+
boolean useAdapterInstance = adapterInstanceClass != null
&& info.getToStorageAdapter() != null
- && (useWriteMethod || isObjectArrayInstanceVar);
+ && (useMethod || isObjectArrayInstanceVar);
if (useAdapterInstance) {
// Push adapter instance to adapt property value. It must be on the
@@ -2382,7 +2416,7 @@ public class GenericEncodingStrategy<S extends Storable> { }
if (instanceVar == null) {
- if (useWriteMethod) {
+ if (useMethod) {
info.addInvokeWriteMethod(a);
} else {
// Set property value directly to protected field of instance.
@@ -2465,7 +2499,7 @@ public class GenericEncodingStrategy<S extends Storable> { return;
}
- if (useWriteMethod) {
+ if (useMethod) {
info.addInvokeWriteMethod(a, instanceVarType);
} else {
// Set property value directly to protected field of referenced
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java index dd43515..3a642e4 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java @@ -21,6 +21,7 @@ package com.amazon.carbonado.raw; import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
+import java.util.EnumSet;
import java.util.Map;
import org.cojen.classfile.ClassFile;
@@ -55,6 +56,8 @@ import com.amazon.carbonado.gen.CodeBuilderUtil; import com.amazon.carbonado.util.ThrowUnchecked;
import com.amazon.carbonado.util.QuickConstructorGenerator;
+import static com.amazon.carbonado.raw.GenericEncodingStrategy.Option;
+
/**
* Generic codec that supports any kind of storable by auto-generating and
* caching storable implementations.
@@ -197,15 +200,17 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S // TODO: Consider caching generated key. Rebuild if null or if pk is dirty.
+ EnumSet<Option> options = EnumSet.of(Option.NORMALIZE);
+
// assembler = b
// properties = null (defaults to all key properties)
// instanceVar = null (null means "this")
// adapterInstanceClass = null (null means use instanceVar, in this case is "this")
- // useReadMethods = false (will read fields directly)
+ // options = options
// partialStartVar = null (only support encoding all properties)
// partialEndVar = null (only support encoding all properties)
LocalVariable encodedVar =
- encodingStrategy.buildKeyEncoding(b, null, null, null, false, null, null);
+ encodingStrategy.buildKeyEncoding(b, null, null, null, options, null, null);
b.loadLocal(encodedVar);
b.returnValue(byteArrayType);
@@ -219,14 +224,16 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S byteArrayType, null);
CodeBuilder b = new CodeBuilder(mi);
+ EnumSet<Option> options = EnumSet.of(Option.NORMALIZE);
+
// assembler = b
// properties = null (defaults to all non-key properties)
// instanceVar = null (null means "this")
// adapterInstanceClass = null (null means use instanceVar, in this case is "this")
- // useReadMethods = false (will read fields directly)
+ // options = options
// generation = generation
LocalVariable encodedVar =
- encodingStrategy.buildDataEncoding(b, null, null, null, false, generation);
+ encodingStrategy.buildDataEncoding(b, null, null, null, options, generation);
b.loadLocal(encodedVar);
b.returnValue(byteArrayType);
@@ -243,9 +250,9 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S // properties = null (defaults to all key properties)
// instanceVar = null (null means "this")
// adapterInstanceClass = null (null means use instanceVar, in this case is "this")
- // useWriteMethods = false (will set fields directly)
+ // options = null (will set fields directly)
// encodedVar = references byte array with encoded key
- encodingStrategy.buildKeyDecoding(b, null, null, null, false, b.getParameter(0));
+ encodingStrategy.buildKeyDecoding(b, null, null, null, null, b.getParameter(0));
b.returnVoid();
}
@@ -262,12 +269,12 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S // properties = null (defaults to all non-key properties)
// instanceVar = null (null means "this")
// adapterInstanceClass = null (null means use instanceVar, in this case is "this")
- // useWriteMethods = false (will set fields directly)
+ // options = null (will set fields directly)
// generation = generation
// altGenerationHandler = altGenerationHandler
// encodedVar = references byte array with encoded data
encodingStrategy.buildDataDecoding
- (b, null, null, null, false, generation, altGenerationHandler, b.getParameter(0));
+ (b, null, null, null, null, generation, altGenerationHandler, b.getParameter(0));
b.returnVoid();
@@ -584,15 +591,17 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S LocalVariable instanceVar = b.createLocalVariable(null, instanceType);
b.storeLocal(instanceVar);
+ EnumSet<Option> options = EnumSet.of(Option.NORMALIZE);
+
// assembler = b
// properties = properties to encode
// instanceVar = instanceVar which references storable instance
// adapterInstanceClass = null (null means use instanceVar)
- // useReadMethods = false (will read fields directly)
+ // options = options
// partialStartVar = null (only support encoding all properties)
// partialEndVar = null (only support encoding all properties)
LocalVariable encodedVar = mEncodingStrategy.buildKeyEncoding
- (b, properties, instanceVar, null, false, null, null);
+ (b, properties, instanceVar, null, options, null, null);
b.loadLocal(encodedVar);
b.returnValue(byteArrayType);
@@ -613,15 +622,17 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S LocalVariable instanceVar = b.createLocalVariable(null, instanceType);
b.storeLocal(instanceVar);
+ EnumSet<Option> options = EnumSet.of(Option.NORMALIZE);
+
// assembler = b
// properties = properties to encode
// instanceVar = instanceVar which references storable instance
// adapterInstanceClass = null (null means use instanceVar)
- // useReadMethods = false (will read fields directly)
+ // options = options
// partialStartVar = int parameter 1, references start property index
// partialEndVar = int parameter 2, references end property index
LocalVariable encodedVar = mEncodingStrategy.buildKeyEncoding
- (b, properties, instanceVar, null, false, b.getParameter(1), b.getParameter(2));
+ (b, properties, instanceVar, null, options, b.getParameter(1), b.getParameter(2));
b.loadLocal(encodedVar);
b.returnValue(byteArrayType);
@@ -645,15 +656,17 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S new TypeDesc[] {objectArrayType});
CodeBuilder b = new CodeBuilder(mi);
+ EnumSet<Option> options = EnumSet.of(Option.NORMALIZE);
+
// assembler = b
// properties = properties to encode
// instanceVar = parameter 0, an object array
// adapterInstanceClass = adapterInstanceClass - see comment above
- // useReadMethods = false (will read fields directly)
+ // options = options
// partialStartVar = null (only support encoding all properties)
// partialEndVar = null (only support encoding all properties)
LocalVariable encodedVar = mEncodingStrategy.buildKeyEncoding
- (b, properties, b.getParameter(0), adapterInstanceClass, false, null, null);
+ (b, properties, b.getParameter(0), adapterInstanceClass, options, null, null);
b.loadLocal(encodedVar);
b.returnValue(byteArrayType);
@@ -670,16 +683,18 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S new TypeDesc[] {objectArrayType, TypeDesc.INT, TypeDesc.INT});
CodeBuilder b = new CodeBuilder(mi);
+ EnumSet<Option> options = EnumSet.of(Option.NORMALIZE);
+
// assembler = b
// properties = properties to encode
// instanceVar = parameter 0, an object array
// adapterInstanceClass = adapterInstanceClass - see comment above
- // useReadMethods = false (will read fields directly)
+ // options = options
// partialStartVar = int parameter 1, references start property index
// partialEndVar = int parameter 2, references end property index
LocalVariable encodedVar = mEncodingStrategy.buildKeyEncoding
(b, properties, b.getParameter(0), adapterInstanceClass,
- false, b.getParameter(1), b.getParameter(2));
+ options, b.getParameter(1), b.getParameter(2));
b.loadLocal(encodedVar);
b.returnValue(byteArrayType);
@@ -715,11 +730,11 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S // properties = no parameters - we just want the key prefix
// instanceVar = null (no parameters means we don't need this)
// adapterInstanceClass = null (no parameters means we don't need this)
- // useReadMethods = false (no parameters means we don't need this)
+ // options = null (no parameters means we don't need this)
// partialStartVar = null (no parameters means we don't need this)
// partialEndVar = null (no parameters means we don't need this)
LocalVariable encodedVar = mEncodingStrategy.buildKeyEncoding
- (b, new OrderedProperty[0], null, null, false, null, null);
+ (b, new OrderedProperty[0], null, null, null, null, null);
b.loadLocal(encodedVar);
b.storeStaticField(BLANK_KEY_FIELD_NAME, byteArrayType);
@@ -783,13 +798,13 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S // properties = null (defaults to all non-key properties)
// instanceVar = "dest" storable
// adapterInstanceClass = null (null means use instanceVar, in this case is "dest")
- // useWriteMethods = false (will set fields directly)
+ // options = null (will set fields directly)
// generation = generation
// altGenerationHandler = null (generation should match)
// encodedVar = "data" byte array
try {
altStrategy.buildDataDecoding
- (b, null, destVar, null, false, generation, null, dataVar);
+ (b, null, destVar, null, null, generation, null, dataVar);
} catch (SupportException e) {
throw new CorruptEncodingException(e);
}
|