Skip to content
Permalink
Browse files

use b64, and add prototype string table

  • Loading branch information
jennybuckley committed Nov 12, 2019
1 parent 0f6f3c3 commit 25048e336b2ed2692c0545b1a59cbb7019070390
Showing with 941 additions and 11 deletions.
  1. +3 −3 fieldpath/serialize_test.go
  2. +9 −3 fieldpath/strings/reader.go
  3. +6 −4 fieldpath/strings/stream.go
  4. +2 −1 fieldpath/strings/table.go
  5. +921 −0 fieldpath/strings/v2.go
@@ -83,9 +83,9 @@ func TestSerializeV1GoldenData(t *testing.T) {

func TestSerializeV2GoldenData(t *testing.T) {
examples := []string{
`[1,0,!A,3,{!B:{!C:!A}},1,!B,1,["t",!B],1,{!C:[!B]},2,2]`,
`[1,0,"aaa",0,"aab",0,"aac",0,"aad",0,"aae",0,"aaf",3,{!A:"first"},3,{!A:"second"},3,{!B:443,!C:"tcp"},3,{!B:443,!C:"udp"},1,1,1,2,1,3,1,"aa",1,"ab",1,true,2,1,2,2,2,3,2,4]`,
`[1,4,"aaa",[7,{!A:"second"},[5,3,[0,"aab"]],1,3,1,true],4,"aab",[0,"aaa",4,"aaf",[7,{!B:443,!C:"udp"},[3,{!B:443,!C:"tcp"}]],3,{!A:"first"}],4,"aac",[4,"aaa",[1,1],0,"aac",5,3,[3,{!A:"second"}]],4,"aad",[4,"aac",[1,1],4,"aaf",[7,{!A:"first"},[3,{!A:"first"}]],6,1,[2,1,6,3,[1,true]]],4,"aae",[0,"aae",7,{!B:443,!C:"tcp"},[3,{!B:443,!C:"udp"}],6,4,[0,"aaf"]],4,"aaf",[6,1,[0,"aac"],2,2,2,3],7,{!A:"first"},[4,"aad",[0,"aaf"]],7,{!B:443,!C:"tcp"},[4,"aaa",[0,"aad"]],7,{!B:443,!C:"udp"},[0,"aac",7,{!A:"first"},[2,3],7,{!B:443,!C:"udp"},[2,4]],5,1,[4,"aac",[2,4],0,"aaf",3,{!B:443,!C:"tcp"}],5,2,[4,"aad",[0,"aaf"],2,1],5,3,[0,"aaa",3,{!A:"first"},2,2],5,"aa",[4,"aab",[0,"aaf"],0,"aae",7,{!A:"first"},[0,"aad"],2,2],5,"ab",[4,"aaf",[2,4],3,{!B:443,!C:"tcp"},3,{!B:443,!C:"udp"},5,1,[3,{!B:443,!C:"udp"}],6,1,[4,"aae",[2,4]]],5,true,[7,{!A:"second"},[0,"aaa"],6,2,[3,{!B:443,!C:"tcp"}]],6,1,[6,3,[0,"aaf"]],6,2,[0,"aae",7,{!B:443,!C:"tcp"},[1,1]],6,3,[4,"aab",[5,true,[1,"aa"]],0,"aaf",2,1],6,4,[5,"aa",[4,"aab",[3,{!A:"second"}]]]]`,
`[2,0,!0,3,{!1:{!2:!+}},1,!B,1,["t",!/],1,{!C:[!B]},2,2]`,
`[2,0,"aaa",0,"aab",0,"aac",0,"aad",0,"aae",0,"aaf",3,{!A:"first"},3,{!A:"second"},3,{!B:443,!C:"tcp"},3,{!B:443,!C:"udp"},1,1,1,2,1,3,1,"aa",1,"ab",1,true,2,1,2,2,2,3,2,4]`,
`[2,4,"aaa",[7,{!A:"second"},[5,3,[0,"aab"]],1,3,1,true],4,"aab",[0,"aaa",4,"aaf",[7,{!B:443,!C:"udp"},[3,{!B:443,!C:"tcp"}]],3,{!A:"first"}],4,"aac",[4,"aaa",[1,1],0,"aac",5,3,[3,{!A:"second"}]],4,"aad",[4,"aac",[1,1],4,"aaf",[7,{!A:"first"},[3,{!A:"first"}]],6,1,[2,1,6,3,[1,true]]],4,"aae",[0,"aae",7,{!B:443,!C:"tcp"},[3,{!B:443,!C:"udp"}],6,4,[0,"aaf"]],4,"aaf",[6,1,[0,"aac"],2,2,2,3],7,{!A:"first"},[4,"aad",[0,"aaf"]],7,{!B:443,!C:"tcp"},[4,"aaa",[0,"aad"]],7,{!B:443,!C:"udp"},[0,"aac",7,{!A:"first"},[2,3],7,{!B:443,!C:"udp"},[2,4]],5,1,[4,"aac",[2,4],0,"aaf",3,{!B:443,!C:"tcp"}],5,2,[4,"aad",[0,"aaf"],2,1],5,3,[0,"aaa",3,{!A:"first"},2,2],5,"aa",[4,"aab",[0,"aaf"],0,"aae",7,{!A:"first"},[0,"aad"],2,2],5,"ab",[4,"aaf",[2,4],3,{!B:443,!C:"tcp"},3,{!B:443,!C:"udp"},5,1,[3,{!B:443,!C:"udp"}],6,1,[4,"aae",[2,4]]],5,true,[7,{!A:"second"},[0,"aaa"],6,2,[3,{!B:443,!C:"tcp"}]],6,1,[6,3,[0,"aaf"]],6,2,[0,"aae",7,{!B:443,!C:"tcp"},[1,1]],6,3,[4,"aab",[5,true,[1,"aa"]],0,"aaf",2,1],6,4,[5,"aa",[4,"aab",[3,{!A:"second"}]]]]`,
}
for i, str := range examples {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
@@ -161,10 +161,16 @@ func parseInt(b []byte) int {
func parseBase64(b []byte) int {
n := 0
for _, d := range b {
if d >= byte('A') && d <= byte('z') {
if d >= byte('A') && d <= byte('Z') {
n = n*64 + int(d) - int('A')
} else if d >= byte('0') && d <= byte('/') {
n = n*64 + int(d) - int('0') + int('z') - int('A') + 1
} else if d >= byte('a') && d <= byte('z') {
n = n*64 + int(d) - int('a') + 26
} else if d >= byte('0') && d <= byte('9') {
n = n*64 + int(d) - int('0') + 52
} else if d == byte('+') {
n = n*64 + 62
} else if d == byte('/') {
n = n*64 + 63
}
}
return n
@@ -17,6 +17,8 @@ limitations under the License.
package strings

import (
"fmt"

"sigs.k8s.io/structured-merge-diff/value"
)

@@ -59,16 +61,16 @@ func (s *streamWithStringTable) WriteObjectField(str string) {
}
}

var digits = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/+")
var digits = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")

func toBase64(x int) string {
if x == 0 {
return "A"
}
var b []byte
var s string
for x > 0 {
b = append(b, digits[x%64])
s = fmt.Sprintf("%v%v", string(digits[x%64]), s)
x /= 64
}
return string(b)
return s
}
@@ -27,9 +27,10 @@ var reverseTables []map[string]int
var versions []string = []string{
v0,
v1,
v2,
}

var DefaultVersion = 1
var DefaultVersion = 2

func init() {
for _, v := range versions {

0 comments on commit 25048e3

Please sign in to comment.
You can’t perform that action at this time.