@SuppressWarnings("unchecked") public static <T> T decode(Class<T> clazz, Splittable split) { if (split == null || split == Splittable.NULL) { return null; } return (T) getTypeOrDie(clazz).decode(clazz, split); }
/** * Encode a value object when the wire format type is known. This method * should be preferred over {@link #encode(Object)} when possible. */ public static Splittable encode(Class<?> clazz, Object obj) { if (obj == null) { return Splittable.NULL; } return getTypeOrDie(clazz).encode(obj); }
/** * Return a JSON object literal with the contents of the store. */ public String encode() { // Backwards-compat: never store a '0' (see constructor) assert nextId >= 0; messageBean.as().setSyntheticId(nextId + 1); return AutoBeanCodex.encode(messageBean).getPayload(); }
public BaseProxy getOriginalProxy() { AutoBean<? extends BaseProxy> parent = AutoBeanUtils.getAutoBean(v.getRootBean()).getTag(Constants.PARENT_OBJECT); return parent == null ? null : parent.as(); }
/** * EntityCodex support. */ public <Q extends BaseProxy> AutoBean<Q> getBeanForPayload(Splittable serializedProxyId) { IdMessage ref = AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, IdMessage.class, serializedProxyId).as(); @SuppressWarnings("unchecked") SimpleProxyId<Q> id = (SimpleProxyId<Q>) getId(ref); return getProxyForReturnPayloadGraph(id); }
protected <W> W getFromWrapper(W obj) { // Some versions of javac have problem inferring the generics here return AutoBeanUtils.<W, W> getAutoBean(obj).as(); }
public void clear() { for (String key : data.getPropertyKeys()) { Splittable.NULL.assign(data, key); reified.setReified(key, null); } }
/** * Returns the uninitialized field value for the given primitive type. */ public static Object getUninitializedFieldValue(Class<?> clazz) { Type type = getTypeOrDie(clazz); if (clazz.equals(type.getPrimitiveType())) { return type.getDefaultValue(); } return null; }
/** * Make an EntityProxy immutable. */ private void makeImmutable(final AutoBean<? extends BaseProxy> toMutate) { // Always diff'ed against itself, producing a no-op toMutate.setTag(Constants.PARENT_OBJECT, toMutate); // Act with entity-identity semantics toMutate.setTag(REQUEST_CONTEXT_STATE, null); toMutate.setFrozen(true); }
/** * Returns true if ValueCodex can operate on values of the given type. * * @param clazz a Class object * @return {@code true} if the given object type can be decoded */ public static boolean canDecode(Class<?> clazz) { if (findType(clazz) != null) { return true; } // Use other platform-specific tests return ValueCodexHelper.canDecode(clazz); }
public Object decode(EncodeState state, Splittable propertyValue) { if (propertyValue == null || propertyValue == Splittable.NULL) { return ValueCodex.getUninitializedFieldValue(type); } return ValueCodex.decode(type, propertyValue); }
/** * Effectively overrides {@link BaseProxyCategory#stableId(AutoBean)} to * return a narrower bound. */ public static <T extends EntityProxy> SimpleEntityProxyId<T> stableId( AutoBean<? extends T> bean) { return bean.getTag(STABLE_ID); }
public void decodeInto(EncodeState state, Splittable data, AutoBean<?> bean) { this.data = data; this.state = state; bean.accept(this); }
/** * Called after visiting a reference property. * * @param propertyName the property name, as a String * @param value the property value * @param ctx a PropertyContext */ public void endVisitCollectionProperty(String propertyName, AutoBean<Collection<?>> value, CollectionPropertyContext ctx) { endVisitReferenceProperty(propertyName, value, ctx); }
/** * Called every time, but {@link #visit(AutoBean, Context)} will be called for * the value only the first time it is encountered. * * @param propertyName the property name, as a String * @param value the property value * @param ctx a PropertyContext */ public boolean visitMapProperty(String propertyName, AutoBean<Map<?, ?>> value, MapPropertyContext ctx) { return visitReferenceProperty(propertyName, value, ctx); }
public SplittableList(Splittable data, Coder elementCoder, EncodeState state) { assert data.isIndexed() : "Expecting indexed data"; this.data = data; this.elementCoder = elementCoder; this.state = state; }
@Override public Short decode(Class<?> clazz, Splittable value) { return (short) value.asNumber(); }
/** * Called after visiting a reference property. * * @param propertyName the property name, as a String * @param value the property value * @param ctx a PropertyContext */ public void endVisitMapProperty(String propertyName, AutoBean<Map<?, ?>> value, MapPropertyContext ctx) { endVisitReferenceProperty(propertyName, value, ctx); }
/** * Called every time, but {@link #visit(AutoBean, Context)} will be called for * the value only the first time it is encountered. * * @param propertyName the property name, as a String * @param value the property value * @param ctx a PropertyContext */ public boolean visitCollectionProperty(String propertyName, AutoBean<Collection<?>> value, CollectionPropertyContext ctx) { return visitReferenceProperty(propertyName, value, ctx); }