├── NET ├── JNetProto.Sharp │ ├── Beans │ │ ├── ProtoSettings.cs │ │ └── ProtoConvert.cs │ ├── JNetProto.Sharp.csproj │ └── API │ │ ├── DataType.cs │ │ ├── IDataReader.cs │ │ └── IDataWriter.cs ├── JNetBase.Sharp │ ├── IO │ │ └── IRewindable.cs │ ├── Threads │ │ ├── IExecutor.cs │ │ ├── ThreadExecutor.cs │ │ └── SingleThread.cs │ ├── JNetBase.Sharp.csproj │ ├── Sys │ │ └── Arrays.cs │ └── Meta │ │ └── Reflect.cs ├── JNetCall.Sharp.Common │ ├── API │ │ ├── Enc │ │ │ ├── IByteEncoding.cs │ │ │ └── IEncoding.cs │ │ ├── Flow │ │ │ ├── ICall.cs │ │ │ ├── MethodResult.cs │ │ │ ├── MethodCall.cs │ │ │ └── MethodStatus.cs │ │ └── IO │ │ │ ├── IPullTransport.cs │ │ │ ├── IErrorable.cs │ │ │ ├── ISendTransport.cs │ │ │ └── IPushTransport.cs │ ├── Client │ │ ├── API │ │ │ └── IProxy.cs │ │ ├── Model │ │ │ ├── DelegateRef.cs │ │ │ └── CallState.cs │ │ └── Tools │ │ │ ├── ClientHelper.cs │ │ │ └── ServiceEnv.cs │ ├── Server │ │ ├── API │ │ │ └── IHosting.cs │ │ └── Model │ │ │ └── DelegateWrap.cs │ ├── JNetCall.Sharp.Common.csproj │ └── Impl │ │ ├── IO │ │ ├── Net │ │ │ ├── NetworkTools.cs │ │ │ └── UdpTransport.cs │ │ ├── StreamTransport.cs │ │ └── StreamTools.cs │ │ ├── Enc │ │ └── BinaryEncoding.cs │ │ └── Util │ │ └── ClassTools.cs ├── JNetCall.Sharp.StdIO │ ├── Common │ │ ├── StreamInit.cs │ │ └── ByteMarks.cs │ ├── JNetCall.Sharp.StdIO.csproj │ ├── Client │ │ └── StdIOClient.cs │ └── Server │ │ └── ServiceHosts.cs ├── Aliens.Sharp │ ├── Aliens.Sharp.csproj │ └── API │ │ ├── IStringCache.cs │ │ ├── ICalculator.cs │ │ ├── ISimultaneous.cs │ │ ├── ITriggering.cs │ │ ├── IDataTyped.cs │ │ └── IMultiple.cs ├── JNetCall.Sharp.Tests │ ├── IO │ │ ├── TestedService.cs │ │ ├── MemTransportTest.cs │ │ ├── TcpTransportTest.cs │ │ ├── UdpTransportTest.cs │ │ ├── FileTransportTest.cs │ │ └── TransportTest.cs │ ├── MainCallTest.cs │ ├── NativeCallTest.cs │ └── JNetCall.Sharp.Tests.csproj ├── JNetHotel.Sharp │ ├── Data │ │ ├── JvmOption.cs │ │ ├── JniResult.cs │ │ └── JvmInitArgs.cs │ ├── Interop │ │ ├── JNINativeInterfacePtr.cs │ │ ├── JNIInvokeInterfacePtr.cs │ │ ├── JValue.cs │ │ ├── JNIInvokeInterface.cs │ │ ├── JNINativeMethod.cs │ │ └── JNIInvokeInterface_.cs │ ├── JNetHotel.Sharp.csproj │ ├── API │ │ └── IVmRef.cs │ ├── Natives.cs │ ├── Mac │ │ └── MacVmRef.cs │ ├── Windows │ │ └── WinVmRef.cs │ ├── BSD │ │ └── BsdVmRef.cs │ └── Linux │ │ └── LinuxVmRef.cs ├── Alien1.Sharp │ ├── Program.cs │ └── Alien1.Sharp.csproj ├── Alien0.Sharp │ └── Alien0.Sharp.csproj ├── JNetCall.Sharp.InProc │ ├── API │ │ └── ICaller.cs │ ├── Client │ │ ├── InProcClient.cs │ │ └── JvmContainer.cs │ ├── JNetCall.Sharp.InProc.csproj │ ├── Tools │ │ └── Interop.cs │ └── Server │ │ ├── ServiceLots.cs │ │ └── ServiceLot.cs ├── Alienator.Sharp │ ├── Alienator.Sharp.csproj │ └── Program.cs ├── Alien2.Sharp │ ├── Alien2.Sharp.csproj │ └── Boot.cs └── JNetProto.Sharp.Tests │ ├── JNetProto.Sharp.Tests.csproj │ └── EnumTest.cs ├── JVM ├── jnetproto-java │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── jnetproto │ │ │ └── java │ │ │ ├── beans │ │ │ └── ProtoSettings.java │ │ │ ├── api │ │ │ ├── DataType.java │ │ │ ├── IDataReader.java │ │ │ └── IDataWriter.java │ │ │ └── tools │ │ │ └── Tuples.java │ └── pom.xml ├── javaenums │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── xafero │ │ │ └── javaenums │ │ │ ├── api │ │ │ ├── IFlag.java │ │ │ └── IEnum.java │ │ │ ├── units │ │ │ ├── ByteEnum.java │ │ │ ├── IntEnum.java │ │ │ ├── LongEnum.java │ │ │ └── ShortEnum.java │ │ │ ├── flags │ │ │ ├── ByteFlag.java │ │ │ ├── IntFlag.java │ │ │ ├── LongFlag.java │ │ │ └── ShortFlag.java │ │ │ └── bits │ │ │ ├── BitFlag32.java │ │ │ ├── BitFlag8.java │ │ │ ├── BitFlag64.java │ │ │ └── BitFlag16.java │ └── pom.xml ├── jnetcall-java-common │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── jnetcall │ │ │ └── java │ │ │ ├── api │ │ │ ├── flow │ │ │ │ ├── ICall.java │ │ │ │ ├── MethodResult.java │ │ │ │ ├── MethodCall.java │ │ │ │ └── MethodStatus.java │ │ │ ├── enc │ │ │ │ ├── IByteEncoding.java │ │ │ │ └── IEncoding.java │ │ │ └── io │ │ │ │ ├── ISendTransport.java │ │ │ │ ├── IPullTransport.java │ │ │ │ └── IPushTransport.java │ │ │ ├── client │ │ │ ├── model │ │ │ │ ├── DelegateRef.java │ │ │ │ └── CallState.java │ │ │ ├── api │ │ │ │ └── IProxy.java │ │ │ └── tools │ │ │ │ ├── ClientHelper.java │ │ │ │ └── ServiceEnv.java │ │ │ ├── server │ │ │ ├── api │ │ │ │ └── IHosting.java │ │ │ └── model │ │ │ │ └── DelegateWrap.java │ │ │ └── impl │ │ │ ├── io │ │ │ ├── StreamTools.java │ │ │ ├── net │ │ │ │ ├── NetworkTools.java │ │ │ │ └── UdpTransport.java │ │ │ └── StreamTransport.java │ │ │ ├── util │ │ │ └── ClassTools.java │ │ │ └── enc │ │ │ └── BinaryEncoding.java │ └── pom.xml ├── jnetbase-java │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── jnetbase │ │ │ └── java │ │ │ ├── io │ │ │ ├── IRewindable.java │ │ │ ├── ByteArrayStream.java │ │ │ └── MemPipeStream.java │ │ │ ├── meta │ │ │ ├── Property.java │ │ │ └── TypeToken.java │ │ │ ├── threads │ │ │ ├── IExecutor.java │ │ │ ├── FuncTimerTask.java │ │ │ ├── ThreadExecutor.java │ │ │ ├── ManualResetEvent.java │ │ │ └── SingleThread.java │ │ │ └── sys │ │ │ ├── Primitives.java │ │ │ ├── Strings.java │ │ │ ├── ArrayX.java │ │ │ └── BitConverter.java │ └── pom.xml ├── jnethotel-java │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── jnethotel │ │ │ └── java │ │ │ ├── interop │ │ │ ├── api │ │ │ │ ├── hostfxr_error_writer_fn.java │ │ │ │ ├── component_entry_point_fn.java │ │ │ │ ├── nethost_library.java │ │ │ │ ├── hostfxr_get_runtime_property_value_fn.java │ │ │ │ ├── load_assembly_and_get_function_pointer_fn.java │ │ │ │ ├── hostfxr_delegate_type.java │ │ │ │ ├── hostfxr_initialize_parameters.java │ │ │ │ ├── get_hostfxr_parameters.java │ │ │ │ └── hostfxr_library.java │ │ │ └── VmHelper.java │ │ │ ├── api │ │ │ ├── IVmRef.java │ │ │ └── ICoreClr.java │ │ │ ├── linux │ │ │ ├── impl │ │ │ │ ├── get_hostfxr_parameters_unix.java │ │ │ │ ├── component_entry_point_fn_unix.java │ │ │ │ ├── hostfxr_error_writer_fn_unix.java │ │ │ │ ├── nethost_library_unix.java │ │ │ │ ├── hostfxr_library_unix.java │ │ │ │ ├── hostfxr_get_runtime_property_value_fn_unix.java │ │ │ │ ├── load_assembly_and_get_function_pointer_fn_unix.java │ │ │ │ └── hostfxr_initialize_parameters_unix.java │ │ │ ├── LinuxCoreClr.java │ │ │ └── LinuxVmRef.java │ │ │ ├── windows │ │ │ ├── impl │ │ │ │ ├── get_hostfxr_parameters_windows.java │ │ │ │ ├── component_entry_point_fn_windows.java │ │ │ │ ├── nethost_library_windows.java │ │ │ │ ├── hostfxr_error_writer_fn_windows.java │ │ │ │ ├── hostfxr_library_windows.java │ │ │ │ ├── hostfxr_get_runtime_property_value_fn_windows.java │ │ │ │ ├── load_assembly_and_get_function_pointer_fn_windows.java │ │ │ │ └── hostfxr_initialize_parameters_windows.java │ │ │ ├── WinCoreClr.java │ │ │ └── WinVmRef.java │ │ │ ├── Natives.java │ │ │ ├── bsd │ │ │ ├── BsdCoreClr.java │ │ │ └── BsdVmRef.java │ │ │ ├── mac │ │ │ ├── MacVmRef.java │ │ │ └── MacCoreClr.java │ │ │ └── Clr.java │ └── pom.xml ├── jnetcall-java-inproc │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── jnetcall │ │ │ └── java │ │ │ ├── api │ │ │ └── ICaller.java │ │ │ ├── client │ │ │ ├── InProcClient.java │ │ │ └── ClrContainer.java │ │ │ └── server │ │ │ ├── ServiceLots.java │ │ │ └── ServiceLot.java │ └── pom.xml ├── jnetcall-java-tests │ └── src │ │ └── test │ │ └── java │ │ └── jnetcall │ │ └── java │ │ └── tests │ │ ├── io │ │ ├── TestedService.java │ │ ├── MemTransportTest.java │ │ ├── TcpTransportTest.java │ │ ├── UdpTransportTest.java │ │ ├── FileTransportTest.java │ │ └── TransportTest.java │ │ ├── MainCallTest.java │ │ └── NativeCallTest.java ├── jnetcall-java-stdio │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── jnetcall │ │ │ └── java │ │ │ ├── common │ │ │ ├── StreamInit.java │ │ │ └── ByteMarks.java │ │ │ ├── client │ │ │ ├── StdIOClient.java │ │ │ └── ExeTransport.java │ │ │ └── server │ │ │ └── ServiceHosts.java │ └── pom.xml ├── aliens-java │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── example │ │ │ └── api │ │ │ ├── ICalculator.java │ │ │ ├── IStringCache.java │ │ │ ├── ISimultaneous.java │ │ │ ├── ITriggering.java │ │ │ ├── IDataTyped.java │ │ │ └── IMultiple.java │ └── pom.xml ├── alien1-java │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── example │ │ │ └── Main.java │ └── pom.xml ├── alien2-java │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── x │ │ │ └── Boot.java │ └── pom.xml ├── alien0-java │ └── pom.xml ├── pom.xml └── alienator-java │ ├── src │ └── main │ │ └── java │ │ └── org │ │ └── example │ │ └── Main.java │ └── pom.xml └── README.md /NET/JNetProto.Sharp/Beans/ProtoSettings.cs: -------------------------------------------------------------------------------- 1 | namespace JNetProto.Sharp.Beans 2 | { 3 | public sealed class ProtoSettings 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /JVM/jnetproto-java/src/main/java/jnetproto/java/beans/ProtoSettings.java: -------------------------------------------------------------------------------- 1 | package jnetproto.java.beans; 2 | 3 | public final class ProtoSettings { 4 | } 5 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/api/IFlag.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.api; 2 | 3 | public interface IFlag extends IEnum { 4 | } 5 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/api/IEnum.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.api; 2 | 3 | public interface IEnum { 4 | 5 | T asNumber(); 6 | } 7 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/flow/ICall.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.flow; 2 | 3 | public interface ICall { 4 | 5 | short I(); 6 | } 7 | -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/IO/IRewindable.cs: -------------------------------------------------------------------------------- 1 | namespace JNetBase.Sharp.IO 2 | { 3 | public interface IRewindable 4 | { 5 | void Rewind(int size); 6 | } 7 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/io/IRewindable.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.io; 2 | 3 | public interface IRewindable { 4 | 5 | void rewind(int size); 6 | } 7 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/Enc/IByteEncoding.cs: -------------------------------------------------------------------------------- 1 | namespace JNetCall.Sharp.API.Enc 2 | { 3 | public interface IByteEncoding : IEncoding 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/Flow/ICall.cs: -------------------------------------------------------------------------------- 1 | namespace JNetCall.Sharp.API.Flow 2 | { 3 | public interface ICall 4 | { 5 | short I { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/enc/IByteEncoding.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.enc; 2 | 3 | public interface IByteEncoding extends IEncoding { 4 | } 5 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/Flow/MethodResult.cs: -------------------------------------------------------------------------------- 1 | namespace JNetCall.Sharp.API.Flow 2 | { 3 | public readonly record struct MethodResult(short I, object R, short S) 4 | : ICall; 5 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/IO/IPullTransport.cs: -------------------------------------------------------------------------------- 1 | namespace JNetCall.Sharp.API.IO 2 | { 3 | public interface IPullTransport : ISendTransport 4 | { 5 | T Pull(); 6 | } 7 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/Flow/MethodCall.cs: -------------------------------------------------------------------------------- 1 | namespace JNetCall.Sharp.API.Flow 2 | { 3 | public readonly record struct MethodCall(short I, string C, string M, object[] A) 4 | : ICall; 5 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/meta/Property.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.meta; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public record Property(String Name, Method Get, Method Set) { 6 | } 7 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/flow/MethodResult.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.flow; 2 | 3 | public record MethodResult(short I, Object R, short S) 4 | implements ICall { 5 | } 6 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/units/ByteEnum.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.units; 2 | 3 | import com.xafero.javaenums.api.IEnum; 4 | 5 | public interface ByteEnum extends IEnum { 6 | } 7 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/units/IntEnum.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.units; 2 | 3 | import com.xafero.javaenums.api.IEnum; 4 | 5 | public interface IntEnum extends IEnum { 6 | } 7 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/units/LongEnum.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.units; 2 | 3 | import com.xafero.javaenums.api.IEnum; 4 | 5 | public interface LongEnum extends IEnum { 6 | } 7 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/units/ShortEnum.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.units; 2 | 3 | import com.xafero.javaenums.api.IEnum; 4 | 5 | public interface ShortEnum extends IEnum { 6 | } 7 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/io/ISendTransport.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.io; 2 | 3 | public interface ISendTransport extends AutoCloseable { 4 | 5 | void send(T payload); 6 | } 7 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/IO/IErrorable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JNetCall.Sharp.API.IO 4 | { 5 | public interface IErrorable : IDisposable 6 | { 7 | string GetErrorDetails(); 8 | } 9 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/flow/MethodCall.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.flow; 2 | 3 | public record MethodCall(short I, String C, String M, Object[] A) 4 | implements ICall { 5 | } 6 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/io/IPullTransport.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.io; 2 | 3 | public interface IPullTransport extends ISendTransport { 4 | 5 | T pull(Class clazz); 6 | } 7 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/IO/ISendTransport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JNetCall.Sharp.API.IO 4 | { 5 | public interface ISendTransport : IDisposable 6 | { 7 | void Send(T payload); 8 | } 9 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.StdIO/Common/StreamInit.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using JNetCall.Sharp.API.IO; 3 | 4 | namespace JNetCall.Sharp.Common 5 | { 6 | public delegate ISendTransport StreamInit(Stream stdIn, Stream stdOut); 7 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/client/model/DelegateRef.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client.model; 2 | 3 | public class DelegateRef { 4 | 5 | public short CallId; 6 | 7 | public Object Entry; 8 | } 9 | -------------------------------------------------------------------------------- /NET/Aliens.Sharp/Aliens.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | Example 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/IO/IPushTransport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JNetCall.Sharp.API.IO 4 | { 5 | public interface IPushTransport : ISendTransport 6 | { 7 | void OnPush(Action data); 8 | } 9 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Client/API/IProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Castle.DynamicProxy; 3 | 4 | namespace JNetCall.Sharp.Client.API 5 | { 6 | public interface IProxy : IInterceptor, IDisposable 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/hostfxr_error_writer_fn.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | public interface hostfxr_error_writer_fn { 4 | 5 | void apply(TString message); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/client/api/IProxy.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client.api; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | 5 | public interface IProxy extends InvocationHandler, AutoCloseable { 6 | } 7 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/IO/TestedService.cs: -------------------------------------------------------------------------------- 1 | using Example.Impl; 2 | 3 | namespace JNetCall.Sharp.Tests.IO 4 | { 5 | internal sealed class TestedService : CalculatorService 6 | { 7 | public override string Name => "Java"; 8 | } 9 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-inproc/src/main/java/jnetcall/java/api/ICaller.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api; 2 | 3 | import java.io.OutputStream; 4 | 5 | public interface ICaller { 6 | 7 | boolean tryCall(byte[] in, OutputStream output) throws Exception; 8 | } 9 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Client/Model/DelegateRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JNetCall.Sharp.Client.Model 4 | { 5 | public class DelegateRef 6 | { 7 | public short CallId; 8 | 9 | public Delegate Entry; 10 | } 11 | } -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/flags/ByteFlag.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.flags; 2 | 3 | import com.xafero.javaenums.api.IFlag; 4 | import com.xafero.javaenums.units.ByteEnum; 5 | 6 | public interface ByteFlag extends ByteEnum, IFlag { 7 | } 8 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/flags/IntFlag.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.flags; 2 | 3 | import com.xafero.javaenums.api.IFlag; 4 | import com.xafero.javaenums.units.IntEnum; 5 | 6 | public interface IntFlag extends IntEnum, IFlag { 7 | } 8 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/flags/LongFlag.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.flags; 2 | 3 | import com.xafero.javaenums.api.IFlag; 4 | import com.xafero.javaenums.units.LongEnum; 5 | 6 | public interface LongFlag extends LongEnum, IFlag { 7 | } 8 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/flags/ShortFlag.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.flags; 2 | 3 | import com.xafero.javaenums.api.IFlag; 4 | import com.xafero.javaenums.units.ShortEnum; 5 | 6 | public interface ShortFlag extends ShortEnum, IFlag { 7 | } 8 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/component_entry_point_fn.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Pointer; 4 | 5 | public interface component_entry_point_fn { 6 | 7 | int apply(Pointer arg, int arg_size_in_bytes); 8 | } 9 | -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/Threads/IExecutor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace JNetBase.Sharp.Threads 5 | { 6 | public interface IExecutor : IDisposable 7 | { 8 | Thread CreateThread(ThreadStart action, string name); 9 | } 10 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/Enc/IEncoding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JNetCall.Sharp.API.Enc 4 | { 5 | public interface IEncoding : IDisposable 6 | { 7 | TRaw Encode(T data); 8 | 9 | T Decode(TRaw data); 10 | } 11 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/io/IPushTransport.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.io; 2 | 3 | import java.util.function.Consumer; 4 | 5 | public interface IPushTransport extends ISendTransport { 6 | 7 | void onPush(Consumer data, Class clazz); 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/threads/IExecutor.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.threads; 2 | 3 | import java.util.concurrent.ThreadFactory; 4 | 5 | public interface IExecutor extends ThreadFactory, AutoCloseable { 6 | 7 | Thread createThread(Runnable action, String name); 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/api/IVmRef.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.api; 2 | 3 | import java.io.IOException; 4 | 5 | public interface IVmRef { 6 | 7 | String getVmDll(); 8 | 9 | void loadLib() throws IOException; 10 | 11 | ICoreClr getCoreClr(); 12 | } 13 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/server/api/IHosting.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.server.api; 2 | 3 | public interface IHosting extends AutoCloseable { 4 | 5 | void addServiceEndpoint(Class type); 6 | 7 | T goDynInvoke(Class type, short id, Object... args); 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/get_hostfxr_parameters_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import jnethotel.java.interop.api.get_hostfxr_parameters; 4 | 5 | public class get_hostfxr_parameters_unix 6 | extends get_hostfxr_parameters { 7 | } 8 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Server/API/IHosting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JNetCall.Sharp.Server.API 4 | { 5 | public interface IHosting : IDisposable 6 | { 7 | void AddServiceEndpoint(Type type); 8 | 9 | T GoDynInvoke(short id, params object[] args); 10 | } 11 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/io/TestedService.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests.io; 2 | 3 | import org.example.impl.CalculatorService; 4 | 5 | public final class TestedService extends CalculatorService { 6 | 7 | @Override 8 | public String getName() { return "C#"; } 9 | } 10 | -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/JNetBase.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /NET/JNetProto.Sharp/JNetProto.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/component_entry_point_fn_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import com.sun.jna.Callback; 4 | import jnethotel.java.interop.api.component_entry_point_fn; 5 | 6 | public interface component_entry_point_fn_unix 7 | extends component_entry_point_fn, Callback { 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/hostfxr_error_writer_fn_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import com.sun.jna.Callback; 4 | import jnethotel.java.interop.api.hostfxr_error_writer_fn; 5 | 6 | public interface hostfxr_error_writer_fn_unix 7 | extends hostfxr_error_writer_fn, Callback { 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/get_hostfxr_parameters_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.WString; 4 | import jnethotel.java.interop.api.get_hostfxr_parameters; 5 | 6 | public class get_hostfxr_parameters_windows 7 | extends get_hostfxr_parameters { 8 | } 9 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Data/JvmOption.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace JNetHotel.Sharp.Data 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 0)] 7 | public struct JvmOption 8 | { 9 | public IntPtr optionString; 10 | private readonly IntPtr extraInfo; 11 | } 12 | } -------------------------------------------------------------------------------- /NET/Aliens.Sharp/API/IStringCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Example.API 4 | { 5 | public interface IStringCache : IDisposable 6 | { 7 | void Set(int key, string value); 8 | string Get(int key); 9 | void Delete(int key); 10 | int Size { get; } 11 | 12 | void Clean(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-stdio/src/main/java/jnetcall/java/common/StreamInit.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.common; 2 | 3 | import jnetcall.java.api.io.ISendTransport; 4 | 5 | import java.io.InputStream; 6 | import java.io.OutputStream; 7 | 8 | public interface StreamInit { 9 | 10 | ISendTransport invoke(InputStream stdIn, OutputStream stdOut); 11 | } 12 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Interop/JNINativeInterfacePtr.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | 3 | namespace JNetHotel.Sharp.Interop 4 | { 5 | internal struct JNINativeInterfacePtr 6 | { 7 | #pragma warning disable CS0649 8 | public unsafe JNINativeInterface* functions; 9 | #pragma warning restore CS0649 10 | } 11 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/nethost_library_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import com.sun.jna.Library; 4 | import jnethotel.java.interop.api.nethost_library; 5 | 6 | import java.nio.ByteBuffer; 7 | 8 | public interface nethost_library_unix 9 | extends nethost_library, Library { 10 | } 11 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/API/Flow/MethodStatus.cs: -------------------------------------------------------------------------------- 1 | namespace JNetCall.Sharp.API.Flow 2 | { 3 | public enum MethodStatus : short 4 | { 5 | Unknown = 0, 6 | 7 | ClassNotFound = 404, 8 | 9 | MethodNotFound = 406, 10 | 11 | MethodFailed = 500, 12 | 13 | Continue = 100, 14 | 15 | Ok = 200 16 | } 17 | } -------------------------------------------------------------------------------- /JVM/aliens-java/src/main/java/org/example/api/ICalculator.java: -------------------------------------------------------------------------------- 1 | package org.example.api; 2 | 3 | public interface ICalculator extends AutoCloseable 4 | { 5 | double add(double n1, double n2); 6 | double subtract(double n1, double n2); 7 | double multiply(double n1, double n2); 8 | double divide(double n1, double n2); 9 | String getName(); 10 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/nethost_library.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.ptr.PointerByReference; 5 | 6 | public interface nethost_library { 7 | 8 | int get_hostfxr_path(TBuffer buffer, PointerByReference buffer_size, Pointer parameters); 9 | } 10 | -------------------------------------------------------------------------------- /JVM/aliens-java/src/main/java/org/example/api/IStringCache.java: -------------------------------------------------------------------------------- 1 | package org.example.api; 2 | 3 | public interface IStringCache extends AutoCloseable { 4 | 5 | void set(int key, String value); 6 | String get(int key) throws UnsupportedOperationException; 7 | void delete(int key); 8 | int getSize(); 9 | 10 | void clean() throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/hostfxr_library_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import jnethotel.java.interop.api.hostfxr_library; 4 | import jnethotel.java.linux.impl.hostfxr_initialize_parameters_unix.ByReference; 5 | 6 | public interface hostfxr_library_unix 7 | extends hostfxr_library { 8 | } 9 | -------------------------------------------------------------------------------- /NET/Aliens.Sharp/API/ICalculator.cs: -------------------------------------------------------------------------------- 1 | namespace Example.API 2 | { 3 | public interface ICalculator : IDataTyped 4 | { 5 | double Add(double n1, double n2); 6 | double Subtract(double n1, double n2); 7 | double Multiply(double n1, double n2); 8 | double Divide(double n1, double n2); 9 | string Name { get; } 10 | } 11 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/sys/Primitives.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.sys; 2 | 3 | public final class Primitives { 4 | 5 | public static int[] castInt(byte[] array) { 6 | var values = new int[array.length]; 7 | for (var i = 0; i < values.length; i++) 8 | values[i] = array[i]; 9 | return values; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Interop/JNIInvokeInterfacePtr.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | 3 | using System.Runtime.InteropServices; 4 | 5 | namespace JNetHotel.Sharp.Interop 6 | { 7 | [StructLayout(LayoutKind.Sequential, Size = 4)] 8 | public struct JNIInvokeInterfacePtr 9 | { 10 | public readonly unsafe JNIInvokeInterface* functions; 11 | } 12 | } -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/JNetHotel.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/component_entry_point_fn_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.win32.StdCallLibrary.StdCallCallback; 4 | import jnethotel.java.interop.api.component_entry_point_fn; 5 | 6 | public interface component_entry_point_fn_windows 7 | extends component_entry_point_fn, StdCallCallback { 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/nethost_library_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.win32.StdCallLibrary; 4 | import jnethotel.java.interop.api.nethost_library; 5 | 6 | import java.nio.CharBuffer; 7 | 8 | public interface nethost_library_windows 9 | extends nethost_library, StdCallLibrary { 10 | } 11 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Data/JniResult.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable UnusedMember.Global 2 | namespace JNetHotel.Sharp.Data 3 | { 4 | public enum JniResult 5 | { 6 | Success = 0, 7 | Error = -1, 8 | ThreadDetached = -2, 9 | VersionError = -3, 10 | NotEnoughMemory = -4, 11 | AlreadyExists = -5, 12 | InvalidArguments = -6 13 | } 14 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/hostfxr_get_runtime_property_value_fn_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import com.sun.jna.Callback; 4 | import jnethotel.java.interop.api.hostfxr_get_runtime_property_value_fn; 5 | 6 | public interface hostfxr_get_runtime_property_value_fn_unix 7 | extends hostfxr_get_runtime_property_value_fn, Callback { 8 | } 9 | -------------------------------------------------------------------------------- /NET/Alien1.Sharp/Program.cs: -------------------------------------------------------------------------------- 1 | using Example.Impl; 2 | using JNetCall.Sharp.Server; 3 | 4 | namespace Example 5 | { 6 | internal static class Program 7 | { 8 | private static void Main() 9 | { 10 | using var host = ServiceHosts.Create(); 11 | host.RegisterAll(); 12 | host.ServeAndWait(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /NET/Aliens.Sharp/API/ISimultaneous.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace Example.API 5 | { 6 | public interface ISimultaneous : IDisposable 7 | { 8 | Task GetId(); 9 | 10 | Task LoadIt(string word); 11 | 12 | Task RemoveIt(); 13 | 14 | Task> RunIt(int waitMs, int idx); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Data/JvmInitArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace JNetHotel.Sharp.Data 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 0)] 6 | public unsafe struct JvmInitArgs 7 | { 8 | public int version; 9 | public int nOptions; 10 | public JvmOption* options; 11 | public byte ignoreUnrecognized; 12 | } 13 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/hostfxr_get_runtime_property_value_fn.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.ptr.PointerByReference; 5 | 6 | public interface hostfxr_get_runtime_property_value_fn { 7 | 8 | int apply(Pointer host_context_handle, TString name, PointerByReference value); 9 | } 10 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/hostfxr_error_writer_fn_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.Callback; 4 | import com.sun.jna.WString; 5 | import jnethotel.java.interop.api.hostfxr_error_writer_fn; 6 | 7 | public interface hostfxr_error_writer_fn_windows 8 | extends hostfxr_error_writer_fn, Callback { 9 | } 10 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.StdIO/JNetCall.Sharp.StdIO.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | JNetCall.Sharp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/load_assembly_and_get_function_pointer_fn_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import com.sun.jna.Callback; 4 | import jnethotel.java.interop.api.load_assembly_and_get_function_pointer_fn; 5 | 6 | public interface load_assembly_and_get_function_pointer_fn_unix 7 | extends load_assembly_and_get_function_pointer_fn, Callback { 8 | } 9 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/enc/IEncoding.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.enc; 2 | 3 | import jnetbase.java.meta.TypeToken; 4 | 5 | public interface IEncoding extends AutoCloseable { 6 | 7 | TRaw encode(T data) throws Exception; 8 | 9 | T decode(TRaw data, Class clazz) throws Exception; 10 | T decode(TRaw data, TypeToken token) throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/hostfxr_library_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.WString; 4 | import jnethotel.java.interop.api.hostfxr_library; 5 | import jnethotel.java.windows.impl.hostfxr_initialize_parameters_windows.ByReference; 6 | 7 | public interface hostfxr_library_windows 8 | extends hostfxr_library { 9 | } 10 | -------------------------------------------------------------------------------- /NET/Alien0.Sharp/Alien0.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | Example 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/hostfxr_get_runtime_property_value_fn_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.Callback; 4 | import com.sun.jna.WString; 5 | import jnethotel.java.interop.api.hostfxr_get_runtime_property_value_fn; 6 | 7 | public interface hostfxr_get_runtime_property_value_fn_windows 8 | extends hostfxr_get_runtime_property_value_fn, Callback { 9 | } 10 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/API/ICaller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace JNetCall.Sharp.API 6 | { 7 | internal interface ICaller 8 | { 9 | bool TryCall(byte[] @in, Stream output); 10 | } 11 | 12 | // ReSharper disable once UnusedType.Global 13 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 14 | public delegate IntPtr CallDelegate(IntPtr input); 15 | } -------------------------------------------------------------------------------- /JVM/alien1-java/src/main/java/org/example/Main.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import jnetcall.java.server.ServiceHosts; 4 | import org.example.impl.CalculatorService; 5 | 6 | public final class Main { 7 | 8 | public static void main(String[] args) throws Exception { 9 | 10 | try (var host = ServiceHosts.create(CalculatorService.class)) { 11 | host.registerAll(); 12 | host.serveAndWait(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /JVM/jnetproto-java/src/main/java/jnetproto/java/api/DataType.java: -------------------------------------------------------------------------------- 1 | package jnetproto.java.api; 2 | 3 | public enum DataType { 4 | Unknown, 5 | 6 | Bool, 7 | I8, 8 | I16, 9 | I32, 10 | I64, 11 | F32, 12 | F64, 13 | F128, 14 | Char, 15 | UTF8, 16 | Duration, 17 | Timestamp, 18 | Guid, 19 | Array, 20 | Map, 21 | Tuple, 22 | Set, 23 | List, 24 | Bag, 25 | Binary, 26 | Null 27 | } 28 | -------------------------------------------------------------------------------- /NET/Alien1.Sharp/Alien1.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | Example 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /JVM/alien2-java/src/main/java/x/Boot.java: -------------------------------------------------------------------------------- 1 | package x; 2 | 3 | import jnetcall.java.server.ServiceLots; 4 | import org.example.impl.CalculatorService; 5 | 6 | @SuppressWarnings("unused") 7 | public final class Boot { 8 | 9 | static { 10 | var host = ServiceLots.create(CalculatorService.class); 11 | host.registerAll(); 12 | host.serve(); 13 | } 14 | 15 | public static byte[] call(byte[] input) throws Exception { return ServiceLots.call(input); } 16 | } -------------------------------------------------------------------------------- /NET/Alienator.Sharp/Alienator.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | Example 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/load_assembly_and_get_function_pointer_fn.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.ptr.PointerByReference; 5 | 6 | public interface load_assembly_and_get_function_pointer_fn { 7 | 8 | int apply(TString assembly_path, TString type_name, TString method_name, TString delegate_type_name, 9 | Pointer reserved, PointerByReference delegate); 10 | } 11 | -------------------------------------------------------------------------------- /JVM/aliens-java/src/main/java/org/example/api/ISimultaneous.java: -------------------------------------------------------------------------------- 1 | package org.example.api; 2 | 3 | import org.javatuples.Pair; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | 7 | public interface ISimultaneous extends AutoCloseable { 8 | 9 | CompletableFuture getId(); 10 | 11 | CompletableFuture loadIt(String word); 12 | 13 | CompletableFuture removeIt(); 14 | 15 | CompletableFuture> runIt(int waitMs, int idx); 16 | } 17 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/client/model/CallState.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client.model; 2 | 3 | import jnetbase.java.threads.ManualResetEvent; 4 | 5 | public class CallState { 6 | 7 | public ManualResetEvent SyncWait; 8 | 9 | public ManualResetEvent AsyncWait; 10 | 11 | public Object Result; 12 | 13 | public void set() { 14 | if (SyncWait != null) SyncWait.set(); 15 | if (AsyncWait != null) AsyncWait.set(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/load_assembly_and_get_function_pointer_fn_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.WString; 4 | import com.sun.jna.win32.StdCallLibrary.StdCallCallback; 5 | import jnethotel.java.interop.api.load_assembly_and_get_function_pointer_fn; 6 | 7 | public interface load_assembly_and_get_function_pointer_fn_windows 8 | extends load_assembly_and_get_function_pointer_fn, StdCallCallback { 9 | } 10 | -------------------------------------------------------------------------------- /NET/Alien2.Sharp/Alien2.Sharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | true 6 | Example 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/API/IVmRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JNetHotel.Sharp.Data; 3 | 4 | namespace JNetHotel.Sharp.API 5 | { 6 | public interface IVmRef 7 | { 8 | unsafe JniResult CreateVm(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args); 9 | 10 | JniResult GetCreatedVms(out IntPtr pvm, int size, out int size2); 11 | 12 | unsafe JniResult GetDefaultArgs(JvmInitArgs* args); 13 | 14 | string VmDll { get; } 15 | 16 | void LoadLib(); 17 | } 18 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/api/flow/MethodStatus.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.api.flow; 2 | 3 | public enum MethodStatus { 4 | Unknown(0), 5 | ClassNotFound(404), 6 | MethodNotFound(406), 7 | MethodFailed(500), 8 | Continue(100), 9 | Ok(200); 10 | 11 | private final short value; 12 | 13 | MethodStatus(int value) { 14 | this.value = (short) value; 15 | } 16 | 17 | public short getValue() { 18 | return value; 19 | } 20 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Client/Model/CallState.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using Nito.AsyncEx; 3 | 4 | namespace JNetCall.Sharp.Client.Model 5 | { 6 | public class CallState 7 | { 8 | public ManualResetEvent SyncWait; 9 | 10 | public AsyncManualResetEvent AsyncWait; 11 | 12 | public object Result; 13 | 14 | public void Set() 15 | { 16 | SyncWait?.Set(); 17 | AsyncWait?.Set(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/MainCallTest.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable UnusedMember.Global 2 | using JNetCall.Sharp.Client; 3 | using static JNetCall.Sharp.Client.Tools.ServiceEnv; 4 | 5 | namespace JNetCall.Sharp.Tests 6 | { 7 | public sealed class MainCallTest : CallTest 8 | { 9 | internal readonly string Path 10 | = BuildPath(@"..\..\JVM\alien1-java\target\alien1-java.jar"); 11 | 12 | protected override T Create() 13 | { 14 | return StdIOClient.Create(Path); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/client/tools/ClientHelper.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client.tools; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Proxy; 5 | 6 | public final class ClientHelper { 7 | 8 | public static T create(Class clazz, InvocationHandler handler) { 9 | var loader = clazz.getClassLoader(); 10 | var types = new Class[]{clazz}; 11 | var proxy = Proxy.newProxyInstance(loader, types, handler); 12 | return (T) proxy; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/hostfxr_delegate_type.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | public interface hostfxr_delegate_type { 4 | 5 | public static final int hdt_com_activation = 0; 6 | public static final int hdt_load_in_memory_assembly = 1; 7 | public static final int hdt_winrt_activation = 2; 8 | public static final int hdt_com_register = 3; 9 | public static final int hdt_com_unregister = 4; 10 | public static final int hdt_load_assembly_and_get_function_pointer = 5; 11 | } 12 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/NativeCallTest.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable UnusedMember.Global 2 | using JNetCall.Sharp.Client; 3 | using static JNetCall.Sharp.Client.Tools.ServiceEnv; 4 | 5 | namespace JNetCall.Sharp.Tests 6 | { 7 | public sealed class NativeCallTest : CallTest 8 | { 9 | internal readonly string Path 10 | = BuildPath(@"..\..\JVM\alien2-java\target\alien2-java.jar"); 11 | 12 | protected override T Create() 13 | { 14 | return InProcClient.Create(Path); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/JNetCall.Sharp.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | JNetCall.Sharp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/MainCallTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests; 2 | 3 | import jnetcall.java.client.StdIOClient; 4 | 5 | import static jnetcall.java.client.tools.ServiceEnv.buildPath; 6 | 7 | public final class MainCallTest extends CallTest { 8 | 9 | final String Path = 10 | buildPath("..\\..\\..\\NET\\Alien1.Sharp\\bin\\Debug\\net6.0\\Alien1.Sharp.exe"); 11 | 12 | @Override 13 | protected T create(Class clazz) { 14 | return StdIOClient.create(clazz, Path); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/NativeCallTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests; 2 | 3 | import jnetcall.java.client.InProcClient; 4 | 5 | import static jnetcall.java.client.tools.ServiceEnv.buildPath; 6 | 7 | public final class NativeCallTest extends CallTest { 8 | 9 | final String Path = 10 | buildPath("..\\..\\..\\NET\\Alien2.Sharp\\bin\\Debug\\net6.0\\Alien2.Sharp.dll"); 11 | 12 | @Override 13 | protected T create(Class clazz) { 14 | return InProcClient.create(clazz, Path); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/Client/InProcClient.cs: -------------------------------------------------------------------------------- 1 | using JNetBase.Sharp.Threads; 2 | using JNetCall.Sharp.Client.Tools; 3 | 4 | namespace JNetCall.Sharp.Client 5 | { 6 | public static class InProcClient 7 | { 8 | public static T Create(string jar) where T : class 9 | { 10 | var pool = new ThreadExecutor(); 11 | var protocol = new JvmTransport(jar, 15); 12 | var handler = new ClassProxy(protocol, pool); 13 | handler.Listen(); 14 | return ClientHelper.Create(handler); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-inproc/src/main/java/jnetcall/java/client/InProcClient.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client; 2 | 3 | import jnetbase.java.threads.ThreadExecutor; 4 | import jnetcall.java.client.tools.ClientHelper; 5 | 6 | public final class InProcClient { 7 | 8 | public static T create(Class clazz, String dll) { 9 | var pool = new ThreadExecutor(); 10 | var protocol = new ClrTransport(dll, 15); 11 | var handler = new ClassProxy(protocol, pool); 12 | handler.listen(); 13 | return ClientHelper.create(clazz, handler); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NET/Alien2.Sharp/Boot.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable UnusedType.Global 2 | // ReSharper disable UnusedMember.Global 3 | // ReSharper disable CheckNamespace 4 | 5 | using System; 6 | using Example.Impl; 7 | using JNetCall.Sharp.Server; 8 | 9 | namespace X 10 | { 11 | public static class Boot 12 | { 13 | static Boot() 14 | { 15 | var host = ServiceLots.Create(); 16 | host.RegisterAll(); 17 | host.Serve(); 18 | } 19 | 20 | public static IntPtr Call(IntPtr input) => ServiceLots.Call(input); 21 | } 22 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/api/ICoreClr.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.api; 2 | 3 | import com.sun.jna.Function; 4 | 5 | public interface ICoreClr { 6 | 7 | Function load_assembly_and_get_callback(String runtime_config_path, String assembly_path, 8 | String type_name, String method_name, 9 | String delegate_type_name) throws Exception; 10 | 11 | Function get_load_assembly_and_get_function_pointer_fn(String runtime_config_path); 12 | 13 | boolean load_hostfxr(); 14 | } 15 | -------------------------------------------------------------------------------- /NET/JNetProto.Sharp/API/DataType.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | namespace JNetProto.Sharp.API 3 | { 4 | public enum DataType 5 | { 6 | Unknown = 0, 7 | 8 | Bool, 9 | I8, 10 | I16, 11 | I32, 12 | I64, 13 | F32, 14 | F64, 15 | F128, 16 | Char, 17 | UTF8, 18 | Duration, 19 | Timestamp, 20 | Guid, 21 | Array, 22 | Map, 23 | Tuple, 24 | Set, 25 | List, 26 | Bag, 27 | Binary, 28 | Null 29 | } 30 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/JNetCall.Sharp.InProc.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | JNetCall.Sharp 6 | 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Impl/IO/Net/NetworkTools.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | 5 | namespace JNetCall.Sharp.Impl.IO.Net 6 | { 7 | public static class NetworkTools 8 | { 9 | public static IPEndPoint ToEndPoint(string host, int port) 10 | { 11 | var dns = Dns.GetHostEntry(host); 12 | var l = dns.AddressList; 13 | var ip = l.First(a => a.AddressFamily == AddressFamily.InterNetwork); 14 | var endPoint = new IPEndPoint(ip, port); 15 | return endPoint; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.StdIO/Common/ByteMarks.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace JNetCall.Sharp.Common 4 | { 5 | public static class ByteMarks 6 | { 7 | public static (Stream stdIn, Stream stdOut) WriteSync(Stream stdOut, Stream stdIn) 8 | { 9 | const int marker = 0xEE; 10 | // Send flag 11 | stdIn.WriteByte(marker); 12 | stdIn.Flush(); 13 | // Receive flag 14 | while (stdOut.ReadByte() != marker) 15 | { 16 | } 17 | // Ready! 18 | return (stdOut, stdIn); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Interop/JValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace JNetHotel.Sharp.Interop 5 | { 6 | [StructLayout(LayoutKind.Explicit)] 7 | public struct JValue 8 | { 9 | [FieldOffset(0)] public byte z; 10 | [FieldOffset(0)] public byte b; 11 | [FieldOffset(0)] public char c; 12 | [FieldOffset(0)] public short s; 13 | [FieldOffset(0)] public int i; 14 | [FieldOffset(0)] public long j; 15 | [FieldOffset(0)] public float f; 16 | [FieldOffset(0)] public double d; 17 | [FieldOffset(0)] public IntPtr l; 18 | } 19 | } -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Interop/JNIInvokeInterface.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace JNetHotel.Sharp.Interop 6 | { 7 | [StructLayout(LayoutKind.Sequential)] 8 | public struct JNIInvokeInterface 9 | { 10 | public IntPtr reserved0; 11 | public IntPtr reserved1; 12 | public IntPtr reserved2; 13 | 14 | public IntPtr DestroyJavaVM; 15 | public IntPtr AttachCurrentThread; 16 | public IntPtr DetachCurrentThread; 17 | public IntPtr GetEnv; 18 | public IntPtr AttachCurrentThreadAsDaemon; 19 | } 20 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Server/Model/DelegateWrap.cs: -------------------------------------------------------------------------------- 1 | using JNetCall.Sharp.Server.API; 2 | 3 | namespace JNetCall.Sharp.Server.Model 4 | { 5 | internal sealed class DelegateWrap 6 | { 7 | private readonly IHosting _host; 8 | private readonly short _id; 9 | 10 | public DelegateWrap(IHosting host, short id) 11 | { 12 | _host = host; 13 | _id = id; 14 | } 15 | 16 | public T0 DynFunc(T1 a, T2 b) 17 | => _host.GoDynInvoke(_id, a, b); 18 | 19 | public void DynAction(T1 a, T2 b) 20 | => _host.GoDynInvoke(_id, a, b); 21 | } 22 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/hostfxr_initialize_parameters.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.Structure; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public abstract class hostfxr_initialize_parameters extends Structure { 10 | public Pointer size; 11 | 12 | public hostfxr_initialize_parameters() { 13 | super(); 14 | } 15 | 16 | public hostfxr_initialize_parameters(Pointer peer) { 17 | super(peer); 18 | } 19 | 20 | protected List getFieldOrder() { 21 | return Arrays.asList("size", "host_path", "dotnet_root"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NET/Aliens.Sharp/API/ITriggering.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Example.API 4 | { 5 | public interface ITriggering : IDisposable 6 | { 7 | public delegate bool PCallBack(int hWnd, string lParam); 8 | 9 | bool EnumWindows(PCallBack callback, int count); 10 | 11 | public event ThresholdHandler ThresholdReached; 12 | 13 | void StartPub(int count); 14 | 15 | public class ThresholdEventArgs : EventArgs 16 | { 17 | public int Threshold { get; set; } 18 | public DateTime TimeReached { get; set; } 19 | } 20 | 21 | public delegate void ThresholdHandler(object sender, ThresholdEventArgs e); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Client/Tools/ClientHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Castle.DynamicProxy; 3 | 4 | namespace JNetCall.Sharp.Client.Tools 5 | { 6 | public static class ClientHelper 7 | { 8 | private static readonly Lazy Generator; 9 | 10 | static ClientHelper() 11 | { 12 | Generator = new Lazy(() => new ProxyGenerator()); 13 | } 14 | 15 | public static T Create(IInterceptor interceptor) where T : class 16 | { 17 | var gen = Generator.Value; 18 | var proxy = gen.CreateInterfaceProxyWithoutTarget(interceptor); 19 | return proxy; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /JVM/javaenums/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero.utils 8 | javaenums 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /JVM/aliens-java/src/main/java/org/example/api/ITriggering.java: -------------------------------------------------------------------------------- 1 | package org.example.api; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public interface ITriggering extends AutoCloseable { 6 | 7 | interface PCallBack { 8 | boolean invoke(int hWnd, String lParam); 9 | } 10 | 11 | boolean enumWindows(PCallBack callback, int count); 12 | 13 | void addThresholdReached(ThresholdHandler handler); 14 | void removeThresholdReached(ThresholdHandler handler); 15 | 16 | void startPub(int count); 17 | 18 | record ThresholdEventArgs(int Threshold, LocalDateTime TimeReached) { 19 | } 20 | 21 | interface ThresholdHandler { 22 | void invoke(Object sender, ThresholdEventArgs e); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnetbase-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-stdio/src/main/java/jnetcall/java/common/ByteMarks.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.common; 2 | 3 | import jnetproto.java.tools.Tuples; 4 | import org.javatuples.Pair; 5 | 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | 10 | public final class ByteMarks { 11 | 12 | public static Pair writeSync(InputStream stdOut, OutputStream stdIn) 13 | throws IOException { 14 | final int marker = 0xEE; 15 | // Send flag 16 | stdIn.write(marker); 17 | stdIn.flush(); 18 | // Receive flag 19 | while (stdOut.read() != marker) ; 20 | // Ready! 21 | return Tuples.create(stdOut, stdIn); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/bits/BitFlag32.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.bits; 2 | 3 | import com.xafero.javaenums.BitFlag; 4 | import com.xafero.javaenums.Enums; 5 | import com.xafero.javaenums.flags.IntFlag; 6 | import com.xafero.javaenums.units.IntEnum; 7 | 8 | import java.util.Collection; 9 | 10 | public final class BitFlag32 11 | extends BitFlag 12 | implements IntEnum { 13 | 14 | public BitFlag32(Class enumType, Collection items) { 15 | super(enumType, items); 16 | } 17 | 18 | @Override 19 | public Integer asNumber() { 20 | return toInt(); 21 | } 22 | 23 | public int toInt() { 24 | return Enums.toInt(_items); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/bits/BitFlag8.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.bits; 2 | 3 | import com.xafero.javaenums.BitFlag; 4 | import com.xafero.javaenums.Enums; 5 | import com.xafero.javaenums.flags.ByteFlag; 6 | import com.xafero.javaenums.units.ByteEnum; 7 | 8 | import java.util.Collection; 9 | 10 | public final class BitFlag8 11 | extends BitFlag 12 | implements ByteEnum { 13 | 14 | public BitFlag8(Class enumType, Collection items) { 15 | super(enumType, items); 16 | } 17 | 18 | @Override 19 | public Byte asNumber() { 20 | return toByte(); 21 | } 22 | 23 | public byte toByte() { 24 | return Enums.toByte(_items); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/bits/BitFlag64.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.bits; 2 | 3 | import com.xafero.javaenums.BitFlag; 4 | import com.xafero.javaenums.Enums; 5 | import com.xafero.javaenums.flags.LongFlag; 6 | import com.xafero.javaenums.units.LongEnum; 7 | 8 | import java.util.Collection; 9 | 10 | public final class BitFlag64 11 | extends BitFlag 12 | implements LongEnum { 13 | 14 | public BitFlag64(Class enumType, Collection items) { 15 | super(enumType, items); 16 | } 17 | 18 | @Override 19 | public Long asNumber() { 20 | return toLong(); 21 | } 22 | 23 | public long toLong() { 24 | return Enums.toLong(_items); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JVM/javaenums/src/main/java/com/xafero/javaenums/bits/BitFlag16.java: -------------------------------------------------------------------------------- 1 | package com.xafero.javaenums.bits; 2 | 3 | import com.xafero.javaenums.BitFlag; 4 | import com.xafero.javaenums.Enums; 5 | import com.xafero.javaenums.flags.ShortFlag; 6 | import com.xafero.javaenums.units.ShortEnum; 7 | 8 | import java.util.Collection; 9 | 10 | public final class BitFlag16 11 | extends BitFlag 12 | implements ShortEnum { 13 | 14 | public BitFlag16(Class enumType, Collection items) { 15 | super(enumType, items); 16 | } 17 | 18 | @Override 19 | public Short asNumber() { 20 | return toShort(); 21 | } 22 | 23 | public short toShort() { 24 | return Enums.toShort(_items); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/threads/FuncTimerTask.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.threads; 2 | 3 | import java.util.TimerTask; 4 | import java.util.function.Consumer; 5 | 6 | public final class FuncTimerTask extends TimerTask implements AutoCloseable { 7 | 8 | private Consumer _worker; 9 | 10 | private FuncTimerTask(Consumer worker) { 11 | _worker = worker; 12 | } 13 | 14 | @Override 15 | public void run() { 16 | _worker.accept(this); 17 | } 18 | 19 | @Override 20 | public void close() throws Exception { 21 | cancel(); 22 | } 23 | 24 | public static FuncTimerTask wrap(Consumer worker) { 25 | return new FuncTimerTask(worker); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Interop/JNINativeMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | // ReSharper disable InconsistentNaming 5 | 6 | namespace JNetHotel.Sharp.Interop 7 | { 8 | public struct JNINativeMethod : IDisposable 9 | { 10 | public IntPtr name; // char* 11 | public IntPtr signature; // char* 12 | public IntPtr fnPtr; // void* 13 | 14 | public void Dispose() 15 | { 16 | if (name != IntPtr.Zero) 17 | { 18 | Marshal.FreeHGlobal(name); 19 | name = IntPtr.Zero; 20 | } 21 | if (signature != IntPtr.Zero) 22 | { 23 | Marshal.FreeHGlobal(signature); 24 | signature = IntPtr.Zero; 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/IO/MemTransportTest.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using JNetBase.Sharp.IO; 3 | using JNetCall.Sharp.API.IO; 4 | using JNetCall.Sharp.Impl.IO; 5 | 6 | namespace JNetCall.Sharp.Tests.IO 7 | { 8 | public sealed class MemTransportTest : TransportTest 9 | { 10 | protected override (ISendTransport, ISendTransport) GetBoth() 11 | { 12 | Stream mem11001 = new MemPipeStream(); 13 | Stream mem11002 = new MemPipeStream(); 14 | var left = new StreamTransport( 15 | Encoding, 16 | mem11001, 17 | mem11002 18 | ); 19 | var right = new StreamTransport( 20 | Encoding, 21 | mem11002, 22 | mem11001 23 | ); 24 | return (left, right); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/io/MemTransportTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests.io; 2 | 3 | import jnetbase.java.io.MemPipeStream; 4 | import jnetcall.java.api.io.ISendTransport; 5 | import jnetcall.java.impl.io.StreamTransport; 6 | import org.javatuples.Pair; 7 | 8 | public final class MemTransportTest extends TransportTest { 9 | 10 | @Override 11 | protected Pair getBoth() { 12 | var mem11001 = new MemPipeStream(); 13 | var mem11002 = new MemPipeStream(); 14 | var left = new StreamTransport( 15 | Encoding, 16 | mem11001.asI(), 17 | mem11002.asO() 18 | ); 19 | var right = new StreamTransport( 20 | Encoding, 21 | mem11002.asI(), 22 | mem11001.asO() 23 | ); 24 | return Pair.with(left, right); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/io/ByteArrayStream.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.io; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | 7 | public final class ByteArrayStream extends ByteArrayInputStream { 8 | 9 | private ByteArrayOutputStream _memory; 10 | 11 | public ByteArrayStream() { 12 | super(new byte[0]); 13 | renew(); 14 | } 15 | 16 | private void renew() { 17 | _memory = new ByteArrayOutputStream(); 18 | } 19 | 20 | public void write(byte[] result) throws IOException { 21 | _memory.write(result); 22 | } 23 | 24 | @Override 25 | public synchronized void reset() { 26 | super.reset(); 27 | 28 | var array = _memory.toByteArray(); 29 | renew(); 30 | 31 | buf = array; 32 | pos = 0; 33 | count = buf.length; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NET/JNetProto.Sharp/API/IDataReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace JNetProto.Sharp.API 6 | { 7 | public interface IDataReader : IDisposable 8 | { 9 | bool ReadBool(); 10 | byte ReadI8(); 11 | short ReadI16(); 12 | int ReadI32(); 13 | long ReadI64(); 14 | float ReadF32(); 15 | double ReadF64(); 16 | decimal ReadF128(); 17 | char ReadChar(); 18 | string ReadUtf8(); 19 | TimeSpan ReadDuration(); 20 | DateTime ReadTimestamp(); 21 | Guid ReadGuid(); 22 | Array ReadArray(); 23 | IDictionary ReadMap(); 24 | ITuple ReadTuple(); 25 | IEnumerable ReadSet(); 26 | IList ReadList(); 27 | object[] ReadBag(); 28 | byte[] ReadBinary(); 29 | object ReadNull(); 30 | object ReadObject(); 31 | } 32 | } -------------------------------------------------------------------------------- /JVM/alien0-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | alien0-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | org.example 20 | aliens-java 21 | 1.0 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnethotel-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | net.java.dev.jna 20 | jna 21 | 5.11.0 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /NET/Aliens.Sharp/API/IDataTyped.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Example.API 5 | { 6 | public interface IDataTyped : IMultiple 7 | { 8 | string ToSimpleText(byte y, short s, int i, long l, float f, double d, 9 | bool b, char c, string t, decimal u, Guid g); 10 | 11 | string ToArrayText(byte[] y, short[] s, int[] i, long[] l, float[] f, double[] d, 12 | bool[] b, char[] c, string[] t, decimal[] u, Guid[] g); 13 | 14 | int GetLineCount(string[] lines); 15 | 16 | long GetFileSize(string path); 17 | 18 | byte[] AllocateBytes(int size, byte value); 19 | 20 | ISet GetUnique(IList lines, bool withTrim); 21 | 22 | IList GetDouble(ISet lines); 23 | 24 | IDictionary GetSystemVariables(DateTime dts, TimeSpan dur, 25 | IDictionary parent); 26 | } 27 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/VmHelper.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop; 2 | 3 | import java.io.File; 4 | 5 | public final class VmHelper { 6 | 7 | public static String getRuntimeConfig(String dll) { 8 | var base = removeDll(dll); 9 | final String suffix = ".runtimeconfig.json"; 10 | return base + suffix; 11 | } 12 | 13 | private static String removeDll(String dll) { 14 | return dll.substring(0, dll.length() - 4); 15 | } 16 | 17 | public static String getTypeName(String typeName, String dll) { 18 | var assemblyShort = (new File(dll)).getName(); 19 | var assemblyName = removeDll(assemblyShort); 20 | return typeName + ", " + assemblyName; 21 | } 22 | 23 | public static String getNext(String dll, String name) { 24 | var assemblyDir = (new File(dll)).getParent(); 25 | return (new File(assemblyDir, name + ".dll")).toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JNetCall 2 | Java VM .NET Call abstraction 3 | 4 | ## History 5 | In the past there was atleast one solution for .NET Framework 4.5+ and Java 8 for reusing software libraries written in Java. 6 | But now I needed the ability to call current Java 18 code from C# 10 on .NET 6, so I created this project here. 7 | 8 | ## Summary 9 | * Call Java from C# 10 | (see NET/Alienator.Sharp/Program.cs) 11 | (StdIO or InProcess) 12 | 13 | * Call C# from Java 14 | (see JVM/alienator-java/src/main/java/org/example/Main.java) 15 | (StdIO or InProcess) 16 | 17 | ## How to build 18 | If you are on Microsoft Windows, use "build.bat", 19 | otherwise "build.sh". 20 | 21 | ## Environments tested 22 | * OpenJDK 18 and .NET 6 on Ubuntu 22.04 23 | * Oracle's JDK 18 and .NET 6 on Windows 11 24 | * Temurin's JDK 18 and .NET 6 on MacOS 12.3 25 | * OpenJDK 18 and .NET 6 on FreeBSD 13.1 26 | 27 | ## License 28 | Everything is licensed under GNU Affero General Public License (AGPL). 29 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnetcall-java-common 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | com.xafero 20 | jnetproto-java 21 | 1.0 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-stdio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnetcall-java-stdio 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | com.xafero 20 | jnetcall-java-common 21 | 1.0 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.StdIO/Client/StdIOClient.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using JNetBase.Sharp.Threads; 3 | using JNetCall.Sharp.API.IO; 4 | using JNetCall.Sharp.Client.Tools; 5 | using JNetCall.Sharp.Impl.Enc; 6 | using JNetCall.Sharp.Impl.IO; 7 | 8 | namespace JNetCall.Sharp.Client 9 | { 10 | // ReSharper disable once InconsistentNaming 11 | public static class StdIOClient 12 | { 13 | public static T Create(string exe) where T : class 14 | { 15 | var pool = new ThreadExecutor(); 16 | var protocol = new JarTransport(exe, InitDefault); 17 | var handler = new ClassProxy(protocol, pool); 18 | handler.Listen(); 19 | return ClientHelper.Create(handler); 20 | } 21 | 22 | private static ISendTransport InitDefault(Stream stdIn, Stream stdOut) 23 | { 24 | var enc = new BinaryEncoding(); 25 | return new StreamTransport(enc, stdIn, stdOut); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/Threads/ThreadExecutor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | 4 | namespace JNetBase.Sharp.Threads 5 | { 6 | public sealed class ThreadExecutor : IExecutor 7 | { 8 | private readonly IList _threads; 9 | 10 | public ThreadExecutor() 11 | { 12 | _threads = new List(); 13 | } 14 | 15 | public void Dispose() 16 | { 17 | foreach (var thread in _threads) 18 | thread.Interrupt(); 19 | _threads.Clear(); 20 | } 21 | 22 | public Thread CreateThread(ThreadStart action, string name) 23 | { 24 | var task = new Thread(action) 25 | { 26 | IsBackground = true 27 | }; 28 | if (name != null) 29 | task.Name = name; 30 | _threads.Add(task); 31 | task.Start(); 32 | return task; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/threads/ThreadExecutor.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.threads; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public final class ThreadExecutor implements IExecutor { 7 | 8 | private final List _threads; 9 | 10 | public ThreadExecutor() { 11 | _threads = new LinkedList(); 12 | } 13 | 14 | @Override 15 | public void close() { 16 | for (var thread : _threads) 17 | thread.interrupt(); 18 | _threads.clear(); 19 | } 20 | 21 | @Override 22 | public Thread createThread(Runnable action, String name) { 23 | var task = new Thread(action); 24 | task.setDaemon(true); 25 | if (name != null) 26 | task.setName(name); 27 | _threads.add(task); 28 | task.start(); 29 | return task; 30 | } 31 | 32 | @Override 33 | public Thread newThread(Runnable action) { 34 | return createThread(action, null); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/IO/TcpTransportTest.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using JNetCall.Sharp.API.IO; 3 | using JNetCall.Sharp.Impl.IO.Net; 4 | 5 | namespace JNetCall.Sharp.Tests.IO 6 | { 7 | public sealed class TcpTransportTest : TransportTest 8 | { 9 | private static int _offset; 10 | private static int NextOffset => Interlocked.Increment(ref _offset); 11 | 12 | protected override (ISendTransport, ISendTransport) GetBoth() 13 | { 14 | var offset = NextOffset; 15 | var portOne = 12001 + offset; 16 | var portTwo = 12051 + offset; 17 | var left = new TcpTransport( 18 | Encoding, 19 | "localhost", portOne, 20 | "localhost", portTwo 21 | ); 22 | var right = new TcpTransport( 23 | Encoding, 24 | "localhost", portTwo, 25 | "localhost", portOne 26 | ); 27 | return (left, right); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/IO/UdpTransportTest.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using JNetCall.Sharp.API.IO; 3 | using JNetCall.Sharp.Impl.IO.Net; 4 | 5 | namespace JNetCall.Sharp.Tests.IO 6 | { 7 | public sealed class UdpTransportTest : TransportTest 8 | { 9 | private static int _offset; 10 | private static int NextOffset => Interlocked.Increment(ref _offset); 11 | 12 | protected override (ISendTransport, ISendTransport) GetBoth() 13 | { 14 | var offset = NextOffset; 15 | var portOne = 11001 + offset; 16 | var portTwo = 11051 + offset; 17 | var left = new UdpTransport( 18 | Encoding, 19 | "localhost", portOne, 20 | "localhost", portTwo 21 | ); 22 | var right = new UdpTransport( 23 | Encoding, 24 | "localhost", portTwo, 25 | "localhost", portOne 26 | ); 27 | return (left, right); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-stdio/src/main/java/jnetcall/java/client/StdIOClient.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client; 2 | 3 | import jnetbase.java.threads.ThreadExecutor; 4 | import jnetcall.java.api.io.ISendTransport; 5 | import jnetcall.java.client.tools.ClientHelper; 6 | import jnetcall.java.impl.enc.BinaryEncoding; 7 | import jnetcall.java.impl.io.StreamTransport; 8 | 9 | import java.io.InputStream; 10 | import java.io.OutputStream; 11 | 12 | public final class StdIOClient { 13 | 14 | public static T create(Class clazz, String exe) { 15 | var pool = new ThreadExecutor(); 16 | var protocol = new ExeTransport(exe, StdIOClient::initDefault); 17 | var handler = new ClassProxy(protocol, pool); 18 | handler.listen(); 19 | return ClientHelper.create(clazz, handler); 20 | } 21 | 22 | private static ISendTransport initDefault(InputStream stdIn, OutputStream stdOut) { 23 | var enc = new BinaryEncoding(); 24 | return new StreamTransport(enc, stdIn, stdOut); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/impl/hostfxr_initialize_parameters_unix.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux.impl; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.Structure; 5 | import jnethotel.java.interop.api.hostfxr_initialize_parameters; 6 | 7 | public class hostfxr_initialize_parameters_unix 8 | extends hostfxr_initialize_parameters { 9 | 10 | public String host_path; 11 | public String dotnet_root; 12 | 13 | public hostfxr_initialize_parameters_unix() { 14 | super(); 15 | } 16 | 17 | public hostfxr_initialize_parameters_unix(Pointer size, String host_path, String dotnet_root) { 18 | super(); 19 | 20 | this.size = size; 21 | this.host_path = host_path; 22 | this.dotnet_root = dotnet_root; 23 | } 24 | 25 | public static class ByReference extends hostfxr_initialize_parameters_unix implements Structure.ByReference { 26 | } 27 | 28 | public static class ByValue extends hostfxr_initialize_parameters_unix implements Structure.ByValue { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/Tools/Interop.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace JNetCall.Sharp.Tools 5 | { 6 | public static class Interop 7 | { 8 | public static byte[] ToByteArray(IntPtr ptr, int size = -1) 9 | { 10 | if (size == -1) 11 | { 12 | const int header = 4; 13 | var len = BitConverter.ToInt32(ToByteArray(ptr, header)); 14 | size = header + len; 15 | } 16 | var array = new byte[size]; 17 | unsafe 18 | { 19 | var arrayPtr = ((byte*)ptr)!; 20 | for (var i = 0; i < array.Length; i++) 21 | array[i] = arrayPtr[i]; 22 | } 23 | return array; 24 | } 25 | 26 | public static IntPtr ToPointer(byte[] data) 27 | { 28 | var pointer = Marshal.AllocHGlobal(data.Length); 29 | Marshal.Copy(data, 0, pointer, data.Length); 30 | return pointer; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Interop/JNIInvokeInterface_.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | using System; 3 | using System.Runtime.InteropServices; 4 | using JNetHotel.Sharp.Data; 5 | 6 | namespace JNetHotel.Sharp.Interop 7 | { 8 | public struct JNIInvokeInterface_ 9 | { 10 | [UnmanagedFunctionPointer(CallingConvention.Winapi)] 11 | internal delegate int DestroyJavaVM(IntPtr pVM); 12 | 13 | [UnmanagedFunctionPointer(CallingConvention.Winapi)] 14 | internal unsafe delegate int AttachCurrentThread(IntPtr pVM, out IntPtr pEnv, JvmInitArgs* Args); 15 | 16 | [UnmanagedFunctionPointer(CallingConvention.Winapi)] 17 | internal delegate int DetachCurrentThread(IntPtr pVM); 18 | 19 | [UnmanagedFunctionPointer(CallingConvention.Winapi)] 20 | internal delegate int GetEnv(IntPtr pVM, out IntPtr pEnv, int Version); 21 | 22 | [UnmanagedFunctionPointer(CallingConvention.Winapi)] 23 | internal unsafe delegate int AttachCurrentThreadAsDaemon(IntPtr pVM, out IntPtr pEnv, JvmInitArgs* Args); 24 | } 25 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/meta/TypeToken.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.meta; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | 6 | public class TypeToken { 7 | 8 | private final Type _base; 9 | private final Type _arg; 10 | 11 | public TypeToken() { 12 | _base = getClass().getGenericSuperclass(); 13 | _arg = ((ParameterizedType) _base).getActualTypeArguments()[0]; 14 | } 15 | 16 | private TypeToken(Type type) { 17 | _base = getClass(); 18 | _arg = type; 19 | } 20 | 21 | public Class toClass() { 22 | return (Class) _arg; 23 | } 24 | 25 | public Type toType() { 26 | return _arg; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return _arg.toString(); 32 | } 33 | 34 | public static TypeToken wrap(Type type) { 35 | return new TypeToken(type); 36 | } 37 | 38 | public static TypeToken wrap(Class clazz) { 39 | return new TypeToken(clazz); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Impl/Enc/BinaryEncoding.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using JNetCall.Sharp.API.Enc; 3 | using JNetProto.Sharp.Beans; 4 | 5 | namespace JNetCall.Sharp.Impl.Enc 6 | { 7 | public sealed class BinaryEncoding : IByteEncoding 8 | { 9 | private readonly ProtoSettings _config; 10 | 11 | public BinaryEncoding() 12 | { 13 | _config = new ProtoSettings(); 14 | } 15 | 16 | public byte[] Encode(T data) 17 | { 18 | using var output = new MemoryStream(); 19 | using var proto = new ProtoConvert(null, output, _config); 20 | proto.WriteObject(data); 21 | return output.ToArray(); 22 | } 23 | 24 | public T Decode(byte[] data) 25 | { 26 | using var input = new MemoryStream(data); 27 | using var proto = new ProtoConvert(input, null, _config); 28 | var res = proto.ReadObject(); 29 | return res; 30 | } 31 | 32 | public void Dispose() 33 | { 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/impl/hostfxr_initialize_parameters_windows.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows.impl; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.Structure; 5 | import com.sun.jna.WString; 6 | import jnethotel.java.interop.api.hostfxr_initialize_parameters; 7 | 8 | public class hostfxr_initialize_parameters_windows 9 | extends hostfxr_initialize_parameters { 10 | 11 | public WString host_path; 12 | public WString dotnet_root; 13 | 14 | public hostfxr_initialize_parameters_windows() { 15 | super(); 16 | } 17 | 18 | public hostfxr_initialize_parameters_windows(Pointer size, WString host_path, WString dotnet_root) { 19 | super(); 20 | 21 | this.size = size; 22 | this.host_path = host_path; 23 | this.dotnet_root = dotnet_root; 24 | } 25 | 26 | public static class ByReference extends hostfxr_initialize_parameters_windows implements Structure.ByReference { 27 | } 28 | 29 | public static class ByValue extends hostfxr_initialize_parameters_windows implements Structure.ByValue { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /JVM/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnetcall-parent 9 | 1.0 10 | 11 | pom 12 | 13 | javaenums 14 | jnethotel-java 15 | jnetcall-java-common 16 | jnetcall-java-inproc 17 | jnetcall-java-stdio 18 | jnetcall-java-tests 19 | jnetbase-java 20 | jnetproto-java 21 | alien0-java 22 | alien1-java 23 | alien2-java 24 | aliens-java 25 | alienator-java 26 | 27 | 28 | -------------------------------------------------------------------------------- /NET/JNetProto.Sharp.Tests/JNetProto.Sharp.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | all 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /JVM/aliens-java/src/main/java/org/example/api/IDataTyped.java: -------------------------------------------------------------------------------- 1 | package org.example.api; 2 | 3 | import java.math.BigDecimal; 4 | import java.time.Duration; 5 | import java.time.LocalDateTime; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Set; 9 | import java.util.UUID; 10 | 11 | public interface IDataTyped extends AutoCloseable { 12 | 13 | String ToSimpleText(byte y, short s, int i, long l, float f, double d, 14 | boolean b, char c, String t, BigDecimal u, UUID g); 15 | 16 | String ToArrayText(byte[] y, short[] s, int[] i, long[] l, float[] f, double[] d, 17 | boolean[] b, char[] c, String[] t, BigDecimal[] u, UUID[] g); 18 | 19 | int GetLineCount(String[] lines); 20 | 21 | long GetFileSize(String path); 22 | 23 | byte[] AllocateBytes(int size, byte value); 24 | 25 | Set GetUnique(List lines, boolean withTrim); 26 | 27 | List GetDouble(Set lines); 28 | 29 | Map GetSystemVariables(LocalDateTime dts, Duration dur, 30 | Map parent); 31 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/sys/Strings.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.sys; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.PrintWriter; 6 | import java.io.StringWriter; 7 | 8 | public final class Strings { 9 | 10 | public static int countMatches(CharSequence text, char letter) { 11 | if (text.length() == 0) 12 | return 0; 13 | var count = 0; 14 | for (var i = 0; i < text.length(); ++i) 15 | if (letter == text.charAt(i)) 16 | ++count; 17 | return count; 18 | } 19 | 20 | public static String getStackTrace(Throwable error) { 21 | var bld = new StringWriter(); 22 | var printer = new PrintWriter(bld, true); 23 | error.printStackTrace(printer); 24 | return bld.getBuffer().toString(); 25 | } 26 | 27 | public static String repeat(int num, String c) { 28 | return new String(new char[num]).replace("\0", c); 29 | } 30 | 31 | public static String readToEnd(InputStream stream) throws IOException { 32 | return new String(stream.readAllBytes()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /JVM/aliens-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | aliens-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | com.flipkart.utils 20 | javatuples 21 | 3.0 22 | 23 | 24 | com.xafero.utils 25 | javaenums 26 | 1.0 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/io/TcpTransportTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests.io; 2 | 3 | import jnetcall.java.api.io.ISendTransport; 4 | import jnetcall.java.impl.io.net.TcpTransport; 5 | import org.javatuples.Pair; 6 | 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | public final class TcpTransportTest extends TransportTest { 10 | 11 | private static AtomicInteger _offset = new AtomicInteger(); 12 | 13 | private static int getNextOffset() { 14 | return _offset.incrementAndGet(); 15 | } 16 | 17 | @Override 18 | protected Pair getBoth() { 19 | var offset = getNextOffset(); 20 | var portOne = 12001 + offset; 21 | var portTwo = 12051 + offset; 22 | var left = new TcpTransport( 23 | Encoding, 24 | "localhost", portOne, 25 | "localhost", portTwo 26 | ); 27 | var right = new TcpTransport( 28 | Encoding, 29 | "localhost", portTwo, 30 | "localhost", portOne 31 | ); 32 | return Pair.with(left, right); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/io/UdpTransportTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests.io; 2 | 3 | import jnetcall.java.api.io.ISendTransport; 4 | import jnetcall.java.impl.io.net.UdpTransport; 5 | import org.javatuples.Pair; 6 | 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | public final class UdpTransportTest extends TransportTest { 10 | 11 | private static AtomicInteger _offset = new AtomicInteger(); 12 | 13 | private static int getNextOffset() { 14 | return _offset.incrementAndGet(); 15 | } 16 | 17 | @Override 18 | protected Pair getBoth() { 19 | var offset = getNextOffset(); 20 | var portOne = 11001 + offset; 21 | var portTwo = 11051 + offset; 22 | var left = new UdpTransport( 23 | Encoding, 24 | "localhost", portOne, 25 | "localhost", portTwo 26 | ); 27 | var right = new UdpTransport( 28 | Encoding, 29 | "localhost", portTwo, 30 | "localhost", portOne 31 | ); 32 | return Pair.with(left, right); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Natives.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using JNetHotel.Sharp.API; 4 | using JNetHotel.Sharp.BSD; 5 | using JNetHotel.Sharp.Linux; 6 | using JNetHotel.Sharp.Mac; 7 | using JNetHotel.Sharp.Windows; 8 | 9 | namespace JNetHotel.Sharp 10 | { 11 | public static class Natives 12 | { 13 | public static IVmRef GetVmRef() 14 | { 15 | if (IsLinux) 16 | return new LinuxVmRef(); 17 | if (IsWindows) 18 | return new WinVmRef(); 19 | if (IsMac) 20 | return new MacVmRef(); 21 | if (IsBSD) 22 | return new BsdVmRef(); 23 | 24 | throw new InvalidOperationException(RuntimeInformation.OSDescription); 25 | } 26 | 27 | private static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); 28 | private static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); 29 | private static bool IsMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); 30 | private static bool IsBSD => RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD); 31 | } 32 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-inproc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnetcall-java-inproc 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | com.xafero 20 | jnetcall-java-common 21 | 1.0 22 | 23 | 24 | com.xafero 25 | jnethotel-java 26 | 1.0 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /NET/JNetProto.Sharp/API/IDataWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace JNetProto.Sharp.API 6 | { 7 | public interface IDataWriter : IDisposable 8 | { 9 | void WriteBool(bool value); 10 | void WriteI8(byte value); 11 | void WriteI16(short value); 12 | void WriteI32(int value); 13 | void WriteI64(long value); 14 | void WriteF32(float value); 15 | void WriteF64(double value); 16 | void WriteF128(decimal value); 17 | void WriteChar(char value); 18 | void WriteUtf8(string value); 19 | void WriteDuration(TimeSpan value); 20 | void WriteTimestamp(DateTime value); 21 | void WriteGuid(Guid value); 22 | void WriteArray(Array value); 23 | void WriteMap(IDictionary value); 24 | void WriteTuple(ITuple value); 25 | void WriteSet(IEnumerable value); 26 | void WriteList(IList value); 27 | void WriteBag(object[] value); 28 | void WriteBinary(byte[] value); 29 | void WriteNull(); 30 | void WriteObject(object value); 31 | void Flush(); 32 | } 33 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/threads/ManualResetEvent.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.threads; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | public final class ManualResetEvent { 7 | 8 | private static final Object mutex = new Object(); 9 | private volatile CountDownLatch event; 10 | 11 | public ManualResetEvent(boolean state) { 12 | if (state) { 13 | event = new CountDownLatch(0); 14 | } else { 15 | event = new CountDownLatch(1); 16 | } 17 | } 18 | 19 | public void set() { 20 | event.countDown(); 21 | } 22 | 23 | public void reset() { 24 | synchronized (mutex) { 25 | if (event.getCount() == 0) { 26 | event = new CountDownLatch(1); 27 | } 28 | } 29 | } 30 | 31 | public void waitOne() throws InterruptedException { 32 | event.await(); 33 | } 34 | 35 | public boolean waitOne(int timeout, TimeUnit unit) throws InterruptedException { 36 | return event.await(timeout, unit); 37 | } 38 | 39 | public boolean isSignalled() { 40 | return event.getCount() == 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/IO/FileTransportTest.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Threading; 3 | using JNetCall.Sharp.API.IO; 4 | using JNetCall.Sharp.Impl.IO.Disk; 5 | 6 | namespace JNetCall.Sharp.Tests.IO 7 | { 8 | public sealed class FileTransportTest : TransportTest 9 | { 10 | private const string Folder = @"FileTmp"; 11 | 12 | private static int _offset; 13 | private static int NextOffset => Interlocked.Increment(ref _offset); 14 | 15 | protected override (ISendTransport, ISendTransport) GetBoth() 16 | { 17 | var offset = NextOffset; 18 | var portOne = 13001 + offset + ""; 19 | var portTwo = 13051 + offset + ""; 20 | var left = new FolderTransport( 21 | Encoding, 22 | Path.Combine(Folder, portOne), 23 | Path.Combine(Folder, portTwo) 24 | ); 25 | var right = new FolderTransport( 26 | Encoding, 27 | Path.Combine(Folder, portTwo), 28 | Path.Combine(Folder, portOne) 29 | ); 30 | return (left, right); 31 | } 32 | 33 | protected override int MaxListWait => 20; 34 | } 35 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/Natives.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java; 2 | 3 | import com.sun.jna.Platform; 4 | import jnethotel.java.api.IVmRef; 5 | import jnethotel.java.bsd.BsdVmRef; 6 | import jnethotel.java.linux.LinuxVmRef; 7 | import jnethotel.java.mac.MacVmRef; 8 | import jnethotel.java.windows.WinVmRef; 9 | 10 | public final class Natives { 11 | 12 | public static IVmRef getVmRef() { 13 | if (isLinux()) 14 | return new LinuxVmRef(); 15 | if (isWindows()) 16 | return new WinVmRef(); 17 | if (isMac()) 18 | return new MacVmRef(); 19 | if (isBSD()) 20 | return new BsdVmRef(); 21 | 22 | var desc = System.getProperty("os.name") + " " + System.getProperty("os.version"); 23 | throw new UnsupportedOperationException(desc.trim()); 24 | } 25 | 26 | private static boolean isWindows() { 27 | return Platform.isWindows(); 28 | } 29 | 30 | private static boolean isLinux() { 31 | return Platform.isLinux(); 32 | } 33 | 34 | private static boolean isMac() { 35 | return Platform.isMac(); 36 | } 37 | 38 | private static boolean isBSD() { 39 | return Platform.isFreeBSD(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/get_hostfxr_parameters.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Pointer; 4 | import com.sun.jna.Structure; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public abstract class get_hostfxr_parameters extends Structure { 10 | public Pointer size; 11 | public TString assembly_path; 12 | public TString dotnet_root; 13 | 14 | public get_hostfxr_parameters() { 15 | super(); 16 | } 17 | 18 | public get_hostfxr_parameters(Pointer peer) { 19 | super(peer); 20 | } 21 | 22 | public get_hostfxr_parameters(Pointer size, TString assembly_path, TString dotnet_root) { 23 | super(); 24 | 25 | this.size = size; 26 | this.assembly_path = assembly_path; 27 | this.dotnet_root = dotnet_root; 28 | } 29 | 30 | protected List getFieldOrder() { 31 | return Arrays.asList("size", "assembly_path", "dotnet_root"); 32 | } 33 | 34 | public static class ByReference extends get_hostfxr_parameters implements Structure.ByReference { 35 | } 36 | 37 | public static class ByValue extends get_hostfxr_parameters implements Structure.ByValue { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/client/tools/ServiceEnv.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client.tools; 2 | 3 | import java.io.File; 4 | import java.nio.file.Paths; 5 | 6 | public final class ServiceEnv { 7 | 8 | private static String getBaseFolder() { 9 | try { 10 | var source = ServiceEnv.class.getProtectionDomain().getCodeSource(); 11 | File jar = new File(source.getLocation().toURI().getPath()); 12 | return jar.getParentFile().getPath(); 13 | } catch (Exception e) { 14 | throw new RuntimeException(e); 15 | } 16 | } 17 | 18 | public static String buildPath(String path) { 19 | var baseDir = getBaseFolder(); 20 | var destDir = Paths.get(baseDir, fixSlash(path)) 21 | .normalize().toAbsolutePath().toString(); 22 | return destDir; 23 | } 24 | 25 | private static String fixSlash(String path) { 26 | var sep = File.separator; 27 | return path.replace('/' + "", sep) 28 | .replace('\\' + "", sep); 29 | } 30 | 31 | public static File getCurrentDir() { 32 | var dir = Paths.get("").toAbsolutePath(); 33 | var txt = dir.normalize().toString(); 34 | return new File(txt); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/impl/io/StreamTools.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.impl.io; 2 | 3 | import jnetbase.java.sys.BitConverter; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.Arrays; 8 | 9 | public final class StreamTools { 10 | 11 | private static byte[] tryRead(InputStream stream, int size, byte[] prefix) 12 | throws IOException { 13 | var skip = prefix != null ? prefix.length : 0; 14 | size += skip; 15 | var buffer = new byte[size]; 16 | int got; 17 | if (prefix == null) { 18 | got = stream.read(buffer); 19 | } else { 20 | buffer = Arrays.copyOf(prefix, size); 21 | var tmp = stream.read(buffer, skip, size - skip); 22 | got = tmp + skip; 23 | } 24 | if (size != got) { 25 | throw new UnsupportedOperationException(size + " != " + got); 26 | } 27 | return buffer; 28 | } 29 | 30 | public static byte[] readWithSize(InputStream stream) throws IOException { 31 | var sizeBytes = tryRead(stream, 4, null); 32 | var size = BitConverter.toInt32(sizeBytes); 33 | var bytes = tryRead(stream, size, sizeBytes); 34 | return bytes; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Client/Tools/ServiceEnv.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace JNetCall.Sharp.Client.Tools 5 | { 6 | public static class ServiceEnv 7 | { 8 | private static string GetBaseFolder() 9 | { 10 | var baseDir = AppContext.BaseDirectory; 11 | var sep = Path.DirectorySeparatorChar; 12 | var parts = new[] { "net6.0", "Debug", "Release", "bin" }; 13 | foreach (var part in parts) 14 | { 15 | var tmp = sep + part + sep; 16 | if (!baseDir.EndsWith(tmp)) 17 | continue; 18 | baseDir = baseDir[..^tmp.Length] + sep; 19 | } 20 | return baseDir; 21 | } 22 | 23 | public static string BuildPath(string path) 24 | { 25 | var baseDir = GetBaseFolder(); 26 | var destDir = Path.Combine(baseDir, FixSlash(path)); 27 | var target = Path.GetFullPath(destDir); 28 | return target; 29 | } 30 | 31 | private static string FixSlash(string path) 32 | { 33 | var sep = Path.DirectorySeparatorChar; 34 | return path.Replace('/', sep) 35 | .Replace('\\', sep); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/Client/JvmContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using JNetHotel.Sharp; 4 | 5 | namespace JNetCall.Sharp.Client 6 | { 7 | public sealed class JvmContainer : IDisposable 8 | { 9 | private readonly Jvm _vm; 10 | 11 | public JvmContainer(string jar) 12 | { 13 | _vm = SetupJvm(jar); 14 | } 15 | 16 | private static Jvm SetupJvm(string jar) 17 | { 18 | var vmRef = Natives.GetVmRef(); 19 | vmRef.LoadLib(); 20 | var jvm = new Jvm(vmRef, jar); 21 | InstallStop(jvm); 22 | return jvm; 23 | } 24 | 25 | private static void InstallStop(IDisposable vm) 26 | { 27 | var domain = AppDomain.CurrentDomain; 28 | domain.ProcessExit += (_, _) => vm.Dispose(); 29 | } 30 | 31 | public byte[] SendAndGetArray(byte[] input) 32 | { 33 | var args = new List { input }; 34 | const string type = "Lx/Boot;"; 35 | var output = _vm.CallStaticMethod(type, "call", "([B)[B", args); 36 | return output; 37 | } 38 | 39 | public void Dispose() 40 | { 41 | // NO-OP 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/JNetCall.Sharp.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | all 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Impl/Util/ClassTools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using JNetBase.Sharp.Meta; 4 | using JNetCall.Sharp.API.Flow; 5 | 6 | namespace JNetCall.Sharp.Impl.Util 7 | { 8 | public sealed class ClassTools 9 | { 10 | private const string AsyncAdd = "_A"; 11 | 12 | public static (string, string) ToMethodId(MethodCall call) 13 | { 14 | var name = call.M.Replace("_", string.Empty); 15 | var count = call.A.Length; 16 | var id = (name + "_" + count).ToLowerInvariant(); 17 | var ida = (id + AsyncAdd).ToLowerInvariant(); 18 | return (ida, id); 19 | } 20 | 21 | public static string ToMethodId(MethodInfo method) 22 | { 23 | var name = method.Name.Replace("_", string.Empty); 24 | var count = method.GetParameters().Length; 25 | var suffix = Reflect.IsAsync(method) ? AsyncAdd : string.Empty; 26 | var id = (name + "_" + count + suffix).ToLowerInvariant(); 27 | return id; 28 | } 29 | 30 | public static string ToDelegateId(Delegate del) 31 | { 32 | var hash = del.Target?.GetHashCode() ?? 0; 33 | var method = del.Method; 34 | return hash + "#" + method; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-stdio/src/main/java/jnetcall/java/server/ServiceHosts.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.server; 2 | 3 | import jnetbase.java.meta.Reflect; 4 | import jnetbase.java.threads.ThreadExecutor; 5 | import jnetcall.java.api.io.ISendTransport; 6 | import jnetcall.java.common.ByteMarks; 7 | import jnetcall.java.impl.enc.BinaryEncoding; 8 | import jnetcall.java.impl.io.StreamTransport; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | public final class ServiceHosts { 15 | 16 | public static ClassHosting create(Class serviceClass) throws IOException { 17 | var stdIn = System.in; 18 | var stdOut = System.out; 19 | ByteMarks.writeSync(stdIn, stdOut); 20 | var protocol = initDefault(stdIn, stdOut); 21 | return create(serviceClass, protocol); 22 | } 23 | 24 | private static ISendTransport initDefault(InputStream stdIn, OutputStream stdOut) { 25 | var enc = new BinaryEncoding(); 26 | return new StreamTransport(enc, stdIn, stdOut); 27 | } 28 | 29 | private static ClassHosting create(Class serviceClass, ISendTransport protocol) { 30 | var instance = Reflect.createNew(serviceClass); 31 | var pool = new ThreadExecutor(); 32 | var host = new ClassHosting(instance, protocol, pool); 33 | return host; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Impl/IO/StreamTransport.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using JNetBase.Sharp.IO; 3 | using JNetCall.Sharp.API.Enc; 4 | using JNetCall.Sharp.API.IO; 5 | 6 | namespace JNetCall.Sharp.Impl.IO 7 | { 8 | public sealed class StreamTransport : IPullTransport 9 | { 10 | private readonly IEncoding _encoding; 11 | private readonly Stream _streamIn; 12 | private readonly Stream _streamOut; 13 | 14 | public StreamTransport(IEncoding encoding, 15 | Stream streamIn, Stream streamOut) 16 | { 17 | _encoding = encoding; 18 | _streamIn = streamIn; 19 | _streamOut = streamOut; 20 | } 21 | 22 | public void Send(T payload) 23 | { 24 | var bytes = _encoding.Encode(payload); 25 | _streamOut.Write(bytes, 0, bytes.Length); 26 | _streamOut.Flush(); 27 | if (_streamOut is IRewindable r) 28 | r.Rewind(bytes.Length); 29 | } 30 | 31 | public T Pull() 32 | { 33 | var bytes = StreamTools.ReadWithSize(_streamIn); 34 | return _encoding.Decode(bytes); 35 | } 36 | 37 | public void Dispose() 38 | { 39 | _streamOut.Dispose(); 40 | _streamIn.Dispose(); 41 | _encoding.Dispose(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/Sys/Arrays.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace JNetBase.Sharp.Sys 7 | { 8 | public static class Arrays 9 | { 10 | public static string ToString(IEnumerable items) 11 | { 12 | return $"[{string.Join(", ", items)}]"; 13 | } 14 | 15 | public static object[] AsObjectArray(IEnumerable items) 16 | { 17 | return items.Cast().ToArray(); 18 | } 19 | 20 | public static Array AsTypedArray(object[] args, Type type, Func convert = null) 21 | { 22 | convert ??= Convert.ChangeType; 23 | var array = Array.CreateInstance(type, args.Length); 24 | for (var i = 0; i < args.Length; i++) 25 | array.SetValue(convert(args[i], type), i); 26 | return array; 27 | } 28 | 29 | private static readonly Type ListType = typeof(List<>); 30 | 31 | public static IList AsTypedArrayList(object[] args, Type type, Func convert = null) 32 | { 33 | convert ??= Convert.ChangeType; 34 | var list = (IList)Activator.CreateInstance(ListType.MakeGenericType(type))!; 35 | foreach (var arg in args) 36 | list.Add(convert(arg, type)); 37 | return list; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /JVM/jnetproto-java/src/main/java/jnetproto/java/api/IDataReader.java: -------------------------------------------------------------------------------- 1 | package jnetproto.java.api; 2 | 3 | import org.javatuples.Tuple; 4 | 5 | import java.io.IOException; 6 | import java.math.BigDecimal; 7 | import java.time.Duration; 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Set; 12 | import java.util.UUID; 13 | 14 | public interface IDataReader extends AutoCloseable { 15 | boolean readBool() throws IOException; 16 | byte readI8() throws IOException; 17 | short readI16() throws IOException; 18 | int readI32() throws IOException; 19 | long readI64() throws IOException; 20 | float readF32() throws IOException; 21 | double readF64() throws IOException; 22 | BigDecimal readF128() throws IOException; 23 | char readChar() throws IOException; 24 | String readUtf8() throws IOException; 25 | Duration readDuration() throws IOException; 26 | LocalDateTime readTimestamp() throws IOException; 27 | UUID readGuid() throws IOException; 28 | Object readArray() throws IOException; 29 | Map readMap() throws IOException; 30 | Tuple readTuple() throws IOException; 31 | Set readSet() throws IOException; 32 | List readList() throws IOException; 33 | Object[] readBag() throws IOException; 34 | byte[] readBinary() throws IOException; 35 | Object readNull(); 36 | Object readObject() throws IOException; 37 | } 38 | -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/Meta/Reflect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | using System.Threading.Tasks; 5 | 6 | namespace JNetBase.Sharp.Meta 7 | { 8 | public static class Reflect 9 | { 10 | public static bool IsAsync(MethodInfo method) 11 | { 12 | return IsAsync(method.ReturnType); 13 | } 14 | 15 | public static bool IsAsync(Type ret) 16 | { 17 | return ret.IsAssignableTo(typeof(Task)) || ret.IsAssignableTo(typeof(ValueTask)); 18 | } 19 | 20 | public static bool IsDelegate(Type ret) 21 | { 22 | return ret.IsAssignableTo(typeof(Delegate)); 23 | } 24 | 25 | public static Type GetTaskType(Type taskType, Type defaultArg = null) 26 | { 27 | var taskArg = taskType.GetGenericArguments().FirstOrDefault(); 28 | if (taskArg == null) 29 | { 30 | return defaultArg ?? typeof(object); 31 | } 32 | return taskArg; 33 | } 34 | 35 | public static MethodInfo GetMethod(Func func) 36 | { 37 | var dest = func.Target!; 38 | var type = dest.GetType(); 39 | var field = type.GetField("method")!; 40 | var raw = field.GetValue(func.Target); 41 | var method = (MethodInfo)raw; 42 | return method; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/impl/io/net/NetworkTools.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.impl.io.net; 2 | 3 | import java.io.IOException; 4 | import java.net.InetSocketAddress; 5 | import java.net.SocketAddress; 6 | import java.nio.ByteBuffer; 7 | import java.nio.ByteOrder; 8 | import java.nio.channels.ReadableByteChannel; 9 | 10 | public final class NetworkTools { 11 | 12 | public static SocketAddress toEndPoint(String host, int port) { 13 | var addr = new InetSocketAddress(host, port); 14 | return addr; 15 | } 16 | 17 | private static ByteBuffer tryRead(ReadableByteChannel stream, int size, ByteBuffer prefix) 18 | throws IOException 19 | { 20 | var skip = prefix != null ? prefix.capacity() : 0; 21 | size += skip; 22 | var buffer = ByteBuffer.allocate(size); 23 | int got; 24 | if (prefix == null) { 25 | got = stream.read(buffer); 26 | } else { 27 | buffer.put(prefix.position(0)); 28 | var tmp = stream.read(buffer); 29 | got = tmp + skip; 30 | } 31 | if (size != got) { 32 | throw new UnsupportedOperationException(size + " != " + got); 33 | } 34 | buffer.position(0); 35 | return buffer; 36 | } 37 | 38 | public static ByteBuffer readWithSize(ReadableByteChannel stream) throws IOException { 39 | var sizeBytes = tryRead(stream, 4, null); 40 | var size = sizeBytes.order(ByteOrder.nativeOrder()).getInt(); 41 | var bytes = tryRead(stream, size, sizeBytes); 42 | return bytes; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.StdIO/Server/ServiceHosts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using JNetBase.Sharp.Threads; 4 | using JNetCall.Sharp.API.IO; 5 | using JNetCall.Sharp.Common; 6 | using JNetCall.Sharp.Impl.Enc; 7 | using JNetCall.Sharp.Impl.IO; 8 | 9 | namespace JNetCall.Sharp.Server 10 | { 11 | public static class ServiceHosts 12 | { 13 | public static ClassHosting Create() where T : new() 14 | { 15 | var stdIn = Console.OpenStandardInput(); 16 | var stdOut = Console.OpenStandardOutput(); 17 | return Create(stdIn, stdOut); 18 | } 19 | 20 | public static ClassHosting Create(Stream stdIn, Stream stdOut) 21 | where T : new() 22 | { 23 | ByteMarks.WriteSync(stdIn, stdOut); 24 | var protocol = InitDefault(stdIn, stdOut); 25 | return Create(protocol); 26 | } 27 | 28 | private static ISendTransport InitDefault(Stream stdIn, Stream stdOut) 29 | { 30 | var enc = new BinaryEncoding(); 31 | return new StreamTransport(enc, stdIn, stdOut); 32 | } 33 | 34 | private static ClassHosting Create(ISendTransport protocol) where T : new() 35 | { 36 | var instance = new T(); 37 | var pool = new ThreadExecutor(); 38 | var host = new ClassHosting(instance, protocol, pool); 39 | return host; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/bsd/BsdCoreClr.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.bsd; 2 | 3 | import com.sun.jna.Function; 4 | import jnethotel.java.interop.BaseCoreClr; 5 | import jnethotel.java.interop.api.hostfxr_delegate_type; 6 | import jnethotel.java.linux.impl.hostfxr_initialize_parameters_unix.ByReference; 7 | import jnethotel.java.linux.impl.hostfxr_library_unix; 8 | import jnethotel.java.linux.impl.nethost_library_unix; 9 | 10 | import java.nio.ByteBuffer; 11 | 12 | class BsdCoreClr extends BaseCoreClr { 13 | 14 | BsdCoreClr(nethost_library_unix instance) 15 | { 16 | nethost_library = instance; 17 | funcFlags = Function.C_CONVENTION; 18 | hdt_load_assembly_and_get_function_pointer = hostfxr_delegate_type.hdt_load_assembly_and_get_function_pointer; 19 | } 20 | 21 | @Override 22 | protected String wrap(String java) { 23 | return java; 24 | } 25 | 26 | @Override 27 | protected ByteBuffer allocate(int size) { 28 | return ByteBuffer.allocate(size); 29 | } 30 | 31 | @Override 32 | protected String toString(ByteBuffer buffer) { 33 | return new String(buffer.array()); 34 | } 35 | 36 | @Override 37 | protected Class getHostFxrClass() { 38 | return hostfxr_library_unix.class; 39 | } 40 | 41 | @Override 42 | protected ByReference createByRef() { 43 | return new ByReference(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/io/FileTransportTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests.io; 2 | 3 | import jnetbase.java.threads.ThreadExecutor; 4 | import jnetcall.java.api.io.ISendTransport; 5 | import jnetcall.java.impl.io.disk.FolderTransport; 6 | import org.javatuples.Pair; 7 | 8 | import java.nio.file.Path; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | 11 | public final class FileTransportTest extends TransportTest { 12 | 13 | private final String Folder = "FileTmp"; 14 | 15 | private static AtomicInteger _offset = new AtomicInteger(); 16 | 17 | private static int getNextOffset() { 18 | return _offset.incrementAndGet(); 19 | } 20 | 21 | @Override 22 | protected Pair getBoth() { 23 | var offset = getNextOffset(); 24 | var first = Path.of(Folder, 13001 + offset + ""); 25 | var second = Path.of(Folder, 13051 + offset + ""); 26 | var exe = new ThreadExecutor(); 27 | var left = new FolderTransport( 28 | Encoding, 29 | first, 30 | second, 31 | exe 32 | ); 33 | var right = new FolderTransport( 34 | Encoding, 35 | second, 36 | first, 37 | exe 38 | ); 39 | return Pair.with(left, right); 40 | } 41 | 42 | @Override 43 | protected int getMaxListWait() { return 20; } 44 | } 45 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/LinuxCoreClr.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux; 2 | 3 | import com.sun.jna.Function; 4 | import jnethotel.java.interop.BaseCoreClr; 5 | import jnethotel.java.interop.api.hostfxr_delegate_type; 6 | import jnethotel.java.linux.impl.hostfxr_initialize_parameters_unix.ByReference; 7 | import jnethotel.java.linux.impl.hostfxr_library_unix; 8 | import jnethotel.java.linux.impl.nethost_library_unix; 9 | 10 | import java.nio.ByteBuffer; 11 | 12 | class LinuxCoreClr extends BaseCoreClr { 13 | 14 | LinuxCoreClr(nethost_library_unix instance) 15 | { 16 | nethost_library = instance; 17 | funcFlags = Function.C_CONVENTION; 18 | hdt_load_assembly_and_get_function_pointer = hostfxr_delegate_type.hdt_load_assembly_and_get_function_pointer; 19 | } 20 | 21 | @Override 22 | protected String wrap(String java) { 23 | return java; 24 | } 25 | 26 | @Override 27 | protected ByteBuffer allocate(int size) { 28 | return ByteBuffer.allocate(size); 29 | } 30 | 31 | @Override 32 | protected String toString(ByteBuffer buffer) { 33 | return new String(buffer.array()); 34 | } 35 | 36 | @Override 37 | protected Class getHostFxrClass() { 38 | return hostfxr_library_unix.class; 39 | } 40 | 41 | @Override 42 | protected ByReference createByRef() { 43 | return new ByReference(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/bsd/BsdVmRef.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.bsd; 2 | 3 | import com.sun.jna.Native; 4 | import com.sun.jna.NativeLibrary; 5 | import jnethotel.java.api.ICoreClr; 6 | import jnethotel.java.api.IVmRef; 7 | import jnethotel.java.linux.impl.nethost_library_unix; 8 | 9 | import java.io.IOException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | 13 | public final class BsdVmRef implements IVmRef { 14 | 15 | private final String DllName = "libnethost.so"; 16 | 17 | @Override 18 | public String getVmDll() { 19 | return DllName; 20 | } 21 | 22 | private NativeLibrary nativeLibrary; 23 | private nethost_library_unix instance; 24 | 25 | @Override 26 | public void loadLib() throws IOException { 27 | var libFileName = getVmDll(); 28 | var libRoot = Path.of("/usr/share/dotnet"); 29 | var libPath = Files.find(libRoot, 7, 30 | (p, b) -> p.getFileName().toString().equals(libFileName)) 31 | .findFirst().orElseThrow().getParent().toString(); 32 | System.setProperty("jna.library.path", libPath); 33 | 34 | final String jnaLibraryName = "nethost"; 35 | nativeLibrary = NativeLibrary.getInstance(jnaLibraryName); 36 | instance = Native.load(jnaLibraryName, nethost_library_unix.class); 37 | } 38 | 39 | @Override 40 | public ICoreClr getCoreClr() { 41 | return new BsdCoreClr(instance); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/linux/LinuxVmRef.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.linux; 2 | 3 | import com.sun.jna.Native; 4 | import com.sun.jna.NativeLibrary; 5 | import jnethotel.java.api.ICoreClr; 6 | import jnethotel.java.api.IVmRef; 7 | import jnethotel.java.linux.impl.nethost_library_unix; 8 | 9 | import java.io.IOException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | 13 | public final class LinuxVmRef implements IVmRef { 14 | 15 | private final String DllName = "libnethost.so"; 16 | 17 | @Override 18 | public String getVmDll() { 19 | return DllName; 20 | } 21 | 22 | private NativeLibrary nativeLibrary; 23 | private nethost_library_unix instance; 24 | 25 | @Override 26 | public void loadLib() throws IOException { 27 | var libFileName = getVmDll(); 28 | var libRoot = Path.of("/usr/share/dotnet"); 29 | var libPath = Files.find(libRoot, 7, 30 | (p, b) -> p.getFileName().toString().equals(libFileName)) 31 | .findFirst().orElseThrow().getParent().toString(); 32 | System.setProperty("jna.library.path", libPath); 33 | 34 | final String jnaLibraryName = "nethost"; 35 | nativeLibrary = NativeLibrary.getInstance(jnaLibraryName); 36 | instance = Native.load(jnaLibraryName, nethost_library_unix.class); 37 | } 38 | 39 | @Override 40 | public ICoreClr getCoreClr() { 41 | return new LinuxCoreClr(instance); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/mac/MacVmRef.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.mac; 2 | 3 | import com.sun.jna.Native; 4 | import com.sun.jna.NativeLibrary; 5 | import jnethotel.java.api.ICoreClr; 6 | import jnethotel.java.api.IVmRef; 7 | import jnethotel.java.linux.impl.nethost_library_unix; 8 | 9 | import java.io.IOException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | 13 | public final class MacVmRef implements IVmRef { 14 | 15 | private final String DllName = "libnethost.dylib"; 16 | 17 | @Override 18 | public String getVmDll() { 19 | return DllName; 20 | } 21 | 22 | private NativeLibrary nativeLibrary; 23 | private nethost_library_unix instance; 24 | 25 | @Override 26 | public void loadLib() throws IOException { 27 | var libFileName = getVmDll(); 28 | var libRoot = Path.of("/usr/local/share/dotnet/"); 29 | var libPath = Files.find(libRoot, 7, 30 | (p, b) -> p.getFileName().toString().equals(libFileName)) 31 | .findFirst().orElseThrow().getParent().toString(); 32 | System.setProperty("jna.library.path", libPath); 33 | 34 | final String jnaLibraryName = "nethost"; 35 | nativeLibrary = NativeLibrary.getInstance(jnaLibraryName); 36 | instance = Native.load(jnaLibraryName, nethost_library_unix.class); 37 | } 38 | 39 | @Override 40 | public ICoreClr getCoreClr() { 41 | return new MacCoreClr(instance); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /JVM/jnetproto-java/src/main/java/jnetproto/java/tools/Tuples.java: -------------------------------------------------------------------------------- 1 | package jnetproto.java.tools; 2 | 3 | import org.javatuples.*; 4 | 5 | public final class Tuples { 6 | 7 | public static Octet create( 8 | T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g, T8 h) { 9 | return Octet.with(a, b, c, d, e, f, g, h); 10 | } 11 | 12 | public static Septet create( 13 | T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g) { 14 | return Septet.with(a, b, c, d, e, f, g); 15 | } 16 | 17 | public static Sextet create( 18 | T1 a, T2 b, T3 c, T4 d, T5 e, T6 f) { 19 | return Sextet.with(a, b, c, d, e, f); 20 | } 21 | 22 | public static Quintet create(T1 a, T2 b, T3 c, T4 d, T5 e) { 23 | return Quintet.with(a, b, c, d, e); 24 | } 25 | 26 | public static Quartet create(T1 a, T2 b, T3 c, T4 d) { 27 | return Quartet.with(a, b, c, d); 28 | } 29 | 30 | public static Triplet create(T1 a, T2 b, T3 c) { 31 | return Triplet.with(a, b, c); 32 | } 33 | 34 | public static Pair create(T1 a, T2 b) { 35 | return Pair.with(a, b); 36 | } 37 | 38 | public static Unit create(T1 a) { 39 | return Unit.with(a); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /NET/JNetBase.Sharp/Threads/SingleThread.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Threading; 4 | 5 | namespace JNetBase.Sharp.Threads 6 | { 7 | public sealed class SingleThread : IDisposable 8 | where T : IDisposable 9 | { 10 | private readonly Func _creator; 11 | private readonly BlockingCollection> _actions; 12 | private readonly Thread _thread; 13 | 14 | private bool _running; 15 | 16 | public SingleThread(Func creator) 17 | { 18 | _creator = creator; 19 | _actions = new BlockingCollection>(); 20 | _running = true; 21 | _thread = new Thread(DoLoop) 22 | { 23 | IsBackground = true 24 | }; 25 | _thread.Start(); 26 | } 27 | 28 | public void Dispose() 29 | { 30 | _running = false; 31 | _thread.Interrupt(); 32 | _actions.Dispose(); 33 | } 34 | 35 | ~SingleThread() 36 | { 37 | Dispose(); 38 | } 39 | 40 | public void Execute(Action action) 41 | { 42 | _actions.Add(action); 43 | } 44 | 45 | private void DoLoop() 46 | { 47 | using var instance = _creator(); 48 | while (_running) 49 | { 50 | var action = _actions.Take(); 51 | action(instance); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/impl/util/ClassTools.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.impl.util; 2 | 3 | import jnetbase.java.meta.Reflect; 4 | import jnetcall.java.api.flow.MethodCall; 5 | import org.javatuples.Pair; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | public final class ClassTools { 10 | 11 | private static final String AsyncAdd = "_A"; 12 | 13 | public static Pair toMethodId(MethodCall call) { 14 | var name = call.M().replace("_", ""); 15 | var count = call.A().length; 16 | var id = (name + "_" + count).toLowerCase(); 17 | var ida = (id + AsyncAdd).toLowerCase(); 18 | return Pair.with(ida, id); 19 | } 20 | 21 | public static String toMethodId(Method method) { 22 | var name = method.getName().replace("_", ""); 23 | var count = method.getParameters().length; 24 | var suffix = Reflect.isAsync(method) ? AsyncAdd : ""; 25 | var id = (name + "_" + count + suffix).toLowerCase(); 26 | return id; 27 | } 28 | 29 | public static boolean isSameMethod(Method m, String callName) { 30 | var mName = m.getName().replace("_", ""); 31 | return mName.equalsIgnoreCase(callName); 32 | } 33 | 34 | public static String toDelegateId(Object del) { 35 | var hash = del.hashCode(); 36 | var type = del.getClass(); 37 | var interf = type.getInterfaces()[0]; 38 | var method = interf.getMethods()[0]; 39 | return hash + "#" + method; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-inproc/src/main/java/jnetcall/java/server/ServiceLots.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.server; 2 | 3 | import jnetbase.java.meta.Reflect; 4 | import jnetbase.java.threads.ThreadExecutor; 5 | import jnetcall.java.api.ICaller; 6 | import jnetcall.java.api.io.ISendTransport; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public final class ServiceLots { 13 | 14 | public static ClassHosting create(Class serviceClass) { 15 | var protocol = new ServiceLot(); 16 | register(protocol); 17 | return create(serviceClass, protocol); 18 | } 19 | 20 | private static ClassHosting create(Class serviceClass, ISendTransport protocol) { 21 | var instance = Reflect.createNew(serviceClass); 22 | var pool = new ThreadExecutor(); 23 | var host = new ClassHosting(instance, protocol, pool); 24 | return host; 25 | } 26 | 27 | private static final List lots = new ArrayList<>(); 28 | 29 | private static void register(ICaller lot) { 30 | lots.add(lot); 31 | } 32 | 33 | @SuppressWarnings("unused") 34 | public static byte[] call(byte[] input) throws Exception { 35 | for (var lot : lots) 36 | try (var output = new ByteArrayOutputStream()) { 37 | if (!lot.tryCall(input, output)) 38 | continue; 39 | return output.toByteArray(); 40 | } 41 | return new byte[]{-1}; 42 | } 43 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/WinCoreClr.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows; 2 | 3 | import com.sun.jna.Function; 4 | import com.sun.jna.WString; 5 | import jnethotel.java.interop.BaseCoreClr; 6 | import jnethotel.java.interop.api.hostfxr_delegate_type; 7 | import jnethotel.java.windows.impl.hostfxr_initialize_parameters_windows.ByReference; 8 | import jnethotel.java.windows.impl.hostfxr_library_windows; 9 | import jnethotel.java.windows.impl.nethost_library_windows; 10 | 11 | import java.nio.CharBuffer; 12 | 13 | class WinCoreClr extends BaseCoreClr { 14 | 15 | WinCoreClr(nethost_library_windows instance) 16 | { 17 | nethost_library = instance; 18 | funcFlags = Function.ALT_CONVENTION; 19 | hdt_load_assembly_and_get_function_pointer = hostfxr_delegate_type.hdt_load_assembly_and_get_function_pointer; 20 | } 21 | 22 | @Override 23 | protected WString wrap(String java) { 24 | return new WString(java); 25 | } 26 | 27 | @Override 28 | protected CharBuffer allocate(int size) { 29 | return CharBuffer.allocate(size); 30 | } 31 | 32 | @Override 33 | protected String toString(CharBuffer buffer) { 34 | return new String(buffer.array()); 35 | } 36 | 37 | @Override 38 | protected Class getHostFxrClass() { 39 | return hostfxr_library_windows.class; 40 | } 41 | 42 | @Override 43 | protected ByReference createByRef() { 44 | return new ByReference(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/mac/MacCoreClr.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.mac; 2 | 3 | import com.sun.jna.Function; 4 | import jnethotel.java.interop.BaseCoreClr; 5 | import jnethotel.java.interop.api.hostfxr_delegate_type; 6 | import jnethotel.java.linux.impl.hostfxr_initialize_parameters_unix; 7 | import jnethotel.java.linux.impl.hostfxr_library_unix; 8 | import jnethotel.java.linux.impl.nethost_library_unix; 9 | 10 | import java.nio.ByteBuffer; 11 | 12 | class MacCoreClr extends BaseCoreClr { 13 | 14 | MacCoreClr(nethost_library_unix instance) { 15 | nethost_library = instance; 16 | funcFlags = Function.C_CONVENTION; 17 | hdt_load_assembly_and_get_function_pointer = hostfxr_delegate_type.hdt_load_assembly_and_get_function_pointer; 18 | } 19 | 20 | @Override 21 | protected String wrap(String java) { 22 | return java; 23 | } 24 | 25 | @Override 26 | protected ByteBuffer allocate(int size) { 27 | return ByteBuffer.allocate(size); 28 | } 29 | 30 | @Override 31 | protected String toString(ByteBuffer buffer) { 32 | return new String(buffer.array()); 33 | } 34 | 35 | @Override 36 | protected Class getHostFxrClass() { 37 | return hostfxr_library_unix.class; 38 | } 39 | 40 | @Override 41 | protected hostfxr_initialize_parameters_unix.ByReference createByRef() { 42 | return new hostfxr_initialize_parameters_unix.ByReference(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /NET/Aliens.Sharp/API/IMultiple.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Example.API 4 | { 5 | public interface IMultiple : IDisposable 6 | { 7 | Tuple GetTuple2T(int a, string b); 8 | (int, string) GetTuple2V(Tuple v); 9 | 10 | Tuple GetTuple3T(int a, string b, bool c); 11 | (int, string, bool) GetTuple3V(Tuple v); 12 | 13 | Tuple GetTuple4T(string a, string[] b, int c, int[] d); 14 | (string, string[], int, int[]) GetTuple4V(Tuple v); 15 | 16 | Tuple GetTuple5T(int a, float b, long c, string d, string e); 17 | (int, float, long, string, string) GetTuple5V(Tuple v); 18 | 19 | WeekDay FindBestDay(int value); 20 | Days FindFreeDays(); 21 | string GetTextOf(WeekDay[] taken, Days days); 22 | 23 | enum WeekDay 24 | { 25 | Monday = 1, 26 | Tuesday = 2, 27 | Wednesday = 3, 28 | Thursday = 4, 29 | Friday = 5, 30 | Saturday = 6, 31 | Sunday = 7 32 | } 33 | 34 | [Flags] 35 | enum Days 36 | { 37 | None = 0, 38 | Sunday = 1, 39 | Monday = 2, 40 | Tuesday = 4, 41 | Wednesday = 8, 42 | Thursday = 16, 43 | Friday = 32, 44 | Saturday = 64 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /JVM/alienator-java/src/main/java/org/example/Main.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import jnetcall.java.client.InProcClient; 4 | import org.example.api.ICalculator; 5 | 6 | import static jnetcall.java.client.tools.ServiceEnv.buildPath; 7 | 8 | public class Main { 9 | 10 | public static void main(String[] args) throws Exception { 11 | 12 | final String path = "..\\..\\..\\NET\\Alien2.Sharp\\bin\\Debug\\net6.0\\Alien2.Sharp.dll"; 13 | 14 | var client = InProcClient.create(ICalculator.class, buildPath(path)); 15 | System.out.println(" *** " + client.getName() + " on JVM *** "); 16 | 17 | var value1 = 100.00D; 18 | var value2 = 15.99D; 19 | var result = client.add(value1, value2); 20 | System.out.printf("Add(%s %s) = %s %n", value1, value2, result); 21 | 22 | value1 = 145.00D; 23 | value2 = 76.54D; 24 | result = client.subtract(value1, value2); 25 | System.out.printf("Subtract(%s %s) = %s %n", value1, value2, result); 26 | 27 | value1 = 9.00D; 28 | value2 = 81.25D; 29 | result = client.multiply(value1, value2); 30 | System.out.printf("Multiply(%s %s) = %s %n", value1, value2, result); 31 | 32 | value1 = 22.00D; 33 | value2 = 7.00D; 34 | result = client.divide(value1, value2); 35 | System.out.printf("Divide(%s %s) = %s %n", value1, value2, result); 36 | 37 | System.out.println("\nPress to terminate the client."); 38 | System.in.read(); 39 | client.close(); 40 | } 41 | } -------------------------------------------------------------------------------- /NET/Alienator.Sharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Example.API; 3 | using JNetCall.Sharp.Client; 4 | using static JNetCall.Sharp.Client.Tools.ServiceEnv; 5 | 6 | namespace Example 7 | { 8 | internal static class Program 9 | { 10 | private static void Main() 11 | { 12 | const string path = @"..\..\JVM\alien2-java\target\alien2-java.jar"; 13 | 14 | var client = InProcClient.Create(BuildPath(path)); 15 | Console.WriteLine(" *** " + client.Name + " on NET *** "); 16 | 17 | var value1 = 100.00D; 18 | var value2 = 15.99D; 19 | var result = client.Add(value1, value2); 20 | Console.WriteLine("Add({0} {1}) = {2}", value1, value2, result); 21 | 22 | value1 = 145.00D; 23 | value2 = 76.54D; 24 | result = client.Subtract(value1, value2); 25 | Console.WriteLine("Subtract({0} {1}) = {2}", value1, value2, result); 26 | 27 | value1 = 9.00D; 28 | value2 = 81.25D; 29 | result = client.Multiply(value1, value2); 30 | Console.WriteLine("Multiply({0} {1}) = {2}", value1, value2, result); 31 | 32 | value1 = 22.00D; 33 | value2 = 7.00D; 34 | result = client.Divide(value1, value2); 35 | Console.WriteLine("Divide({0} {1}) = {2}", value1, value2, result); 36 | 37 | Console.WriteLine("\nPress to terminate the client."); 38 | Console.ReadLine(); 39 | client.Dispose(); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/windows/WinVmRef.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.windows; 2 | 3 | import com.sun.jna.Native; 4 | import com.sun.jna.NativeLibrary; 5 | import jnethotel.java.api.ICoreClr; 6 | import jnethotel.java.api.IVmRef; 7 | import jnethotel.java.windows.impl.nethost_library_windows; 8 | 9 | import java.io.IOException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | 13 | public final class WinVmRef implements IVmRef { 14 | 15 | private final String DllName = "nethost.dll"; 16 | 17 | @Override 18 | public String getVmDll() { 19 | return DllName; 20 | } 21 | 22 | private NativeLibrary nativeLibrary; 23 | private nethost_library_windows instance; 24 | 25 | @Override 26 | public void loadLib() throws IOException { 27 | var libFileName = getVmDll(); 28 | var libRoot = Path.of("C:\\Program Files\\dotnet"); 29 | var libPath = Files.find(libRoot, 7, 30 | (p, b) -> p.getFileName().toString().equals(libFileName) && 31 | p.getParent().toString().contains("-x64")) 32 | .findFirst().orElseThrow().getParent().toString(); 33 | System.setProperty("jna.library.path", libPath); 34 | 35 | final String jnaLibraryName = "nethost"; 36 | nativeLibrary = NativeLibrary.getInstance(jnaLibraryName); 37 | instance = Native.load(jnaLibraryName, nethost_library_windows.class); 38 | } 39 | 40 | @Override 41 | public ICoreClr getCoreClr() { 42 | return new WinCoreClr(instance); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/impl/enc/BinaryEncoding.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.impl.enc; 2 | 3 | import jnetbase.java.meta.TypeToken; 4 | import jnetcall.java.api.enc.IByteEncoding; 5 | import jnetproto.java.beans.ProtoConvert; 6 | import jnetproto.java.beans.ProtoSettings; 7 | 8 | import java.io.ByteArrayInputStream; 9 | import java.io.ByteArrayOutputStream; 10 | 11 | public final class BinaryEncoding implements IByteEncoding { 12 | 13 | private final ProtoSettings _config; 14 | 15 | public BinaryEncoding() { 16 | _config = new ProtoSettings(); 17 | } 18 | 19 | @Override 20 | public byte[] encode(T data) throws Exception { 21 | try (var output = new ByteArrayOutputStream(); 22 | var proto = new ProtoConvert(null, output, _config)) { 23 | proto.writeObject(data); 24 | return output.toByteArray(); 25 | } 26 | } 27 | 28 | @Override 29 | public T decode(byte[] data, Class clazz) throws Exception { 30 | try (var input = new ByteArrayInputStream(data); 31 | var proto = new ProtoConvert(input, null, _config)) { 32 | var res = proto.readObject(clazz); 33 | return res; 34 | } 35 | } 36 | 37 | @Override 38 | public T decode(byte[] data, TypeToken token) throws Exception { 39 | try (var input = new ByteArrayInputStream(data); 40 | var proto = new ProtoConvert(input, null, _config)) { 41 | var res = proto.readObject(token); 42 | return res; 43 | } 44 | } 45 | 46 | @Override 47 | public void close() throws Exception { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/interop/api/hostfxr_library.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java.interop.api; 2 | 3 | import com.sun.jna.Library; 4 | import com.sun.jna.Pointer; 5 | import com.sun.jna.ptr.PointerByReference; 6 | 7 | public interface hostfxr_library extends Library { 8 | 9 | int hostfxr_main(int argc, PointerByReference argv); 10 | 11 | int hostfxr_main_startupinfo(int argc, PointerByReference argv, TString host_path, 12 | TString dotnet_root, TString app_path); 13 | 14 | hostfxr_error_writer_fn hostfxr_set_error_writer(hostfxr_error_writer_fn error_writer); 15 | 16 | int hostfxr_initialize_for_dotnet_command_line(int argc, PointerByReference argv, 17 | TByRef parameters, 18 | PointerByReference host_context_handle); 19 | 20 | int hostfxr_initialize_for_runtime_config(TString runtime_config_path, 21 | TByRef parameters, 22 | PointerByReference host_context_handle); 23 | 24 | int hostfxr_set_runtime_property_value(Pointer host_context_handle, TString name, TString value); 25 | 26 | int hostfxr_get_runtime_properties(Pointer host_context_handle, PointerByReference count, 27 | PointerByReference keys, PointerByReference values); 28 | 29 | int hostfxr_run_app(Pointer host_context_handle); 30 | 31 | int hostfxr_get_runtime_delegate(Pointer host_context_handle, int type, PointerByReference delegate); 32 | 33 | int hostfxr_close(Pointer host_context_handle); 34 | } 35 | -------------------------------------------------------------------------------- /JVM/jnetproto-java/src/main/java/jnetproto/java/api/IDataWriter.java: -------------------------------------------------------------------------------- 1 | package jnetproto.java.api; 2 | 3 | import org.javatuples.Tuple; 4 | 5 | import java.io.IOException; 6 | import java.math.BigDecimal; 7 | import java.time.Duration; 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Set; 12 | import java.util.UUID; 13 | 14 | public interface IDataWriter extends AutoCloseable { 15 | void writeBool(boolean value) throws IOException; 16 | void writeI8(byte value) throws IOException; 17 | void writeI16(short value) throws IOException; 18 | void writeI32(int value) throws IOException; 19 | void writeI64(long value) throws IOException; 20 | void writeF32(float value) throws IOException; 21 | void writeF64(double value) throws IOException; 22 | void writeF128(BigDecimal value) throws IOException; 23 | void writeChar(char value) throws IOException; 24 | void writeUtf8(String value) throws IOException; 25 | void writeDuration(Duration value) throws IOException; 26 | void writeTimestamp(LocalDateTime value) throws IOException; 27 | void writeGuid(UUID value) throws IOException; 28 | void writeArray(Object value) throws IOException; 29 | void writeMap(Map value) throws IOException; 30 | void writeTuple(Tuple value) throws IOException; 31 | void writeSet(Set value) throws IOException; 32 | void writeList(List value) throws IOException; 33 | void writeBag(Object[] value) throws IOException; 34 | void writeBinary(byte[] value) throws IOException; 35 | void writeNull(); 36 | void writeObject(Object value) throws IOException; 37 | void flush() throws IOException; 38 | } 39 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Impl/IO/Net/UdpTransport.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Net.Sockets; 3 | using JNetCall.Sharp.API.Enc; 4 | using JNetCall.Sharp.API.IO; 5 | 6 | namespace JNetCall.Sharp.Impl.IO.Net 7 | { 8 | public sealed class UdpTransport : IPullTransport 9 | { 10 | private readonly IEncoding _encoding; 11 | private readonly UdpClient _receiver; 12 | private readonly UdpClient _sender; 13 | 14 | public UdpTransport(IEncoding encoding, 15 | string hostIn, int portIn, string hostOut, int portOut) 16 | : this(encoding, NetworkTools.ToEndPoint(hostIn, portIn), 17 | NetworkTools.ToEndPoint(hostOut, portOut)) 18 | { 19 | } 20 | 21 | private UdpTransport(IEncoding encoding, 22 | IPEndPoint endPointIn, IPEndPoint endPointOut) 23 | { 24 | _encoding = encoding; 25 | _receiver = new UdpClient(endPointIn); 26 | _sender = new UdpClient(); 27 | _sender.Connect(endPointOut); 28 | } 29 | 30 | public void Send(T payload) 31 | { 32 | var bytes = _encoding.Encode(payload); 33 | _sender.Send(bytes, bytes.Length); 34 | } 35 | 36 | private IPEndPoint _remote; 37 | 38 | public T Pull() 39 | { 40 | var bytes = _receiver.Receive(ref _remote); 41 | return _encoding.Decode(bytes); 42 | } 43 | 44 | public void Dispose() 45 | { 46 | _encoding.Dispose(); 47 | _sender.Close(); 48 | _sender.Dispose(); 49 | _receiver.Close(); 50 | _receiver.Dispose(); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/server/model/DelegateWrap.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.server.model; 2 | 3 | import jnetbase.java.meta.Reflect; 4 | import jnetcall.java.server.api.IHosting; 5 | 6 | import java.lang.reflect.InvocationHandler; 7 | import java.lang.reflect.Method; 8 | 9 | public final class DelegateWrap implements InvocationHandler { 10 | 11 | private final IHosting _host; 12 | private final short _id; 13 | private final Class _delType; 14 | 15 | public DelegateWrap(IHosting host, short id, Class delType) { 16 | _host = host; 17 | _id = id; 18 | _delType = delType; 19 | } 20 | 21 | @Override 22 | public Object invoke(Object proxy, Method method, Object[] args) { 23 | var owner = method.getDeclaringClass(); 24 | if (owner.equals(_delType)) { 25 | var retType = method.getReturnType(); 26 | var res = _host.goDynInvoke(retType, _id, args); 27 | return res; 28 | } 29 | if (owner.equals(Object.class)) { 30 | var name = method.getName(); 31 | if (name.equals("toString")) 32 | return getId(); 33 | if (name.equals("equals")) 34 | return isEqual(args[0]); 35 | } 36 | throw new RuntimeException(_id + ", " + method + ", " + args); 37 | } 38 | 39 | private String getId() { 40 | return "Delegate<" + _delType.getName() + ">#" + _id; 41 | } 42 | 43 | private boolean isEqual(Object obj) { 44 | if (Reflect.getProxyHandler(obj) instanceof DelegateWrap other) { 45 | if (getId().equals(other.getId())) 46 | return true; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/threads/SingleThread.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.threads; 2 | 3 | import java.util.concurrent.BlockingQueue; 4 | import java.util.concurrent.LinkedBlockingQueue; 5 | import java.util.function.Consumer; 6 | import java.util.function.Supplier; 7 | 8 | public final class SingleThread 9 | implements AutoCloseable { 10 | 11 | private final Supplier _creator; 12 | private final BlockingQueue> _actions; 13 | private final Thread _thread; 14 | 15 | private boolean _running; 16 | 17 | public SingleThread(Supplier creator) { 18 | _creator = creator; 19 | _actions = new LinkedBlockingQueue>(); 20 | _running = true; 21 | _thread = new Thread(this::doLoop); 22 | _thread.setDaemon(true); 23 | _thread.start(); 24 | } 25 | 26 | @Override 27 | public void close() throws Exception { 28 | _running = false; 29 | _thread.interrupt(); 30 | _actions.clear(); 31 | } 32 | 33 | @SuppressWarnings("removal") 34 | @Override 35 | protected void finalize() throws Throwable { 36 | close(); 37 | super.finalize(); 38 | } 39 | 40 | public void execute(Consumer action) { 41 | _actions.add(action); 42 | } 43 | 44 | private void doLoop() { 45 | try { 46 | doMyLoop(); 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | private void doMyLoop() throws Exception { 53 | try (var instance = _creator.get()) { 54 | while (_running) { 55 | var action = _actions.take(); 56 | action.accept(instance); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/Server/ServiceLots.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using JNetBase.Sharp.Threads; 5 | using JNetCall.Sharp.API; 6 | using JNetCall.Sharp.API.IO; 7 | using JNetCall.Sharp.Tools; 8 | 9 | namespace JNetCall.Sharp.Server 10 | { 11 | public static class ServiceLots 12 | { 13 | public static ClassHosting Create() where T : new() 14 | { 15 | var protocol = new ServiceLot(); 16 | Register(protocol); 17 | return Create(protocol); 18 | } 19 | 20 | private static ClassHosting Create(ISendTransport protocol) where T : new() 21 | { 22 | var instance = new T(); 23 | var pool = new ThreadExecutor(); 24 | var host = new ClassHosting(instance, protocol, pool); 25 | return host; 26 | } 27 | 28 | private static readonly IList Lots = new List(); 29 | 30 | private static void Register(ICaller lot) 31 | { 32 | Lots.Add(lot); 33 | } 34 | 35 | // ReSharper disable UnusedMember.Global 36 | private static byte[] Call(byte[] input) 37 | { 38 | foreach (var lot in Lots) 39 | { 40 | using var output = new MemoryStream(); 41 | if (!lot.TryCall(input, output)) 42 | continue; 43 | return output.ToArray(); 44 | } 45 | return new[] { unchecked((byte)-1) }; 46 | } 47 | 48 | public static IntPtr Call(IntPtr inputPtr) 49 | { 50 | var input = Interop.ToByteArray(inputPtr); 51 | var output = Call(input); 52 | return Interop.ToPointer(output); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/impl/io/StreamTransport.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.impl.io; 2 | 3 | import jnetbase.java.io.IRewindable; 4 | import jnetcall.java.api.enc.IEncoding; 5 | import jnetcall.java.api.io.IPullTransport; 6 | import jnetcall.java.api.io.ISendTransport; 7 | 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | 11 | public final class StreamTransport implements ISendTransport, IPullTransport, AutoCloseable { 12 | 13 | private final IEncoding _encoding; 14 | private final InputStream _streamIn; 15 | private final OutputStream _streamOut; 16 | 17 | public StreamTransport(IEncoding encoding, 18 | InputStream streamIn, OutputStream streamOut) { 19 | _encoding = encoding; 20 | _streamIn = streamIn; 21 | _streamOut = streamOut; 22 | } 23 | 24 | @Override 25 | public T pull(Class clazz) { 26 | try { 27 | var bytes = StreamTools.readWithSize(_streamIn); 28 | return _encoding.decode(bytes, clazz); 29 | } catch (Exception e) { 30 | throw new RuntimeException(e); 31 | } 32 | } 33 | 34 | @Override 35 | public void send(T payload) { 36 | try { 37 | var bytes = _encoding.encode(payload); 38 | _streamOut.write(bytes, 0, bytes.length); 39 | _streamOut.flush(); 40 | if (_streamOut instanceof IRewindable r) 41 | r.rewind(bytes.length); 42 | } catch (Exception e) { 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | 47 | @Override 48 | public void close() throws Exception { 49 | _streamOut.close(); 50 | _streamIn.close(); 51 | _encoding.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/sys/ArrayX.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.sys; 2 | 3 | import java.lang.reflect.Array; 4 | import java.lang.reflect.Type; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.function.BiFunction; 8 | 9 | public final class ArrayX { 10 | 11 | public static ArrayList asObjectList(Iterable items) { 12 | var list = new ArrayList(); 13 | for (var item : items) 14 | list.add(item); 15 | return list; 16 | } 17 | 18 | public static Object[] asObjectArray(Object raw) { 19 | if (raw instanceof Iterable i) 20 | return asObjectArray(i); 21 | var array = new Object[Array.getLength(raw)]; 22 | for (var i = 0; i < array.length; i++) 23 | array[i] = Array.get(raw, i); 24 | return array; 25 | } 26 | 27 | public static Object[] asObjectArray(Iterable items) { 28 | return asObjectList(items).toArray(Object[]::new); 29 | } 30 | 31 | private static Object noConvert(Object obj, Type type) { 32 | return obj; 33 | } 34 | 35 | public static Object asTypedArray(Object[] args, Class type, BiFunction convert) { 36 | convert = convert == null ? ArrayX::noConvert : convert; 37 | var array = Array.newInstance(type, args.length); 38 | for (var i = 0; i < args.length; i++) 39 | Array.set(array, i, convert.apply(args[i], type)); 40 | return array; 41 | } 42 | 43 | public static List asTypedArrayList(Object[] args, Type type, BiFunction convert) { 44 | convert = convert == null ? ArrayX::noConvert : convert; 45 | var list = new ArrayList(); 46 | for (var arg : args) 47 | list.add(convert.apply(arg, type)); 48 | return list; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-inproc/src/main/java/jnetcall/java/client/ClrContainer.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client; 2 | 3 | import com.sun.jna.Function; 4 | import jnethotel.java.Clr; 5 | import jnethotel.java.Natives; 6 | import jnethotel.java.api.ICoreClr; 7 | import org.javatuples.Pair; 8 | 9 | public final class ClrContainer implements AutoCloseable { 10 | 11 | private final Clr _vm; 12 | private final Function _caller; 13 | 14 | public ClrContainer(String dll) { 15 | try { 16 | var tmp = setupClr(dll); 17 | _vm = tmp.getValue0(); 18 | _caller = tmp.getValue1(); 19 | } catch (Exception e) { 20 | throw new RuntimeException(dll, e); 21 | } 22 | } 23 | 24 | private static Pair setupClr(String dll) throws Exception { 25 | var vmRef = Natives.getVmRef(); 26 | vmRef.loadLib(); 27 | var clr = new Clr(vmRef); 28 | var caller = getCallCallback(clr.getCore(), dll); 29 | installStop(clr); 30 | return Pair.with(clr, caller); 31 | } 32 | 33 | private static void installStop(AutoCloseable vm) { 34 | var domain = Runtime.getRuntime(); 35 | domain.addShutdownHook(new Thread(() -> { 36 | try { 37 | vm.close(); 38 | } catch (Exception e) { 39 | throw new RuntimeException(e); 40 | } 41 | })); 42 | } 43 | 44 | public byte[] sendAndGetArray(byte[] input) { 45 | var output = _vm.callStaticByteArrayMethod(_caller, input); 46 | return output; 47 | } 48 | 49 | private static Function getCallCallback(ICoreClr coreClr, String dll) 50 | throws Exception { 51 | final var bootType = "X.Boot"; 52 | final var bootMethod = "Call"; 53 | final var bootDelegate = "JNetCall.Sharp.API.CallDelegate, JNetCall.Sharp.InProc"; 54 | return Clr.getCallback(coreClr, dll, bootType, bootMethod, bootDelegate); 55 | } 56 | 57 | @Override 58 | public void close() { 59 | // NO-OP 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /JVM/alien2-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | alien2-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | org.example 20 | alien0-java 21 | 1.0 22 | 23 | 24 | com.xafero 25 | jnetcall-java-inproc 26 | 1.0 27 | 28 | 29 | 30 | 31 | ${project.artifactId} 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-assembly-plugin 36 | 3.3.0 37 | 38 | false 39 | 40 | jar-with-dependencies 41 | 42 | 43 | 44 | 45 | package 46 | 47 | single 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.InProc/Server/ServiceLot.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using JNetCall.Sharp.API; 5 | using JNetCall.Sharp.API.Enc; 6 | using JNetCall.Sharp.API.Flow; 7 | using JNetCall.Sharp.API.IO; 8 | using JNetCall.Sharp.Impl.Enc; 9 | 10 | namespace JNetCall.Sharp.Server 11 | { 12 | public sealed class ServiceLot : ICaller, IPullTransport 13 | { 14 | private readonly object _sync; 15 | private readonly IEncoding _encoding; 16 | private readonly BlockingCollection _inputs; 17 | private readonly BlockingCollection _outputs; 18 | 19 | public ServiceLot() 20 | { 21 | _sync = new object(); 22 | _encoding = new BinaryEncoding(); 23 | _inputs = new BlockingCollection(); 24 | _outputs = new BlockingCollection(); 25 | } 26 | 27 | public T Pull() 28 | { 29 | return (T)_inputs.Take(); 30 | } 31 | 32 | public void Send(T payload) 33 | { 34 | _outputs.Add(payload); 35 | } 36 | 37 | private IList Synchronize(IEnumerable inputs) 38 | { 39 | lock (_sync) 40 | { 41 | foreach (var input in inputs) _inputs.Add(input); 42 | var copy = new List(); 43 | while (_outputs.TryTake(out var item)) copy.Add((MethodResult)item); 44 | return copy; 45 | } 46 | } 47 | 48 | public bool TryCall(byte[] @in, Stream output) 49 | { 50 | var calls = _encoding.Decode>(@in); 51 | var answers = Synchronize(calls); 52 | var bytes = _encoding.Encode(answers); 53 | output.Write(bytes); 54 | output.Flush(); 55 | return true; 56 | } 57 | 58 | public void Dispose() 59 | { 60 | _inputs.Dispose(); 61 | _outputs.Dispose(); 62 | _encoding.Dispose(); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /JVM/aliens-java/src/main/java/org/example/api/IMultiple.java: -------------------------------------------------------------------------------- 1 | package org.example.api; 2 | 3 | import com.xafero.javaenums.BitFlag; 4 | import com.xafero.javaenums.flags.IntFlag; 5 | import com.xafero.javaenums.units.IntEnum; 6 | import org.javatuples.Pair; 7 | import org.javatuples.Quartet; 8 | import org.javatuples.Quintet; 9 | import org.javatuples.Triplet; 10 | 11 | public interface IMultiple extends AutoCloseable { 12 | 13 | Pair GetTuple2T(int a, String b); 14 | Pair GetTuple2V(Pair v); 15 | 16 | Triplet GetTuple3T(int a, String b, boolean c); 17 | Triplet GetTuple3V(Triplet v); 18 | 19 | Quartet GetTuple4T(String a, String[] b, int c, int[] d); 20 | Quartet GetTuple4V(Quartet v); 21 | 22 | Quintet GetTuple5T(int a, float b, long c, String d, String e); 23 | Quintet GetTuple5V(Quintet v); 24 | 25 | WeekDay FindBestDay(int value); 26 | BitFlag FindFreeDays(); 27 | String GetTextOf(WeekDay[] taken, BitFlag days); 28 | 29 | enum WeekDay implements IntEnum { 30 | Monday(1), 31 | Tuesday(2), 32 | Wednesday(3), 33 | Thursday(4), 34 | Friday(5), 35 | Saturday(6), 36 | Sunday(7); 37 | 38 | public final int Value; WeekDay(int n) { Value = n; } 39 | 40 | @Override 41 | public Integer asNumber() { 42 | return Value; 43 | } 44 | } 45 | 46 | enum Days implements IntFlag { 47 | None(0), 48 | Sunday(1), 49 | Monday(2), 50 | Tuesday(4), 51 | Wednesday(8), 52 | Thursday(16), 53 | Friday(32), 54 | Saturday(64); 55 | 56 | public final int Value; Days(int n) { Value = n; } 57 | 58 | @Override 59 | public Integer asNumber() { 60 | return Value; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Tests/IO/TransportTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JNetBase.Sharp.Threads; 3 | using JNetCall.Sharp.API.Enc; 4 | using JNetCall.Sharp.API.IO; 5 | using JNetCall.Sharp.Client; 6 | using JNetCall.Sharp.Client.Tools; 7 | using JNetCall.Sharp.Impl.Enc; 8 | using JNetCall.Sharp.Server; 9 | 10 | namespace JNetCall.Sharp.Tests.IO 11 | { 12 | public abstract class TransportTest : CallTest 13 | { 14 | protected abstract (ISendTransport, ISendTransport) GetBoth(); 15 | 16 | protected readonly IEncoding Encoding = new BinaryEncoding(); 17 | 18 | protected override string Patch(string input) 19 | { 20 | return input.Replace("=255", "=-1") 21 | .Replace("E+", "E") 22 | .Replace("=1,", "=1.") 23 | .Replace("=3,", "=3.") 24 | .Replace("=True", "=true") 25 | .Replace("[False", "[false") 26 | .Replace("[-1,", "[-1.") 27 | .Replace("[-3,", "[-3."); 28 | } 29 | 30 | protected override T Create() 31 | { 32 | var (left, right) = GetBoth(); 33 | var client = CreateClient(left); 34 | CreateServer(right, false); 35 | return client; 36 | } 37 | 38 | private static T CreateClient(ISendTransport transport) 39 | where T : class, IDisposable 40 | { 41 | var executor = new ThreadExecutor(); 42 | var interceptor = new ClassProxy(transport, executor); 43 | interceptor.Listen(); 44 | return ClientHelper.Create(interceptor); 45 | } 46 | 47 | private static void CreateServer(ISendTransport transport, bool blocking) 48 | where T : new() 49 | { 50 | var executor = new ThreadExecutor(); 51 | var instance = new T(); 52 | var hosting = new ClassHosting(instance, transport, executor); 53 | hosting.RegisterAll(); 54 | if (blocking) 55 | hosting.ServeAndWait(); 56 | else 57 | hosting.Serve(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Mac/MacVmRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using JNetHotel.Sharp.API; 6 | using JNetHotel.Sharp.Data; 7 | 8 | namespace JNetHotel.Sharp.Mac 9 | { 10 | internal unsafe class MacVmRef : IVmRef 11 | { 12 | private const string DllName = "libjvm.dylib"; 13 | 14 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 15 | private static extern JniResult JNI_CreateJavaVM(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args); 16 | 17 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 18 | private static extern JniResult JNI_GetCreatedJavaVMs(out IntPtr pvm, int size, [Out] out int size2); 19 | 20 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 21 | private static extern JniResult JNI_GetDefaultJavaVMInitArgs(JvmInitArgs* args); 22 | 23 | public JniResult CreateVm(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args) 24 | => JNI_CreateJavaVM(out pvm, out pEnv, args); 25 | 26 | public JniResult GetCreatedVms(out IntPtr pvm, int size, out int size2) 27 | => JNI_GetCreatedJavaVMs(out pvm, size, out size2); 28 | 29 | public JniResult GetDefaultArgs(JvmInitArgs* args) 30 | => JNI_GetDefaultJavaVMInitArgs(args); 31 | 32 | public string VmDll => DllName; 33 | 34 | public void LoadLib() 35 | { 36 | const string javaLibRoot = "/Library/Java/"; 37 | if (!Directory.Exists(javaLibRoot)) 38 | throw new InvalidOperationException("Could not locate Java lib folder!"); 39 | var javaLib = Directory.GetFiles(javaLibRoot, VmDll, SearchOption.AllDirectories) 40 | .FirstOrDefault(); 41 | if (!File.Exists(javaLib)) 42 | throw new InvalidOperationException("Could not locate JVM library!"); 43 | UnixLoadLibrary(javaLib, RTLD_NOW); 44 | } 45 | 46 | private const int RTLD_NOW = 0x002; 47 | 48 | [DllImport("libdl.dylib", EntryPoint = "dlopen")] 49 | public static extern IntPtr UnixLoadLibrary(string fileName, int flags); 50 | } 51 | } -------------------------------------------------------------------------------- /JVM/jnetcall-java-tests/src/test/java/jnetcall/java/tests/io/TransportTest.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.tests.io; 2 | 3 | import jnetbase.java.meta.Reflect; 4 | import jnetbase.java.threads.ThreadExecutor; 5 | import jnetcall.java.api.enc.IEncoding; 6 | import jnetcall.java.api.io.ISendTransport; 7 | import jnetcall.java.client.ClassProxy; 8 | import jnetcall.java.client.tools.ClientHelper; 9 | import jnetcall.java.impl.enc.BinaryEncoding; 10 | import jnetcall.java.server.ClassHosting; 11 | import jnetcall.java.server.api.IHosting; 12 | import jnetcall.java.tests.CallTest; 13 | import org.example.impl.CalculatorService; 14 | import org.javatuples.Pair; 15 | 16 | public abstract class TransportTest extends CallTest { 17 | 18 | protected abstract Pair getBoth(); 19 | 20 | protected final IEncoding Encoding = new BinaryEncoding(); 21 | 22 | @Override 23 | protected String patch(String input) { 24 | return input.replace("E","E+") 25 | .replace("true","True") 26 | .replace("false","False"); 27 | } 28 | 29 | @Override 30 | protected T create(Class clazz) { 31 | var both = getBoth(); 32 | var left = both.getValue0(); 33 | var right = both.getValue1(); 34 | var client = createClient(clazz, left); 35 | createServer(TestedService.class, right, false); 36 | return client; 37 | } 38 | 39 | private static T createClient(Class clazz, ISendTransport transport) { 40 | var executor = new ThreadExecutor(); 41 | var interceptor = new ClassProxy(transport, executor); 42 | interceptor.listen(); 43 | return ClientHelper.create(clazz, interceptor); 44 | } 45 | 46 | private static IHosting createServer(Class clazz, ISendTransport transport, boolean blocking) { 47 | var executor = new ThreadExecutor(); 48 | var instance = Reflect.createNew(clazz); 49 | var hosting = new ClassHosting(instance, transport, executor); 50 | hosting.registerAll(); 51 | if (blocking) 52 | hosting.serveAndWait(); 53 | else 54 | hosting.serve(); 55 | return hosting; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-common/src/main/java/jnetcall/java/impl/io/net/UdpTransport.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.impl.io.net; 2 | 3 | import jnetcall.java.api.enc.IEncoding; 4 | import jnetcall.java.api.io.IPullTransport; 5 | import jnetcall.java.api.io.ISendTransport; 6 | 7 | import java.io.IOException; 8 | import java.net.SocketAddress; 9 | import java.nio.ByteBuffer; 10 | import java.nio.channels.DatagramChannel; 11 | 12 | public final class UdpTransport implements ISendTransport, IPullTransport, AutoCloseable { 13 | 14 | private final IEncoding _encoding; 15 | private final DatagramChannel _receiver; 16 | private final DatagramChannel _sender; 17 | 18 | public UdpTransport(IEncoding encoding, 19 | String hostIn, int portIn, String hostOut, int portOut) { 20 | this(encoding, NetworkTools.toEndPoint(hostIn, portIn), 21 | NetworkTools.toEndPoint(hostOut, portOut)); 22 | } 23 | 24 | private UdpTransport(IEncoding encoding, 25 | SocketAddress endPointIn, SocketAddress endPointOut) { 26 | _encoding = encoding; 27 | try { 28 | _receiver = DatagramChannel.open().bind(endPointIn); 29 | _sender = DatagramChannel.open(); 30 | _sender.connect(endPointOut); 31 | } catch (IOException e) { 32 | throw new RuntimeException(e); 33 | } 34 | } 35 | 36 | @Override 37 | public T pull(Class clazz) { 38 | try { 39 | var buff = ByteBuffer.allocate(65535); 40 | _receiver.receive(buff); 41 | return _encoding.decode(buff.array(), clazz); 42 | } catch (Exception e) { 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | 47 | @Override 48 | public void send(T payload) { 49 | try { 50 | var bytes = _encoding.encode(payload); 51 | var buff = ByteBuffer.wrap(bytes); 52 | _sender.write(buff); 53 | } catch (Exception e) { 54 | throw new RuntimeException(e); 55 | } 56 | } 57 | 58 | @Override 59 | public void close() throws Exception { 60 | _encoding.close(); 61 | _sender.close(); 62 | _receiver.close(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /JVM/alien1-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | alien1-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | org.example 20 | alien0-java 21 | 1.0 22 | 23 | 24 | com.xafero 25 | jnetcall-java-stdio 26 | 1.0 27 | 28 | 29 | 30 | 31 | ${project.artifactId} 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-assembly-plugin 36 | 3.3.0 37 | 38 | false 39 | 40 | jar-with-dependencies 41 | 42 | 43 | 44 | org.example.Main 45 | 46 | 47 | 48 | 49 | 50 | package 51 | 52 | single 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /JVM/alienator-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | alienator-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | org.example 20 | aliens-java 21 | 1.0 22 | 23 | 24 | com.xafero 25 | jnetcall-java-inproc 26 | 1.0 27 | 28 | 29 | 30 | 31 | ${project.artifactId} 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-assembly-plugin 36 | 3.3.0 37 | 38 | false 39 | 40 | jar-with-dependencies 41 | 42 | 43 | 44 | org.example.Main 45 | 46 | 47 | 48 | 49 | 50 | package 51 | 52 | single 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-inproc/src/main/java/jnetcall/java/server/ServiceLot.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.server; 2 | 3 | import jnetbase.java.meta.TypeToken; 4 | import jnetcall.java.api.ICaller; 5 | import jnetcall.java.api.enc.IEncoding; 6 | import jnetcall.java.api.flow.MethodCall; 7 | import jnetcall.java.api.flow.MethodResult; 8 | import jnetcall.java.api.io.IPullTransport; 9 | import jnetcall.java.impl.enc.BinaryEncoding; 10 | 11 | import java.io.OutputStream; 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | import java.util.List; 15 | import java.util.concurrent.BlockingQueue; 16 | import java.util.concurrent.LinkedBlockingQueue; 17 | 18 | public final class ServiceLot implements ICaller, IPullTransport { 19 | 20 | private final Object _sync; 21 | private final IEncoding _encoding; 22 | private final BlockingQueue _inputs; 23 | private final BlockingQueue _outputs; 24 | 25 | public ServiceLot() { 26 | _sync = new Object(); 27 | _encoding = new BinaryEncoding(); 28 | _inputs = new LinkedBlockingQueue<>(); 29 | _outputs = new LinkedBlockingQueue<>(); 30 | } 31 | 32 | @Override 33 | public T pull(Class clazz) { 34 | try { 35 | return clazz.cast(_inputs.take()); 36 | } catch (InterruptedException e) { 37 | throw new RuntimeException(e); 38 | } 39 | } 40 | 41 | @Override 42 | public void send(T payload) { 43 | _outputs.add(payload); 44 | } 45 | 46 | private List synchronize(Collection inputs) { 47 | synchronized (_sync) { 48 | _inputs.addAll(inputs); 49 | var copy = new ArrayList(); 50 | ((BlockingQueue) _outputs).drainTo(copy); 51 | return copy; 52 | } 53 | } 54 | 55 | private static final TypeToken> mcList = new TypeToken<>() { 56 | }; 57 | 58 | @Override 59 | public boolean tryCall(byte[] in, OutputStream output) throws Exception { 60 | var calls = _encoding.decode(in, mcList); 61 | var answers = synchronize(calls); 62 | var bytes = _encoding.encode(answers); 63 | output.write(bytes); 64 | output.flush(); 65 | return true; 66 | } 67 | 68 | @Override 69 | public void close() throws Exception { 70 | _inputs.clear(); 71 | _outputs.clear(); 72 | _encoding.close(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Windows/WinVmRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using JNetHotel.Sharp.API; 6 | using JNetHotel.Sharp.Data; 7 | 8 | namespace JNetHotel.Sharp.Windows 9 | { 10 | internal unsafe class WinVmRef : IVmRef 11 | { 12 | private const string DllName = "jvm.dll"; 13 | 14 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 15 | private static extern JniResult JNI_CreateJavaVM(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args); 16 | 17 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 18 | private static extern JniResult JNI_GetCreatedJavaVMs(out IntPtr pvm, int size, [Out] out int size2); 19 | 20 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 21 | private static extern JniResult JNI_GetDefaultJavaVMInitArgs(JvmInitArgs* args); 22 | 23 | public JniResult CreateVm(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args) 24 | => JNI_CreateJavaVM(out pvm, out pEnv, args); 25 | 26 | public JniResult GetCreatedVms(out IntPtr pvm, int size, out int size2) 27 | => JNI_GetCreatedJavaVMs(out pvm, size, out size2); 28 | 29 | public JniResult GetDefaultArgs(JvmInitArgs* args) 30 | => JNI_GetDefaultJavaVMInitArgs(args); 31 | 32 | public string VmDll => DllName; 33 | 34 | public void LoadLib() 35 | { 36 | var paths = Environment.GetEnvironmentVariable("Path")?.Split(";"); 37 | var javaBinPath = paths?.FirstOrDefault(p => File.Exists(Path.Combine(p, "java.exe"))); 38 | if (!Directory.Exists(javaBinPath)) 39 | throw new InvalidOperationException("Could not locate Java binary!"); 40 | var javaRootPath = Path.GetDirectoryName(javaBinPath); 41 | if (!Directory.Exists(javaRootPath)) 42 | throw new InvalidOperationException("Could not locate Java root!"); 43 | var javaDllPath = Directory.GetFiles(javaRootPath, "jvm.dll", SearchOption.AllDirectories).FirstOrDefault(); 44 | if (!File.Exists(javaDllPath)) 45 | throw new InvalidOperationException("Could not locate JVM library!"); 46 | LoadLibrary(javaDllPath); 47 | } 48 | 49 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] 50 | public static extern IntPtr LoadLibrary(string dllToLoad); 51 | } 52 | } -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/BSD/BsdVmRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using JNetHotel.Sharp.API; 6 | using JNetHotel.Sharp.Data; 7 | 8 | namespace JNetHotel.Sharp.BSD 9 | { 10 | internal unsafe class BsdVmRef : IVmRef 11 | { 12 | private const string DllName = "libjvm.so"; 13 | 14 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 15 | private static extern JniResult JNI_CreateJavaVM(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args); 16 | 17 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 18 | private static extern JniResult JNI_GetCreatedJavaVMs(out IntPtr pvm, int size, [Out] out int size2); 19 | 20 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 21 | private static extern JniResult JNI_GetDefaultJavaVMInitArgs(JvmInitArgs* args); 22 | 23 | public JniResult CreateVm(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args) 24 | => JNI_CreateJavaVM(out pvm, out pEnv, args); 25 | 26 | public JniResult GetCreatedVms(out IntPtr pvm, int size, out int size2) 27 | => JNI_GetCreatedJavaVMs(out pvm, size, out size2); 28 | 29 | public JniResult GetDefaultArgs(JvmInitArgs* args) 30 | => JNI_GetDefaultJavaVMInitArgs(args); 31 | 32 | public string VmDll => DllName; 33 | 34 | public void LoadLib() 35 | { 36 | const string local = "/usr/local/"; 37 | var javaRootPath = Directory.GetDirectories(local, "openjdk*", SearchOption.TopDirectoryOnly) 38 | .FirstOrDefault(); 39 | if (!Directory.Exists(javaRootPath)) 40 | throw new InvalidOperationException("Could not locate Java root!"); 41 | var javaSoPath = Directory.GetFiles(javaRootPath, VmDll, SearchOption.AllDirectories) 42 | .FirstOrDefault(); 43 | if (!File.Exists(javaSoPath)) 44 | throw new InvalidOperationException("Could not locate JVM library!"); 45 | 46 | // WARNING: Must exist! 47 | // ln -s /usr/local/openjdk18/lib/server/libjvm.so /usr/local/lib/libjvm.so 48 | UnixLoadLibrary(javaSoPath, RTLD_NOW); 49 | } 50 | 51 | private const int RTLD_NOW = 0x002; 52 | 53 | [DllImport("libdl", EntryPoint = "dlopen")] 54 | public static extern IntPtr UnixLoadLibrary(string fileName, int flags); 55 | } 56 | } -------------------------------------------------------------------------------- /JVM/jnethotel-java/src/main/java/jnethotel/java/Clr.java: -------------------------------------------------------------------------------- 1 | package jnethotel.java; 2 | 3 | import com.sun.jna.Function; 4 | import com.sun.jna.Memory; 5 | import com.sun.jna.Pointer; 6 | import jnethotel.java.api.ICoreClr; 7 | import jnethotel.java.api.IVmRef; 8 | import jnethotel.java.interop.VmHelper; 9 | 10 | import java.io.File; 11 | import java.io.FileNotFoundException; 12 | import java.nio.ByteBuffer; 13 | import java.nio.ByteOrder; 14 | 15 | public final class Clr implements AutoCloseable { 16 | 17 | private final IVmRef _vmRef; 18 | private final ICoreClr _core; 19 | 20 | public Clr(IVmRef vmRef) { 21 | _vmRef = vmRef; 22 | _core = _vmRef.getCoreClr(); 23 | } 24 | 25 | @Override 26 | public void close() { 27 | } 28 | 29 | public static Function getCallback(ICoreClr coreClr, String dll, String type, 30 | String method, String delegate) 31 | throws Exception { 32 | var runtimeConfig = VmHelper.getRuntimeConfig(dll); 33 | var typeName = type.contains(", ") ? type : VmHelper.getTypeName(type, dll); 34 | 35 | if (!(new File(dll).exists())) 36 | throw new FileNotFoundException(dll); 37 | if (!(new File(runtimeConfig).exists())) 38 | throw new FileNotFoundException(runtimeConfig); 39 | 40 | return coreClr.load_assembly_and_get_callback(runtimeConfig, dll, typeName, method, delegate); 41 | } 42 | 43 | private static Memory toPointer(byte[] data) { 44 | var pointer = new Memory(data.length); 45 | pointer.write(0, data, 0, data.length); 46 | return pointer; 47 | } 48 | 49 | private static byte[] toByteArray(Pointer ptr, int size) { 50 | if (size == -1) { 51 | final int header = 4; 52 | var lenBits = ptr.getByteArray(0, header); 53 | var len = ByteBuffer.wrap(lenBits).order(ByteOrder.nativeOrder()).getInt(); 54 | size = header + len; 55 | } 56 | var array = new byte[size]; 57 | for (var i = 0; i < array.length; i++) 58 | array[i] = ptr.getByte(i); 59 | return array; 60 | } 61 | 62 | public ICoreClr getCore() { 63 | return _core; 64 | } 65 | 66 | public byte[] callStaticByteArrayMethod(Function func, byte[] input) { 67 | var inputPtr = toPointer(input); 68 | var outputPtr = func.invokePointer(new Object[]{inputPtr}); 69 | return toByteArray(outputPtr, -1); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /NET/JNetHotel.Sharp/Linux/LinuxVmRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using JNetHotel.Sharp.API; 6 | using JNetHotel.Sharp.Data; 7 | 8 | namespace JNetHotel.Sharp.Linux 9 | { 10 | internal unsafe class LinuxVmRef : IVmRef 11 | { 12 | private const string DllName = "libjvm.so"; 13 | 14 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 15 | private static extern JniResult JNI_CreateJavaVM(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args); 16 | 17 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 18 | private static extern JniResult JNI_GetCreatedJavaVMs(out IntPtr pvm, int size, [Out] out int size2); 19 | 20 | [DllImport(DllName, CallingConvention = CallingConvention.StdCall)] 21 | private static extern JniResult JNI_GetDefaultJavaVMInitArgs(JvmInitArgs* args); 22 | 23 | public JniResult CreateVm(out IntPtr pvm, out IntPtr pEnv, JvmInitArgs* args) 24 | => JNI_CreateJavaVM(out pvm, out pEnv, args); 25 | 26 | public JniResult GetCreatedVms(out IntPtr pvm, int size, out int size2) 27 | => JNI_GetCreatedJavaVMs(out pvm, size, out size2); 28 | 29 | public JniResult GetDefaultArgs(JvmInitArgs* args) 30 | => JNI_GetDefaultJavaVMInitArgs(args); 31 | 32 | public string VmDll => DllName; 33 | 34 | public void LoadLib() 35 | { 36 | var javaBinLink = new FileInfo("/usr/bin/java"); 37 | var javaBinPath = javaBinLink.ResolveLinkTarget(true)?.FullName; 38 | if (!File.Exists(javaBinPath)) 39 | throw new InvalidOperationException("Could not locate Java binary!"); 40 | var javaRootPath = Path.GetFullPath(Path.Combine(javaBinPath, "..", "..")); 41 | if (!Directory.Exists(javaRootPath)) 42 | throw new InvalidOperationException("Could not locate Java root!"); 43 | var javaSoPath = Directory.GetFiles(javaRootPath, "libjvm.so", SearchOption.AllDirectories) 44 | .FirstOrDefault(); 45 | if (!File.Exists(javaSoPath)) 46 | throw new InvalidOperationException("Could not locate JVM library!"); 47 | UnixLoadLibrary(javaSoPath, RTLD_NOW); 48 | } 49 | 50 | private const int RTLD_NOW = 0x002; 51 | 52 | [DllImport("libdl.so.2", EntryPoint = "dlopen")] 53 | public static extern IntPtr UnixLoadLibrary(string fileName, int flags); 54 | } 55 | } -------------------------------------------------------------------------------- /NET/JNetCall.Sharp.Common/Impl/IO/StreamTools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading.Tasks; 4 | 5 | namespace JNetCall.Sharp.Impl.IO 6 | { 7 | public static class StreamTools 8 | { 9 | private static async Task TryReadAsync(Stream stream, int size, byte[] prefix = null) 10 | { 11 | var skip = prefix?.Length ?? 0; 12 | size += skip; 13 | var buffer = new byte[size]; 14 | int got; 15 | if (prefix == null) 16 | { 17 | got = await stream.ReadAsync(buffer); 18 | } 19 | else 20 | { 21 | Array.Copy(prefix, 0, buffer, 0, skip); 22 | var tmp = await stream.ReadAsync(buffer, skip, size - skip); 23 | got = tmp + skip; 24 | } 25 | if (size != got) 26 | { 27 | throw new InvalidOperationException(size + " != " + got); 28 | } 29 | return buffer; 30 | } 31 | 32 | public static async Task ReadWithSizeAsync(Stream stream) 33 | { 34 | var sizeBytes = await TryReadAsync(stream, 4); 35 | var size = BitConverter.ToInt32(sizeBytes); 36 | var bytes = await TryReadAsync(stream, size, sizeBytes); 37 | return bytes; 38 | } 39 | 40 | private static byte[] TryRead(Stream stream, int size, byte[] prefix = null) 41 | { 42 | var skip = prefix?.Length ?? 0; 43 | size += skip; 44 | var buffer = new byte[size]; 45 | int got; 46 | if (prefix == null) 47 | { 48 | got = stream.Read(buffer); 49 | } 50 | else 51 | { 52 | Array.Copy(prefix, 0, buffer, 0, skip); 53 | var tmp = stream.Read(buffer, skip, size - skip); 54 | got = tmp + skip; 55 | } 56 | if (size != got) 57 | { 58 | throw new InvalidOperationException(size + " != " + got); 59 | } 60 | return buffer; 61 | } 62 | 63 | public static byte[] ReadWithSize(Stream stream) 64 | { 65 | var sizeBytes = TryRead(stream, 4); 66 | var size = BitConverter.ToInt32(sizeBytes); 67 | var bytes = TryRead(stream, size, sizeBytes); 68 | return bytes; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/sys/BitConverter.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.sys; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.nio.ByteOrder; 5 | import java.util.UUID; 6 | 7 | public final class BitConverter { 8 | 9 | private static ByteBuffer allocate(int size) { 10 | return ByteBuffer.allocate(size).order(ByteOrder.nativeOrder()); 11 | } 12 | 13 | private static ByteBuffer wrap(byte[] bytes) { 14 | return ByteBuffer.wrap(bytes).order(ByteOrder.nativeOrder()); 15 | } 16 | 17 | public static byte[] getBytes(short value) { 18 | return allocate(2).putShort(value).array(); 19 | } 20 | 21 | public static short toInt16(byte[] bytes) { 22 | return wrap(bytes).getShort(); 23 | } 24 | 25 | public static byte[] getBytes(int value) { 26 | return allocate(4).putInt(value).array(); 27 | } 28 | 29 | public static int toInt32(byte[] bytes) { 30 | return wrap(bytes).getInt(); 31 | } 32 | 33 | public static byte[] getBytes(long value) { 34 | return allocate(8).putLong(value).array(); 35 | } 36 | 37 | public static long toInt64(byte[] bytes) { 38 | return wrap(bytes).getLong(); 39 | } 40 | 41 | public static byte[] getBytes(float value) { 42 | return allocate(4).putFloat(value).array(); 43 | } 44 | 45 | public static float toSingle(byte[] bytes) { 46 | return wrap(bytes).getFloat(); 47 | } 48 | 49 | public static byte[] getBytes(double value) { 50 | return allocate(8).putDouble(value).array(); 51 | } 52 | 53 | public static double toDouble(byte[] bytes) { 54 | return wrap(bytes).getDouble(); 55 | } 56 | 57 | public static byte[] getBytes(UUID value) { 58 | var most = getBytes(value.getMostSignificantBits()); 59 | return allocate(16) 60 | .put(most, 4, 4) 61 | .put(most, 2, 1) 62 | .put(most, 3, 1) 63 | .put(most, 0, 1) 64 | .put(most, 1, 1) 65 | .order(ByteOrder.BIG_ENDIAN) 66 | .putLong(value.getLeastSignificantBits()) 67 | .array(); 68 | } 69 | 70 | public static UUID toGuid(byte[] bytes) { 71 | var raw = wrap(bytes); 72 | var first = getBytes(raw.getInt()); 73 | var second = getBytes(raw.getInt()); 74 | var most = toInt64(new byte[]{second[2], second[3], second[0], second[1], 75 | first[0], first[1], first[2], first[3]}); 76 | var least = raw.order(ByteOrder.BIG_ENDIAN).getLong(); 77 | return new UUID(most, least); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /JVM/jnetbase-java/src/main/java/jnetbase/java/io/MemPipeStream.java: -------------------------------------------------------------------------------- 1 | package jnetbase.java.io; 2 | 3 | import java.io.*; 4 | import java.util.concurrent.BlockingQueue; 5 | import java.util.concurrent.LinkedBlockingQueue; 6 | 7 | public final class MemPipeStream implements Flushable, Closeable { 8 | 9 | private final byte[] _array; 10 | private final Input _input; 11 | private final Output _output; 12 | private final BlockingQueue _queue; 13 | 14 | public MemPipeStream() { 15 | _array = new byte[0]; 16 | _input = new Input(_array); 17 | _output = new Output(); 18 | _queue = new LinkedBlockingQueue(); 19 | } 20 | 21 | private int _readPos; 22 | private int _writePos; 23 | 24 | public InputStream asI() { 25 | return _input; 26 | } 27 | 28 | public OutputStream asO() { 29 | return _output; 30 | } 31 | 32 | @Override 33 | public void flush() throws IOException { 34 | _output.flush(); 35 | } 36 | 37 | @Override 38 | public void close() throws IOException { 39 | _queue.clear(); 40 | _output.close(); 41 | _input.close(); 42 | } 43 | 44 | private final class Input extends ByteArrayInputStream { 45 | 46 | public Input(byte[] buf) { 47 | super(buf); 48 | } 49 | 50 | @Override 51 | public int read(byte[] b) { 52 | try { 53 | _queue.take(); 54 | pos = _readPos; 55 | var res = super.read(b, 0, b.length); 56 | if (res >= 0) 57 | _readPos += res; 58 | return res; 59 | } catch (InterruptedException e) { 60 | throw new RuntimeException(e); 61 | } 62 | } 63 | 64 | @Override 65 | public synchronized int read(byte[] b, int off, int len) { 66 | pos = _readPos; 67 | var res = super.read(b, off, len); 68 | if (res >= 0) 69 | _readPos += res; 70 | return res; 71 | } 72 | 73 | synchronized void replace(byte[] array) { 74 | buf = array; 75 | count = array.length; 76 | } 77 | } 78 | 79 | private final class Output extends ByteArrayOutputStream implements IRewindable { 80 | 81 | public Output() { 82 | } 83 | 84 | @Override 85 | public synchronized void write(byte[] b, int off, int len) { 86 | count = _writePos; 87 | super.write(b, off, len); 88 | _writePos += len; 89 | } 90 | 91 | @Override 92 | public void rewind(int size) { 93 | _input.replace(_output.toByteArray()); 94 | _queue.offer(true); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /JVM/jnetproto-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xafero 8 | jnetproto-java 9 | 1.0 10 | 11 | 12 | UTF-8 13 | 18 14 | 18 15 | 16 | 17 | 18 | 19 | com.xafero 20 | jnetbase-java 21 | 1.0 22 | 23 | 24 | com.flipkart.utils 25 | javatuples 26 | 3.0 27 | 28 | 29 | com.xafero.utils 30 | javaenums 31 | 1.0 32 | 33 | 34 | org.testng 35 | testng 36 | 7.5 37 | test 38 | 39 | 40 | commons-codec 41 | commons-codec 42 | 1.15 43 | test 44 | 45 | 46 | com.google.code.gson 47 | gson 48 | 2.9.0 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.jacoco 57 | jacoco-maven-plugin 58 | 0.8.8 59 | 60 | 61 | 62 | prepare-agent 63 | 64 | 65 | 66 | report 67 | prepare-package 68 | 69 | report 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /NET/JNetProto.Sharp.Tests/EnumTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using static JNetProto.Sharp.Tests.ComplexTest; 4 | 5 | namespace JNetProto.Sharp.Tests 6 | { 7 | public class EnumTest 8 | { 9 | [Theory] 10 | [InlineData("13000000130404000000000A0100730300000415000000", Season.Spring, "s", ErrorCode.None, Days.Monday | Days.Wednesday | Days.Friday)] 11 | [InlineData("13000000130404020000000A01006103C8000418000000", Season.Autumn, "a", ErrorCode.OutlierReading, Days.Thursday | Days.Friday)] 12 | [InlineData("13000000130404030000000A0100770364000402000000", Season.Winter, "w", ErrorCode.ConnectionLost, Days.Tuesday)] 13 | [InlineData("13000000130404030000000A0100770300000400000000", Season.Winter, "w", null, null)] 14 | public void ShouldWrite1(string hex, Season what, string why, ErrorCode? code, Days? days) 15 | { 16 | var bitty = new Bitty(what, why, code ?? default, days ?? default); 17 | TestWrite(hex, bitty, r => r.ReadObject()); 18 | } 19 | 20 | [Theory] 21 | [InlineData("2900000013030E04010200000001000000020000000E0A01020000000100680100770E030102000000C8006400", new[]{Season.Summer, Season.Autumn}, new[]{"h", "w"}, new[]{ErrorCode.OutlierReading, ErrorCode.ConnectionLost})] 22 | [InlineData("2000000013030E040101000000010000000E0A01010000000100680E030101000000C800", new[]{Season.Summer}, new[]{"h"}, new[]{ErrorCode.OutlierReading})] 23 | [InlineData("1700000013030E0401000000000E0A01000000000E030100000000", new Season[0], new string[0], new ErrorCode[0])] 24 | public void ShouldWrite2(string hex, Season[] whats, string[] whys, ErrorCode[] codes) 25 | { 26 | var texted = new Texted(whats, whys, codes); 27 | TestWrite(hex, texted, r => r.ReadObject()); 28 | } 29 | 30 | public record Bitty(Season What, string Why, ErrorCode Code, Days Days); 31 | 32 | public record Texted(Season[] Whats, string[] Whys, ErrorCode[] Codes); 33 | 34 | public enum Season 35 | { 36 | Spring, 37 | Summer, 38 | Autumn, 39 | Winter 40 | } 41 | 42 | public enum ErrorCode : short 43 | { 44 | None = 0, 45 | Unknown = 1, 46 | ConnectionLost = 100, 47 | OutlierReading = 200 48 | } 49 | 50 | [Flags] 51 | public enum Days 52 | { 53 | None = 0b_0000_0000, // 0 54 | Monday = 0b_0000_0001, // 1 55 | Tuesday = 0b_0000_0010, // 2 56 | Wednesday = 0b_0000_0100, // 4 57 | Thursday = 0b_0000_1000, // 8 58 | Friday = 0b_0001_0000, // 16 59 | Saturday = 0b_0010_0000, // 32 60 | Sunday = 0b_0100_0000, // 64 61 | Weekend = Saturday | Sunday 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /NET/JNetProto.Sharp/Beans/ProtoConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JNetProto.Sharp.API; 3 | using JNetProto.Sharp.Core; 4 | using JNetProto.Sharp.Tools; 5 | using Stream = System.IO.Stream; 6 | using MemoryStream = System.IO.MemoryStream; 7 | 8 | namespace JNetProto.Sharp.Beans 9 | { 10 | public sealed class ProtoConvert : IDisposable 11 | { 12 | private readonly object _writeLock = new(); 13 | private readonly object _readLock = new(); 14 | 15 | private readonly IDataReader _reader; 16 | private readonly IDataWriter _writer; 17 | private readonly ProtoSettings _cfg; 18 | 19 | public ProtoConvert(Stream stdOutput, Stream stdInput, ProtoSettings cfg) 20 | { 21 | _reader = new BinaryReader(stdOutput); 22 | _writer = new BinaryWriter(stdInput); 23 | _cfg = cfg; 24 | } 25 | 26 | public void WriteObject(object obj) 27 | { 28 | var bytes = SerializeObject(obj, _cfg); 29 | lock (_writeLock) 30 | { 31 | _writer.WriteBinary(bytes); 32 | } 33 | } 34 | 35 | public T ReadObject() 36 | { 37 | byte[] bytes; 38 | lock (_readLock) 39 | { 40 | bytes = _reader.ReadBinary(); 41 | } 42 | return DeserializeObject(bytes, _cfg); 43 | } 44 | 45 | public void Flush() 46 | { 47 | lock (_writeLock) 48 | { 49 | _writer.Flush(); 50 | } 51 | } 52 | 53 | public void Dispose() 54 | { 55 | _reader?.Dispose(); 56 | _writer?.Dispose(); 57 | } 58 | 59 | private static byte[] SerializeObject(object obj, ProtoSettings s) 60 | { 61 | var raw = Conversions.ToObjectArray(obj); 62 | var args = (object[])raw; 63 | return SerializeObject(args, s); 64 | } 65 | 66 | private static T DeserializeObject(object[] args, ProtoSettings _) 67 | { 68 | var type = typeof(T); 69 | var raw = Conversions.FromObjectArray(type, args); 70 | return (T)raw; 71 | } 72 | 73 | private static byte[] SerializeObject(object[] args, ProtoSettings _) 74 | { 75 | using var mem = new MemoryStream(); 76 | using IDataWriter writer = new BinaryWriter(mem); 77 | writer.WriteObject(args); 78 | return mem.ToArray(); 79 | } 80 | 81 | private static T DeserializeObject(byte[] bytes, ProtoSettings s) 82 | { 83 | using var mem = new MemoryStream(bytes); 84 | using IDataReader reader = new BinaryReader(mem); 85 | var args = (object[])reader.ReadObject(); 86 | return DeserializeObject(args, s); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /JVM/jnetcall-java-stdio/src/main/java/jnetcall/java/client/ExeTransport.java: -------------------------------------------------------------------------------- 1 | package jnetcall.java.client; 2 | 3 | import jnetbase.java.sys.Strings; 4 | import jnetcall.java.api.io.IPullTransport; 5 | import jnetcall.java.api.io.ISendTransport; 6 | import jnetcall.java.client.tools.ServiceEnv; 7 | import jnetcall.java.common.ByteMarks; 8 | import jnetcall.java.common.StreamInit; 9 | import org.javatuples.Pair; 10 | 11 | import java.io.*; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | final class ExeTransport implements ISendTransport, IPullTransport { 15 | 16 | private final String _exe; 17 | private final IPullTransport _parent; 18 | 19 | public ExeTransport(String exe, StreamInit init) { 20 | try { 21 | if (!(new File(exe)).exists() && exe.endsWith(".exe")) 22 | exe = exe.substring(0, exe.length() - 4); 23 | if (!(new File(exe)).exists()) 24 | throw new FileNotFoundException("Missing: " + exe); 25 | _exe = exe; 26 | var std = start(); 27 | _parent = (IPullTransport) init.invoke(std.getValue0(), std.getValue1()); 28 | } catch (IOException e) { 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | private Process _process; 34 | 35 | private Pair start() throws IOException { 36 | var pwd = ServiceEnv.getCurrentDir(); 37 | _process = new ProcessBuilder(_exe) 38 | .directory(pwd) 39 | .redirectInput(ProcessBuilder.Redirect.PIPE) 40 | .redirectError(ProcessBuilder.Redirect.PIPE) 41 | .redirectOutput(ProcessBuilder.Redirect.PIPE) 42 | .start(); 43 | return writeSync(_process); 44 | } 45 | 46 | private void stop(int milliseconds) throws InterruptedException { 47 | _process.waitFor(milliseconds, TimeUnit.MILLISECONDS); 48 | _process.destroyForcibly(); 49 | 50 | _process.destroy(); 51 | } 52 | 53 | private static Pair writeSync(Process process) 54 | throws IOException { 55 | var stdOut = process.getInputStream(); 56 | var stdIn = process.getOutputStream(); 57 | return ByteMarks.writeSync(stdOut, stdIn); 58 | } 59 | 60 | private String getErrorDetails() throws IOException { 61 | _process.getOutputStream().close(); 62 | return (Strings.readToEnd(_process.getInputStream()) + " " + 63 | Strings.readToEnd(_process.getErrorStream())).trim(); 64 | } 65 | 66 | @Override 67 | public void send(T payload) { 68 | _parent.send(payload); 69 | } 70 | 71 | @Override 72 | public T pull(Class clazz) { 73 | var msg = _parent.pull(clazz); 74 | return msg; 75 | } 76 | 77 | @Override 78 | public void close() throws Exception { 79 | stop(250); 80 | _parent.close(); 81 | } 82 | } 83 | --------------------------------------------------------------------------------