From 1c496d8be1d3cc8b5134c0443367d5b53e7b9f9d Mon Sep 17 00:00:00 2001
From: Akilan Selvacoumar <31743758+Akilan1999@users.noreply.github.com>
Date: Sat, 16 Dec 2023 02:55:54 +0000
Subject: [PATCH] Update Bindings.md
---
Docs/Bindings.md | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/Docs/Bindings.md b/Docs/Bindings.md
index 81f4663..0fb6867 100644
--- a/Docs/Bindings.md
+++ b/Docs/Bindings.md
@@ -1,6 +1,8 @@
# Language Bindings
[Language bindings](https://en.wikipedia.org/wiki/Language_binding) refers to wrappers to bridge 2 programming languages. This is used in P2PRC to extend calling P2PRC functions in other programming languages. Currently this is done by generating ```.so``` and ```.h``` from the Go compiler.
+
+
## How to build shared object files
The easier way
```bash
@@ -21,6 +23,7 @@ ls
# Find files
p2prc.h p2prc.so
```
+
## Workings under the hood
Below are a sample set of commands to
@@ -67,6 +70,15 @@ it is pretty trivial to notice a common structure).
```go
// --------- Example ------------
+//export StartContainer
+func StartContainer(IP string) (output *C.char) {
+ container, err := client.StartContainer(IP, 0, false, "", "")
+ if err != nil {
+ return C.CString(err.Error())
+ }
+ return ConvertStructToJSONString(container)
+}
+
//export ViewPlugin
func ViewPlugin() (output *C.char) {
plugins, err := plugin.DetectPlugins()
@@ -76,17 +88,25 @@ func ViewPlugin() (output *C.char) {
return ConvertStructToJSONString(plugins)
}
-//export PullPlugin
-func PullPlugin(pluginUrl string) (output *C.char) {
- err := plugin.DownloadPlugin(pluginUrl)
- if err != nil {
- return C.CString(err.Error())
- }
- return C.CString("Success")
+```
+It is easy to notice that:
+- ```ConvertStructToJSONString()```: This is a helper function that convert
+ a go object to JSON string initially and converts it to ```CString```.
+- ```(output *C.char)```: This is the return type for most of the functions.
+
+#### A Pseudo code to refer to the common function implementation shape could be represented as:
+```
+func (output *C.char) {
+ , := ()
+ if != nil {
+ return C.CString(.Error())
+ }
+ return ConvertStructToJSONString()
}
```
+
## Current languages supported