@Override public void write(TensorModifyUpdate update) { putByte(null, (byte) update.getOperation().id); update.getValue().serialize(this); }
public TensorModifyUpdate(Operation operation, TensorFieldValue tensor) { super(ValueUpdateClassID.TENSORMODIFY); this.operation = operation; this.tensor = tensor; verifyCompatibleType(tensor.getDataType().getTensorType()); }
@Override protected ValueUpdate readTensorModifyUpdate(DataType type) { byte operationId = getByte(null); TensorModifyUpdate.Operation operation = TensorModifyUpdate.Operation.getOperation(operationId); if (operation == null) { throw new DeserializationException("Unknown operation id " + operationId + " for tensor modify update"); } if (!(type instanceof TensorDataType)) { throw new DeserializationException("Expected tensor data type, got " + type); } TensorDataType tensorDataType = (TensorDataType)type; TensorFieldValue tensor = new TensorFieldValue(TensorModifyUpdate.convertToCompatibleType(tensorDataType.getTensorType())); tensor.deserialize(this); return new TensorModifyUpdate(operation, tensor); } }
public static TensorModifyUpdate createModifyUpdate(TokenBuffer buffer, Field field) { expectFieldIsOfTypeTensor(field); expectTensorTypeHasNoneIndexedUnboundDimensions(field); expectTensorTypeIsNotMixed(field); expectObjectStart(buffer.currentToken()); ModifyUpdateResult result = createModifyUpdateResult(buffer, field); expectOperationSpecified(result.operation, field.getName()); expectTensorSpecified(result.tensor, field.getName()); return new TensorModifyUpdate(result.operation, result.tensor); }
private static ModifyUpdateResult createModifyUpdateResult(TokenBuffer buffer, Field field) { ModifyUpdateResult result = new ModifyUpdateResult(); TensorDataType tensorDataType = (TensorDataType)field.getDataType(); TensorType convertedType = TensorModifyUpdate.convertToCompatibleType(tensorDataType.getTensorType()); buffer.next(); int localNesting = buffer.nesting(); while (localNesting <= buffer.nesting()) { switch (buffer.currentName()) { case MODIFY_OPERATION: result.operation = createOperation(buffer, field.getName()); break; case TENSOR_CELLS: result.tensor = createTensor(buffer, convertedType); break; default: throw new IllegalArgumentException("Unknown JSON string '" + buffer.currentName() + "' in modify update for field '" + field.getName() + "'"); } buffer.next(); } return result; }