(args ...vector.Any)
| 14 | } |
| 15 | |
| 16 | func (b *Base64) Call(args ...vector.Any) vector.Any { |
| 17 | if vec, ok := expr.CheckForNullThenError(args); ok { |
| 18 | return vec |
| 19 | } |
| 20 | val := vector.Under(args[0]) |
| 21 | switch val.Type().ID() { |
| 22 | case super.IDBytes: |
| 23 | out := vector.NewStringEmpty(0) |
| 24 | for i := uint32(0); i < val.Len(); i++ { |
| 25 | bytes := vector.BytesValue(val, i) |
| 26 | out.Append(base64.StdEncoding.EncodeToString(bytes)) |
| 27 | } |
| 28 | return out |
| 29 | case super.IDString: |
| 30 | errvals := vector.NewStringEmpty(0) |
| 31 | tags := make([]uint32, val.Len()) |
| 32 | out := vector.NewBytesEmpty(0) |
| 33 | for i := uint32(0); i < val.Len(); i++ { |
| 34 | s := vector.StringValue(val, i) |
| 35 | bytes, err := base64.StdEncoding.DecodeString(s) |
| 36 | if err != nil { |
| 37 | errvals.Append(s) |
| 38 | tags[i] = 1 |
| 39 | continue |
| 40 | } |
| 41 | out.Append(bytes) |
| 42 | } |
| 43 | err := vector.NewWrappedError(b.sctx, "base64: string argument is not base64", errvals) |
| 44 | return vector.NewDynamic(tags, []vector.Any{out, err}) |
| 45 | default: |
| 46 | return vector.NewWrappedError(b.sctx, "base64: argument must a bytes or string type", val) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | type Hex struct { |
| 51 | sctx *super.Context |
nothing calls this directly
no test coverage detected