glycerine / bambam

auto-generate capnproto schema from your golang source files. Depends on go-capnproto-1.0 at https://github.com/glycerine/go-capnproto
MIT License
65 stars 12 forks source link

enum support #17

Open glycerine opened 9 years ago

glycerine commented 9 years ago

Hi Björn (@HyperDrummer),

I'm surfacing your email question to a ticket so it is public; other people may have the same question.

I haven't implemented enum support. If you would like to assist with this, the first step would be to write down several examples of the starting and ending text that involve transformation of enums, and then to put those into a test file. The bambam project is entirely test driven (BDD to the extent possible), and this is an especially valuable approach for compilers (like bambam). Once you have a failing test in place, we can look at how to implement it. I would suggest starting a new branch so that the master doesn't have the failing test on it.

Best regards,

Jason

You asked:

Imagine these structs:

type MyStruct struct {
    Hello []string `capid:"0"`
    World []int    `capid:"1"`
}

type People struct {
    Name     string `capid:"0"`
    LastName string `capid:"1"`
}

type MType int

const (
    PeopleType MType = iota
    MyStructType
)

type MsgType struct {
    Msg     MType `capid:"0"`
    MsgSize int   `capid:"1"`
}

For these go structures I want to create a schema with bambam including the code generation. Ok, now I call bambam and what I end up with ist the following schema:

@0x827b101c9c0b86fb;
using Go = import "go.capnp";
$Go.package("main");
$Go.import("testpkg");

struct MsgTypeCapn { 
   msg      @0:   Int64; 
   msgSize  @1:   Int64; 
} 

struct MyStructCapn { 
   hello  @0:   List(Text); 
   world  @1:   List(Int64); 
} 

struct PeopleCapn { 
   name      @0:   Text; 
   lastName  @1:   Text; 
} 

In the generated code:

func MsgTypeCapnToGo(src MsgTypeCapn, dest *MsgType) *MsgType {
  if dest == nil {
    dest = &MsgType{}
  }
  dest.Msg = *MTypeCapnToGo(src.Msg(), nil)
  dest.MsgSize = int(src.MsgSize())

  return dest
}

which leads to build errors:

./translateCapn.go:37: undefined: MTypeCapnToGo ./translateCapn.go:47: undefined: MTypeGoToCapn

The undefined data types never got generated.

Do you have an idea how to use enums with code generation? Thanks in advance

Björn

dmitshur commented 9 years ago

You should used fenced code blocks for code, that way it's easier to read (indentation preserved, mono font, optional highlighting, and content won't get misinterpreted as other markup).

https://help.github.com/articles/github-flavored-markdown/#fenced-code-blocks

glycerine commented 9 years ago

Hi Dmitri (@shurcooL), thanks for your comment. I've appreciated your contributions to the Go community, particularly go-goon which I find invaluable. Are you using bambam?

dmitshur commented 9 years ago

Hi @glycerine, I'm glad you found some of my work useful!

I found out about this repo via https://github.com/avelino/awesome-go/pull/353, but I am not using it at this time.