use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method marshallVariablesContainer.
public static VariableContainer marshallVariablesContainer(MarshallerWriteContext context, Map<String, Object> variables) throws IOException {
AutomatikoMessages.VariableContainer.Builder vcbuilder = AutomatikoMessages.VariableContainer.newBuilder();
for (String key : variables.keySet()) {
AutomatikoMessages.Variable.Builder builder = AutomatikoMessages.Variable.newBuilder().setName(key);
if (variables.get(key) != null) {
ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(variables.get(key));
Integer index = context.getStrategyIndex(strategy);
builder.setStrategyIndex(index).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, variables.get(key))));
}
vcbuilder.addVariable(builder.build());
}
return vcbuilder.build();
}
use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.
the class PersisterHelper method writeStrategiesIndex.
public static void writeStrategiesIndex(MarshallerWriteContext context, AutomatikoMessages.Header.Builder _header) throws IOException {
for (Entry<ObjectMarshallingStrategy, Integer> entry : context.usedStrategies.entrySet()) {
Builder _strat = AutomatikoMessages.Header.StrategyIndex.newBuilder().setId(entry.getValue().intValue()).setName(entry.getKey().getName());
Context ctx = context.strategyContext.get(entry.getKey());
if (ctx != null) {
Output os = ByteString.newOutput();
ctx.write(new ObjectOutputStream(os));
_strat.setData(os.toByteString());
os.close();
}
_header.addStrategy(_strat.build());
}
}
use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method marshallVariablesMap.
public static Variable marshallVariablesMap(MarshallerWriteContext context, Map<String, Object> variables, boolean extractFiles) throws IOException {
Map<String, Variable> marshalledVariables = new HashMap<String, Variable>();
for (String key : variables.keySet()) {
AutomatikoMessages.Variable.Builder builder = AutomatikoMessages.Variable.newBuilder().setName(key);
Object variable = variables.get(key);
if (variable != null) {
ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(variable);
Integer index = context.getStrategyIndex(strategy);
builder.setStrategyIndex(index).setDataType(strategy.getType(variable.getClass())).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, variable)));
}
marshalledVariables.put(key, builder.build());
}
return marshallVariable(context, "variablesMap", marshalledVariables, extractFiles);
}
use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method marshallVariable.
public static Variable marshallVariable(MarshallerWriteContext context, String name, Object value, boolean extractFiles) throws IOException {
AutomatikoMessages.Variable.Builder builder = AutomatikoMessages.Variable.newBuilder().setName(name);
if (value != null) {
if (extractFiles && (boolean) context.env.getOrDefault("_export_", false)) {
if (value instanceof ByteArrayFile) {
ByteArrayFile file = ((ByteArrayFile) value);
value = new ByteArrayFile(file.name(), file.content(), file.attributes());
}
}
ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(value);
Integer index = context.getStrategyIndex(strategy);
builder.setStrategyIndex(index).setDataType(strategy.getType(value.getClass())).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, value)));
}
return builder.build();
}
use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method unmarshallVariableValue.
public static Object unmarshallVariableValue(MarshallerReaderContext context, AutomatikoMessages.Variable _variable) throws IOException, ClassNotFoundException {
if (_variable.getValue() == null || _variable.getValue().isEmpty()) {
return null;
}
ObjectMarshallingStrategy strategy = context.usedStrategies.get(_variable.getStrategyIndex());
Object value = strategy.unmarshal(_variable.getDataType(), context.strategyContexts.get(strategy), context, _variable.getValue().toByteArray(), null);
return value;
}
Aggregations