# Layers - *for use in specification* ## Bytes This is only a partial layer, which means it depends on another layer to be implemented and a protocol to be defined. It's the basis of protocols that requires a byte stream, instead of using a ffi, for example. ### Marshaling For any method, the `Read` and `Write` traits are used to convert all data between rust code and the protocol provided. In case of receiving a request, the data is read and converted to rust type, calling the implemented function. If the method returns anything, it will be written using the argument that implements `Write`, with only the exception of streams that will require a callback. Nonetheless, the callback will use the same approach used for methods. ### Types * InternalError * Ok = 0 * InvalidArg = 1 * NullPtr = 2 * Abort = 3 * CallbackException = 4 * UndefinedException = 5 * Unimplemented = 6 * Type = 7 * NotAllowedOperation = 8 * StreamSenderState * Error = 1 * Value = 2 * Request = 3 * Awaiting = 4 * Done = 5 * StreamReceiverState * Error = 1 * Close = 2 * Start = 3 * Pause = 4 * Resume = 5 * Request = 6 * MethodType * Ok = 0 * Error = 1 * Instance = 2 * CreateInstance = 3 * DisposeInstance = 4 * Method = 5 * MethodCall = 6 * Sender = 7 * Receiver = 8 * Query = 9 * QueryCall = 10 ### Request All digests are 16 bytes long, while enumerations are 64-bit integers. 1. *package* `digest` 2. *library* `digest` 3. *interface* `digest` 4. *method type* `MethodType` 1. Error 1. *method type* `MethodType` 2. Instance 1. *call id* `int` 2. *instance id* `int` 3. CreateInstance 1. *call id* `int` 4. DisposeInstance 1. *instance id* `int` 5. Method 1. *call id* `int` 2. *method* `digest` 3. *intance id?* `int` 4. *result?* 6. MethodCall 1. *call id* `int` 2. *method* `digest` 3. *intance id?* `int` 4. *args?* 5. Stream 1. *state* `StreamReceiver` 1. Start | Pause 7. Sender 1. *call id* `int` 2. *method* `digest` 3. *intance id?* `int` 4. *state* `StreamSender` 1. Request | Awaiting | Done 2. Value 1. *stream value* `any` 8. Receiver 1. *call id* `int` 2. *method* `digest` 3. *intance id?* `int` 4. *state* `StreamReceiver` 1. Request | Close | Start | Pause | Resume 9. Query 1. *call id* `int` 2. *method* `digest` 3. *intance id?* `int` 4. *result?* 10. QueryCall 1. *call id* `int` 2. *method* `digest` 3. *intance id?* `int` 4. *args?* 5. Stream 1. *state* `StreamReceiver` 1. Start | Pause ## FFI Layer that uses foreigh function interface as communication. For now, only 64-bit is supported. If 32-bit or 128-bit is used in the future, all other layers will also have to be the same type as to avoid data loss. ### Layout Since it uses the x64 calling convention, call between language would be the same as any call using the languague supported ffi calls. In Rust, this would be the `extern "C"` function attribute, and in Dart, the `ffi` library to annotate functions used for interfacing with this calling convention. ### Stream support The main problem with stream is that it needs to use a callback to send an event to the client to acknowledge for new data, and then the need to raise a signal to the thread that is listening to that event. This is the reason that there's a function that sends a handle and id, so that the client can call the server to retrive data or do something else with the stream. ## Web Sockets ... ### WS - [ ] Client-side - [ ] Server-side - [ ] Streams - [ ] Documentation