func main() { var err error argParse() codec := collatejson.NewCodec(100) out := make([]byte, 0, len(options.inp)*3+collatejson.MinBufferSize) if options.encode { out, err = codec.Encode([]byte(options.inp), out) if err != nil { log.Fatal(err) } hexout := make([]byte, len(out)*5) n := hex.Encode(hexout, out) fmt.Printf("in : %q\n", options.inp) fmt.Printf("out: %q\n", string(out)) fmt.Printf("hex: %q\n", string(hexout[:n])) } else if options.decode { inpbs := make([]byte, len(options.inp)*5) n, err := hex.Decode(inpbs, []byte(options.inp)) if err != nil { log.Fatal(err) } fmt.Println(n, inpbs[:n]) out, err = codec.Decode([]byte(inpbs[:n]), out) if err != nil { log.Fatal(err) } fmt.Printf("in : %q\n", options.inp) fmt.Printf("out: %q\n", string(out)) } }
func sortFile(filename string) (outs []string) { s, err := ioutil.ReadFile(filename) if err != nil { panic(err.Error()) } codec := collatejson.NewCodec(100) codec.SortbyArrayLen(options.arrLenPrefix) codec.SortbyPropertyLen(options.mapLenPrefix) outs = encodeLines(codec, s) return }