com.javonet.core.interpreter.Interpreter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javonet-java-sdk Show documentation
Show all versions of javonet-java-sdk Show documentation
Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology.
It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products.
Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today!
For more information check out our guides at https://www.javonet.com/guides/v2/
package com.javonet.core.interpreter;
import com.javonet.core.handler.Handler;
import com.javonet.core.protocol.CommandDeserializer;
import com.javonet.core.protocol.CommandSerializer;
import com.javonet.core.transmitter.Transmitter;
import com.javonet.utils.Command;
import com.javonet.utils.ConnectionType;
import com.javonet.utils.RuntimeName;
import com.javonet.utils.TcpConnectionData;
import com.javonet.core.receiver.Receiver;
public class Interpreter {
private final Handler handler = new Handler();
public Command execute(Command command, ConnectionType connectionType, TcpConnectionData tcpConnectionData) {
CommandSerializer commandSerializer = new CommandSerializer();
byte[] messageByteArray = commandSerializer.serialize(command, connectionType, tcpConnectionData);
byte[] response = new byte[]{};
if(command.getRuntimeName() == RuntimeName.Jvm && connectionType == ConnectionType.IN_MEMORY)
{
response = new Receiver().sendCommand(messageByteArray);
}
else
{
response = Transmitter.sendCommand(messageByteArray);
}
return new CommandDeserializer(response).deserialize();
}
public Command process(byte[] byteArray) {
Command receivedCommand = new CommandDeserializer(byteArray).deserialize();
return handler.handleCommand(receivedCommand);
}
}