diff --git a/src/cmd/jsondebug/common/helpers.go b/src/cmd/jsondebug/common/helpers.go index e94390f0a..08e77de0a 100644 --- a/src/cmd/jsondebug/common/helpers.go +++ b/src/cmd/jsondebug/common/helpers.go @@ -1,8 +1,10 @@ package common import ( + "encoding/json" "fmt" "runtime" + "time" ) const ( @@ -16,7 +18,16 @@ type FooArray struct { } type Foo struct { - A []byte + ID string `json:"id"` + Labels map[string]string `json:"labels"` + ModTime time.Time `json:"modified"` + Deleted bool `json:"deleted,omitempty"` + Content json.RawMessage `json:"data"` +} + +type Content struct { + ID string `json:"id"` + Data []byte `json:"data"` } func PrintMemUsage() { diff --git a/src/cmd/jsondebug/gen/gen.go b/src/cmd/jsondebug/gen/gen.go index a869fe3d9..ac11e2af4 100644 --- a/src/cmd/jsondebug/gen/gen.go +++ b/src/cmd/jsondebug/gen/gen.go @@ -5,8 +5,10 @@ import ( "encoding/json" "fmt" "os" + "time" "github.com/alcionai/corso/src/cmd/jsondebug/common" + "github.com/google/uuid" ) func main() { @@ -28,8 +30,18 @@ func main() { ) return } + content := common.Content{ + ID: uuid.NewString(), + Data: buf, + } + payload, _ := json.Marshal(content) - item := common.Foo{A: buf} + item := common.Foo{ + ID: uuid.NewString(), + Labels: map[string]string{"foo": "bar"}, + ModTime: time.Now(), + Content: payload, + } data.Entries = append(data.Entries, &item) } diff --git a/src/cmd/jsondebug/jsonparser/read.go b/src/cmd/jsondebug/jsonparser/read.go index cd8fa7a3e..7ef452213 100644 --- a/src/cmd/jsondebug/jsonparser/read.go +++ b/src/cmd/jsondebug/jsonparser/read.go @@ -32,20 +32,34 @@ func main() { common.PrintMemUsage() + // var handler func([]byte, []byte, jsonparser.ValueType, int) error + // handler := func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error { + // fmt.Printf("Key: '%s'\n Value: '%s'\n Type: %s\n", string(key), string(value), dataType) + // return nil + // } + jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) { - buf, _, _, errInner := jsonparser.Get(value, "A") + + id, _ := jsonparser.GetString(value, "id") + content, _, _, errInner := jsonparser.Get(value, "data") if errInner != nil { - fmt.Printf("Error decoding input: %v\n", err) + fmt.Printf("Error decoding input: %v\n", errInner) return } - _ = value - cpBuf := make([]byte, len(buf)) - _ = copy(cpBuf, buf) + + cpBuf := make([]byte, len(content)) + _ = copy(cpBuf, content) e := &common.Foo{ - A: cpBuf, + ID: id, + Content: cpBuf, } output.Entries = append(output.Entries, e) + }, "entries") common.PrintMemUsage() + + // for _, e := range output.Entries { + // fmt.Printf("ID: '%s'\n Content: %s \n", e.ID, e.Content) + // } }