Skip to content

Commit

Permalink
ft. working on schema embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
glycerine committed Dec 27, 2016
1 parent 09eac6d commit d6dc4bf
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 98 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func Run(mode gen.Method, c *cfg.ZebraConfig) error {
}
}

return printer.PrintFile(newFilename(c.Out, c.GoFile, fs.Package), fs, mode, c)
return printer.PrintFile(newFilename(c.Out, c.GoFile, fs.Package), fs, mode, c, c.GoFile)
}

// picks a new file name based on input flags and input filename(s).
Expand Down
16 changes: 15 additions & 1 deletion printer/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ func infof(s string, v ...interface{}) {
// PrintFile prints the methods for the provided list
// of elements to the given file name and canonical
// package path.
func PrintFile(file string, f *parse.FileSet, mode gen.Method, cfg *cfg.ZebraConfig) error {
func PrintFile(file string, f *parse.FileSet, mode gen.Method, cfg *cfg.ZebraConfig, pathGoSource string) error {
out, tests, err := generate(f, mode, cfg)
if err != nil {
return err
}

// add the serialized msgpack2 zebra schema in []byte form.
tr, err := parse.TranslateToZebraSchema(pathGoSource, f)
if err != nil {
return err
}
sby, err := tr.MarshalMsg(nil)
if err != nil {
return err
}
_, err = fmt.Fprintf(out, "\nvar ZebraSchemaInMsgpack2Format = %#v\n", sby)
if err != nil {
return err
}

// we'll run goimports on the main file
// in another goroutine, and run it here
// for the test file. empirically, this
Expand Down
Binary file modified testdata/my.z
Binary file not shown.
192 changes: 96 additions & 96 deletions testdata/my.z.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,6 @@
"SourcePackage": "main",
"ZebraSchemaId": 1947397430155838,
"Structs": [
{
"StructName": "A",
"Fields": [
{
"Zid": 0,
"FieldGoName": "Name",
"FieldTagName": "name",
"FieldTypeStr": "string",
"FieldCategory": 23,
"FieldPrimitive": 2,
"FieldFullType": {
"Kind": 2,
"Str": "string"
}
},
{
"Zid": 1,
"FieldGoName": "Bday",
"FieldTagName": "Bday",
"FieldTypeStr": "time.Time",
"FieldCategory": 23,
"FieldPrimitive": 20,
"FieldFullType": {
"Kind": 20,
"Str": "Time"
}
},
{
"Zid": 2,
"FieldGoName": "Phone",
"FieldTagName": "phone",
"FieldTypeStr": "string",
"FieldCategory": 23,
"FieldPrimitive": 2,
"FieldFullType": {
"Kind": 2,
"Str": "string"
},
"OmitEmpty": true
},
{
"Zid": 3,
"FieldGoName": "Sibs",
"FieldTagName": "Sibs",
"FieldTypeStr": "int",
"FieldCategory": 23,
"FieldPrimitive": 13,
"FieldFullType": {
"Kind": 13,
"Str": "int"
},
"OmitEmpty": true
},
{
"Zid": 4,
"FieldGoName": "GPA",
"FieldTagName": "GPA",
"FieldTypeStr": "float64",
"FieldCategory": 23,
"FieldPrimitive": 4,
"FieldFullType": {
"Kind": 4,
"Str": "float64"
}
},
{
"Zid": 5,
"FieldGoName": "Friend",
"FieldTagName": "Friend",
"FieldTypeStr": "bool",
"FieldCategory": 23,
"FieldPrimitive": 18,
"FieldFullType": {
"Kind": 18,
"Str": "bool"
}
}
]
},
{
"StructName": "Sys",
"Fields": [
{
"Zid": 0,
"FieldGoName": "F",
"FieldTagName": "F",
"FieldTypeStr": "interface{}",
"FieldCategory": 23,
"FieldPrimitive": 19,
"FieldFullType": {
"Kind": 19,
"Str": "Intf"
}
}
]
},
{
"StructName": "S2",
"Fields": [
Expand Down Expand Up @@ -269,6 +173,102 @@
}
}
]
},
{
"StructName": "A",
"Fields": [
{
"Zid": 0,
"FieldGoName": "Name",
"FieldTagName": "name",
"FieldTypeStr": "string",
"FieldCategory": 23,
"FieldPrimitive": 2,
"FieldFullType": {
"Kind": 2,
"Str": "string"
}
},
{
"Zid": 1,
"FieldGoName": "Bday",
"FieldTagName": "Bday",
"FieldTypeStr": "time.Time",
"FieldCategory": 23,
"FieldPrimitive": 20,
"FieldFullType": {
"Kind": 20,
"Str": "Time"
}
},
{
"Zid": 2,
"FieldGoName": "Phone",
"FieldTagName": "phone",
"FieldTypeStr": "string",
"FieldCategory": 23,
"FieldPrimitive": 2,
"FieldFullType": {
"Kind": 2,
"Str": "string"
},
"OmitEmpty": true
},
{
"Zid": 3,
"FieldGoName": "Sibs",
"FieldTagName": "Sibs",
"FieldTypeStr": "int",
"FieldCategory": 23,
"FieldPrimitive": 13,
"FieldFullType": {
"Kind": 13,
"Str": "int"
},
"OmitEmpty": true
},
{
"Zid": 4,
"FieldGoName": "GPA",
"FieldTagName": "GPA",
"FieldTypeStr": "float64",
"FieldCategory": 23,
"FieldPrimitive": 4,
"FieldFullType": {
"Kind": 4,
"Str": "float64"
}
},
{
"Zid": 5,
"FieldGoName": "Friend",
"FieldTagName": "Friend",
"FieldTypeStr": "bool",
"FieldCategory": 23,
"FieldPrimitive": 18,
"FieldFullType": {
"Kind": 18,
"Str": "bool"
}
}
]
},
{
"StructName": "Sys",
"Fields": [
{
"Zid": 0,
"FieldGoName": "F",
"FieldTagName": "F",
"FieldTypeStr": "interface{}",
"FieldCategory": 23,
"FieldPrimitive": 19,
"FieldFullType": {
"Kind": 19,
"Str": "Intf"
}
}
]
}
],
"Imports": [
Expand Down

0 comments on commit d6dc4bf

Please sign in to comment.