Skip to content

Commit

Permalink
Update docs on IO methods (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Nov 18, 2024
1 parent da44524 commit 7184cb0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cel/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ func AstToString(a *Ast) (string, error) {
return parser.Unparse(a.impl.Expr(), a.impl.SourceInfo())
}

// RefValueToValue converts between ref.Val and api.expr.Value.
// RefValueToValue converts between ref.Val and google.api.expr.v1alpha1.Value.
// The result Value is the serialized proto form. The ref.Val must not be error or unknown.
func RefValueToValue(res ref.Val) (*exprpb.Value, error) {
return ValueAsAlphaProto(res)
}

// ValueAsAlphaProto converts between ref.Val and google.api.expr.v1alpha1.Value.
// The result Value is the serialized proto form. The ref.Val must not be error or unknown.
func ValueAsAlphaProto(res ref.Val) (*exprpb.Value, error) {
canonical, err := ValueAsProto(res)
if err != nil {
Expand All @@ -118,6 +120,8 @@ func ValueAsAlphaProto(res ref.Val) (*exprpb.Value, error) {
return alpha, err
}

// ValueAsProto converts between ref.Val and cel.expr.Value.
// The result Value is the serialized proto form. The ref.Val must not be error or unknown.
func ValueAsProto(res ref.Val) (*celpb.Value, error) {
switch res.Type() {
case types.BoolType:
Expand Down Expand Up @@ -205,11 +209,12 @@ var (
anyPbType = reflect.TypeOf(&anypb.Any{})
)

// ValueToRefValue converts between exprpb.Value and ref.Val.
// ValueToRefValue converts between google.api.expr.v1alpha1.Value and ref.Val.
func ValueToRefValue(adapter types.Adapter, v *exprpb.Value) (ref.Val, error) {
return AlphaProtoAsValue(adapter, v)
}

// AlphaProtoAsValue converts between google.api.expr.v1alpha1.Value and ref.Val.
func AlphaProtoAsValue(adapter types.Adapter, v *exprpb.Value) (ref.Val, error) {
canonical := &celpb.Value{}
if err := convertProto(v, canonical); err != nil {
Expand All @@ -218,6 +223,7 @@ func AlphaProtoAsValue(adapter types.Adapter, v *exprpb.Value) (ref.Val, error)
return ProtoAsValue(adapter, canonical)
}

// ProtoAsValue converts between cel.expr.Value and ref.Val.
func ProtoAsValue(adapter types.Adapter, v *celpb.Value) (ref.Val, error) {
switch v.Kind.(type) {
case *celpb.Value_NullValue:
Expand Down

0 comments on commit 7184cb0

Please sign in to comment.