support for []byte (code not finished, temp commit)

This commit is contained in:
Egor Aristov 2025-11-11 09:05:18 +03:00
parent 6b7014a2b7
commit f24a0d706c
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F
2 changed files with 40 additions and 11 deletions

View File

@ -21,6 +21,20 @@ func (api GoIpcApi) Div(a int, b int) (int, error) {
return a / b, nil
}
func (api GoIpcApi) XorData(data1 []byte, data2 []byte) ([]byte, error) {
if len(data1) == 0 || len(data2) == 0 {
return nil, fmt.Errorf("empty input data")
}
if len(data1) != len(data2) {
return nil, fmt.Errorf("input data length mismatch")
}
result := make([]byte, len(data1))
for i := 0; i < len(data1); i++ {
result[i] = data1[i] ^ data2[i]
}
return result, nil
}
func main() {
cwd, err := os.Getwd()
if err != nil {

View File

@ -99,8 +99,14 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
apiMethod.Name = funcDecl.Name.Name
for _, param := range funcDecl.Type.Params.List {
var apiPar api.Val
ident := param.Type.(*ast.Ident)
switch ident.Name {
if len(param.Names) != 1 {
return nil, fmt.Errorf("all parameters in method %s should be named", apiMethod.Name)
}
switch paramType := param.Type.(type) {
case *ast.Ident:
switch paramType.Name {
case "int":
apiPar.Type = api.TInt
case "string":
@ -108,11 +114,20 @@ func (p *GoApiParser) parseFile(sourceFile string) ([]api.Endpoint, error) {
case "bool":
apiPar.Type = api.TBool
default:
return nil, fmt.Errorf("parameter type %s is not supported yet", ident.Name)
return nil, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
}
if len(param.Names) != 1 {
return nil, fmt.Errorf("all parameters in method %s should be named", apiMethod.Name)
case *ast.ArrayType:
switch elementType := paramType.Elt.(type) {
case *ast.Ident:
switch elementType.Name {
case "byte":
apiPar.Type = api.TBlob
default:
return nil, fmt.Errorf("parameter type %s is not supported yet", paramType.Name)
}
}
}
apiPar.Name = param.Names[0].Name
apiMethod.Params = append(apiMethod.Params, apiPar)
}