(args ...vector.Any)
| 52 | } |
| 53 | |
| 54 | func (h *Hex) Call(args ...vector.Any) vector.Any { |
| 55 | if vec, ok := expr.CheckForNullThenError(args); ok { |
| 56 | return vec |
| 57 | } |
| 58 | val := vector.Under(args[0]) |
| 59 | switch val.Type().ID() { |
| 60 | case super.IDBytes: |
| 61 | out := vector.NewStringEmpty(val.Len()) |
| 62 | for i := uint32(0); i < val.Len(); i++ { |
| 63 | bytes := vector.BytesValue(val, i) |
| 64 | out.Append(hex.EncodeToString(bytes)) |
| 65 | } |
| 66 | return out |
| 67 | case super.IDString: |
| 68 | errvals := vector.NewStringEmpty(0) |
| 69 | tags := make([]uint32, val.Len()) |
| 70 | out := vector.NewBytesEmpty(0) |
| 71 | for i := uint32(0); i < val.Len(); i++ { |
| 72 | s := vector.StringValue(val, i) |
| 73 | bytes, err := hex.DecodeString(s) |
| 74 | if err != nil { |
| 75 | errvals.Append(s) |
| 76 | tags[i] = 1 |
| 77 | continue |
| 78 | } |
| 79 | out.Append(bytes) |
| 80 | } |
| 81 | err := vector.NewWrappedError(h.sctx, "hex: string argument is not hexidecimal", errvals) |
| 82 | return vector.NewDynamic(tags, []vector.Any{out, err}) |
| 83 | default: |
| 84 | return vector.NewWrappedError(h.sctx, "hex: argument must a bytes or string type", val) |
| 85 | } |
| 86 | } |
nothing calls this directly
no test coverage detected