Sha256: d9aa3e2718d708996c00b623246d27ac42c75ac18428566496f2d8d045cee6db

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

package main

import (
	"encoding/csv"
	"encoding/hex"
	"encoding/json"
	"github.com/vmihailenco/msgpack/v5"
	"io"
	"os"
)

func main() {
	reader := csv.NewReader(os.Stdin)
	defer os.Stdin.Close()

	writer := csv.NewWriter(os.Stdout)
	defer os.Stdout.Close()
	defer writer.Flush()

	for {
		record, err := reader.Read()
		if err == io.EOF {
			break
		}

		writer.Write(processRow(record))
	}
}

func processRow(record []string) []string {
	for i, r := range record {
		if isHexEncoded(r) {
			record[i] = reencodeField(r)
		}
	}

	return record
}

func isHexEncoded(field string) bool {
	return len(field) >= 2 && field[0:2] == "\\x"
}

func reencodeField(field string) string {
	decoded_bytes, err := hex.DecodeString(field[2:])
	if err != nil {
		return field
	}

	var intermediate interface{}
	err = msgpack.Unmarshal(decoded_bytes, &intermediate)
	if err != nil {
		return field
	}

	return encode(intermediate)
}

func encode(data interface{}) string {
	result, err := json.Marshal(data)
	if err != nil {
		panic(err)
	}

	return string(result)
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dynflow-1.9.0 extras/expand/main.go
dynflow-1.8.3 extras/expand/main.go
dynflow-1.8.2 extras/expand/main.go
dynflow-1.8.1 extras/expand/main.go
dynflow-1.8.0 extras/expand/main.go
dynflow-1.7.0 extras/expand/main.go
dynflow-1.6.11 extras/expand/main.go
dynflow-1.6.10 extras/expand/main.go
dynflow-1.6.8 extras/expand/main.go
dynflow-1.6.7 extras/expand/main.go
dynflow-1.6.6 extras/expand/main.go
dynflow-1.6.5 extras/expand/main.go
dynflow-1.6.4 extras/expand/main.go
dynflow-1.6.3 extras/expand/main.go