func computeOverheads(codec *collatejson.Codec) { var err error items := []string{ "10", "10000", "1000000000", "100000000000000000.0", "123456789123565670.0", "10.2", "10.23456789012", "null", "true", "false", `"hello world"`, `[ 10, 10000, 1000000000, 10.2, 10.23456789012, null, true, false, "hello world" ]`, `{ "a": 10000, "b": 10.23456789012, "c": null, "d": true, "e": false, "f": "hello world" }`, } for _, item := range items { out := make([]byte, 0, 1024) out, err = codec.Encode([]byte(item), out) if err != nil { log.Fatal(err) } fmt.Printf("item: %q\n", item) fmt.Println(" i/p len:", len(item)) fmt.Println(" o/p len:", len(out)) } }
func encodeLines(codec *collatejson.Codec, s []byte) []string { var err error texts, codes := lines(s), make(codeList, 0) for i, x := range texts { code := make([]byte, 0, len(x)*3+collatejson.MinBufferSize) if code, err = codec.Encode(x, code); err != nil { log.Fatal(err) } codes = append(codes, codeObj{i, code}) } outs := doSort(texts, codes) return outs }