| 35 | } |
| 36 | |
| 37 | func (h *Hex) Call(args []super.Value) super.Value { |
| 38 | val := args[0].Under() |
| 39 | if val.IsNull() { |
| 40 | return super.Null |
| 41 | } |
| 42 | switch val.Type().ID() { |
| 43 | case super.IDBytes: |
| 44 | return super.NewString(hex.EncodeToString(val.Bytes())) |
| 45 | case super.IDString: |
| 46 | b, err := hex.DecodeString(super.DecodeString(val.Bytes())) |
| 47 | if err != nil { |
| 48 | return h.sctx.WrapError("hex: string argument is not hexidecimal", val) |
| 49 | } |
| 50 | return super.NewBytes(b) |
| 51 | default: |
| 52 | return h.sctx.WrapError("base64: argument must a bytes or string type", val) |
| 53 | } |
| 54 | } |