Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum support #17

Open
glycerine opened this issue Apr 14, 2015 · 3 comments
Open

enum support #17

glycerine opened this issue Apr 14, 2015 · 3 comments

Comments

@glycerine
Copy link
Owner

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
Copy link

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
Copy link
Owner Author

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
Copy link

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

I found out about this repo via avelino/awesome-go#353, but I am not using it at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants