org.apache.plc4x.java.abeth.readwrite.io.DF1CommandRequestMessageIO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plc4j-driver-ab-eth Show documentation
Show all versions of plc4j-driver-ab-eth Show documentation
Implementation of a PLC4X driver able to speak using the Allen Bradley AB-ETH protocol.
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.plc4x.java.abeth.readwrite.io;
import org.apache.plc4x.java.abeth.readwrite.*;
import org.apache.plc4x.java.abeth.readwrite.io.*;
import org.apache.plc4x.java.abeth.readwrite.types.*;
import org.apache.plc4x.java.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Supplier;
public class DF1CommandRequestMessageIO {
private static final Logger LOGGER = LoggerFactory.getLogger(DF1CommandRequestMessageIO.class);
public static DF1CommandRequestMessageBuilder parse(ReadBuffer io) throws ParseException {
int startPos = io.getPos();
int curPos;
// Simple Field (command)
DF1RequestCommand command = DF1RequestCommandIO.parse(io);
// Create the instance
return new DF1CommandRequestMessageBuilder(command);
}
public static void serialize(WriteBuffer io, DF1CommandRequestMessage _value) throws ParseException {
// Simple Field (command)
DF1RequestCommand command = (DF1RequestCommand) _value.getCommand();
DF1RequestCommandIO.serialize(io, command);
}
private static int COUNT(Object obj) {
if(obj.getClass().isArray()) {
Object[] arr = (Object[]) obj;
return arr.length;
} else if(obj instanceof Collection) {
Collection col = (Collection) obj;
return col.size();
}
throw new RuntimeException("Unable to count object of type " + obj.getClass().getName());
}
private static T CAST(Object obj, Class clazz) {
try {
return clazz.cast(obj);
} catch(ClassCastException e) {
throw new RuntimeException("Unable to cast object of type " + obj.getClass().getName() + " to " + clazz.getName());
}
}
public static class DF1CommandRequestMessageBuilder implements DF1RequestMessageIO.DF1RequestMessageBuilder {
private final DF1RequestCommand command;
public DF1CommandRequestMessageBuilder(DF1RequestCommand command) {
this.command = command;
}
public DF1CommandRequestMessage build(short destinationAddress, short sourceAddress, short status, int transactionCounter) {
return new DF1CommandRequestMessage(destinationAddress, sourceAddress, status, transactionCounter, command);
}
}
}