Skip to content

Commit

Permalink
add bool
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjit-bhat committed Jun 9, 2024
1 parent d016c8c commit cdc9f9b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rpc/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ func genFieldWrite(field *types.Var) ast.Stmt {
},
},
}
case types.Bool:
call = &ast.CallExpr{
Fun: &ast.SelectorExpr{
X: &ast.Ident{Name: "marshalutil"},
Sel: &ast.Ident{Name: "WriteBool"},
},
Args: []ast.Expr{
&ast.Ident{Name: "b"},
&ast.SelectorExpr{
X: &ast.Ident{Name: "o"},
Sel: &ast.Ident{Name: name},
},
},
}
default:
log.Fatal("unsupported type: ", basic.Name())
}
Expand Down Expand Up @@ -182,6 +196,14 @@ func genFieldRead(field *types.Var) []ast.Stmt {
},
Args: []ast.Expr{&ast.Ident{Name: "b"}},
}
case types.Bool:
call = &ast.CallExpr{
Fun: &ast.SelectorExpr{
X: &ast.Ident{Name: "marshalutil"},
Sel: &ast.Ident{Name: "ReadBool"},
},
Args: []ast.Expr{&ast.Ident{Name: "b"}},
}
default:
log.Fatal("unsupported type: ", basic.Name())
}
Expand Down
1 change: 1 addition & 0 deletions rpc/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var data = []entry{
{"alias/alias.go", "alias/alias.golden", 1},
{"mult/mult.go", "mult/mult.golden", 3},
{"otherpkg/otherpkg.go", "otherpkg/otherpkg.golden", 1},
{"bool/bool.go", "bool/bool.golden", 1},
}

// tmpWrite writes data to a tmp file and returns the tmp file name.
Expand Down
5 changes: 5 additions & 0 deletions rpc/testdata/bool/bool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package rpc

type arg struct {
x bool
}
30 changes: 30 additions & 0 deletions rpc/testdata/bool/bool.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Auto-generated from spec "github.com/mit-pdos/pav/rpc/testdata/bool/bool.go"
// using compiler "github.com/mit-pdos/pav/rpc".
package rpc

import (
"github.com/mit-pdos/pav/marshalutil"
"github.com/tchajed/marshal"
)

type errorTy = bool

const (
errNone errorTy = false
errSome errorTy = true
)

func (o *arg) encode() []byte {
var b = make([]byte, 0)
b = marshalutil.WriteBool(b, o.x)
return b
}
func (o *arg) decode(b0 []byte) ([]byte, errorTy) {
var b = b0
x, b, err := marshalutil.ReadBool(b)
if err {
return nil, err
}
o.x = x
return b, errNone
}

0 comments on commit cdc9f9b

Please sign in to comment.