@@ -10,52 +10,59 @@ import (
1010const isFailure = rune ('F' )
1111const isSuccess = rune ('S' )
1212
13- /*
14- func main() {
15- panic("not implemented")
16- }
17-
18- func success(buffer []byte) uint64 {
19- return copyBufferToMemory(append([]byte(string(isSuccess)), buffer...))
20- }
21-
22- func failure(buffer []byte) uint64 {
23- return copyBufferToMemory(append([]byte(string(isFailure)), buffer...))
24- }
25- */
26-
13+ // success appends the isSuccess byte to the beginning of the input buffer and returns the result.
14+ //
15+ // buffer: byte slice to append isSuccess byte to.
16+ // []byte: byte slice with the appended isSuccess byte.
2717func success (buffer []byte ) []byte {
2818 return append ([]byte (string (isSuccess )), buffer ... )
2919}
3020
21+ // failure appends a string "isFailure" to the given byte slice buffer and returns the new slice.
22+ //
23+ // buffer: the byte slice to which "isFailure" is appended.
24+ // Returns the new byte slice with the string "isFailure" appended to it.
3125func failure (buffer []byte ) []byte {
3226 return append ([]byte (string (isFailure )), buffer ... )
3327}
3428
35-
36-
37-
38- // Result function
29+ // Result returns the data without the first byte if the first byte is isSuccess.
30+ // Otherwise, it returns nil and an error with the data starting from the second byte.
31+ //
32+ // data: A byte slice containing the data to check.
33+ // []byte: The data without the first byte if the first byte is isSuccess.
34+ // error: If the first byte is not isSuccess, it returns an error with the data starting from the second byte.
3935func Result (data []byte ,) ([]byte , error ) {
4036 if data [0 ] == byte (isSuccess ) {
4137 return data [1 :], nil
4238 }
4339 return nil , errors .New (string (data [1 :]))
4440}
4541
46- // GetHandle returns the handle function
42+ // GetHandle returns an exported function named "callHandle" from the given module.
43+ //
44+ // mod: The module to retrieve the function from.
45+ //
46+ // Returns: An exported function with the name "callHandle".
4747func GetHandle (mod api.Module ) api.Function {
4848 return mod .ExportedFunction ("callHandle" )
4949}
5050
51- // GetHandleJSON returns the handle function
51+ // GetHandleJSON returns the exported "callHandleJSON" function from the given module.
52+ //
53+ // mod: the module to retrieve the function from.
54+ //
55+ // returns: the exported "callHandleJSON" function.
5256func GetHandleJSON (mod api.Module ) api.Function {
5357 return mod .ExportedFunction ("callHandleJSON" )
5458}
5559
56- // GetHandleHTTP returns the handle function
60+ // GetHandleHTTP returns the exported 'callHandleHTTP' function from a given module.
61+ //
62+ // mod: The module containing the exported function.
63+ //
64+ // returns:
65+ // - api.Function: the exported 'callHandleHTTP' function.
5766func GetHandleHTTP (mod api.Module ) api.Function {
5867 return mod .ExportedFunction ("callHandleHTTP" )
5968}
60-
61- // TODO: handle the other handles
0 commit comments