ExprLiteral creates a literal (constant) Expr.
(id int64, value any)
| 270 | |
| 271 | // ExprLiteral creates a literal (constant) Expr. |
| 272 | func ExprLiteral(id int64, value any) *exprpb.Expr { |
| 273 | var literal *exprpb.Constant |
| 274 | switch v := value.(type) { |
| 275 | case bool: |
| 276 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_BoolValue{ |
| 277 | BoolValue: v}} |
| 278 | case int64: |
| 279 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_Int64Value{ |
| 280 | Int64Value: v}} |
| 281 | case uint64: |
| 282 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_Uint64Value{ |
| 283 | Uint64Value: v}} |
| 284 | case float64: |
| 285 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_DoubleValue{ |
| 286 | DoubleValue: v}} |
| 287 | case string: |
| 288 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_StringValue{ |
| 289 | StringValue: v}} |
| 290 | case structpb.NullValue: |
| 291 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_NullValue{ |
| 292 | NullValue: v}} |
| 293 | case []byte: |
| 294 | literal = &exprpb.Constant{ConstantKind: &exprpb.Constant_BytesValue{ |
| 295 | BytesValue: v}} |
| 296 | default: |
| 297 | panic("literal type not implemented") |
| 298 | } |
| 299 | return &exprpb.Expr{Id: id, ExprKind: &exprpb.Expr_ConstExpr{ConstExpr: literal}} |
| 300 | } |
| 301 | |
| 302 | // ExprCall creates a call Expr. |
| 303 | func ExprCall(id int64, function string, args ...*exprpb.Expr) *exprpb.Expr { |