(value *v1pb.RowValue)
| 47 | } |
| 48 | |
| 49 | func convertValueToBytesInCSV(value *v1pb.RowValue) []byte { |
| 50 | if value == nil || value.Kind == nil { |
| 51 | return []byte("") |
| 52 | } |
| 53 | switch value.Kind.(type) { |
| 54 | case *v1pb.RowValue_StringValue: |
| 55 | return quoteCSVString(value.GetStringValue()) |
| 56 | case *v1pb.RowValue_Int32Value: |
| 57 | return []byte(strconv.FormatInt(int64(value.GetInt32Value()), 10)) |
| 58 | case *v1pb.RowValue_Int64Value: |
| 59 | return []byte(strconv.FormatInt(value.GetInt64Value(), 10)) |
| 60 | case *v1pb.RowValue_Uint32Value: |
| 61 | return []byte(strconv.FormatUint(uint64(value.GetUint32Value()), 10)) |
| 62 | case *v1pb.RowValue_Uint64Value: |
| 63 | return []byte(strconv.FormatUint(value.GetUint64Value(), 10)) |
| 64 | case *v1pb.RowValue_FloatValue: |
| 65 | return []byte(strconv.FormatFloat(float64(value.GetFloatValue()), 'f', -1, 32)) |
| 66 | case *v1pb.RowValue_DoubleValue: |
| 67 | return []byte(strconv.FormatFloat(value.GetDoubleValue(), 'f', -1, 64)) |
| 68 | case *v1pb.RowValue_BoolValue: |
| 69 | return []byte(strconv.FormatBool(value.GetBoolValue())) |
| 70 | case *v1pb.RowValue_BytesValue: |
| 71 | hexStr := "0x" + hex.EncodeToString(value.GetBytesValue()) |
| 72 | return quoteCSVString(hexStr) |
| 73 | case *v1pb.RowValue_NullValue: |
| 74 | return []byte("") |
| 75 | case *v1pb.RowValue_TimestampValue: |
| 76 | return quoteCSVString(formatTimestamp(value.GetTimestampValue())) |
| 77 | case *v1pb.RowValue_TimestampTzValue: |
| 78 | return quoteCSVString(formatTimestampTz(value.GetTimestampTzValue())) |
| 79 | case *v1pb.RowValue_ValueValue: |
| 80 | return convertValueValueToBytes(value.GetValueValue()) |
| 81 | default: |
| 82 | return []byte("") |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // quoteCSVString wraps a string in double quotes and escapes internal quotes. |
| 87 | func quoteCSVString(s string) []byte { |
no test coverage detected