jmckaskill/go-capnproto — pull request #4 by peterwald (2013-11-22 23:14:49+00:00)
Title: Add support for enumeration tagging in the schema file.

Generate a map[EnumType]string that maps the enumeration codes to a friendly string. The string is taken from a $tag annotation added to each declaration in the schema file.

for example the following schema definition

using Go = import "../../jmckaskill/go-capnproto/go.capnp";

$Go.package("sample");

@0xa930f62d3f8257e3;

enum Fruits {
apples @0 $Go.tag("Apples");
bananas @1 $Go.tag("Bananas");
oranges @2 $Go.tag("Oranges");
}

now generates

package sample

// AUTO GENERATED - DO NOT EDIT

import (
C "github.com/jmckaskill/go-capnproto"
"unsafe"
)

type Fruits uint16

const (
FRUITS_APPLES Fruits = 0 // Apples
FRUITS_BANANAS = 1 // Bananas
FRUITS_ORANGES = 2 // Oranges
)

var Fruits_Tags map[Fruits]string = map[Fruits]string{
FRUITS_APPLES: "Apples",
FRUITS_BANANAS: "Bananas",
FRUITS_ORANGES: "Oranges",
}

type Fruits_List C.PointerList

func NewFruitsList(s *C.Segment, sz int) Fruits_List { return Fruits_List(s.NewUInt16List(sz)) }
func (s Fruits_List) Len() int { return C.UInt16List(s).Len() }
func (s Fruits_List) At(i int) Fruits { return Fruits(C.UInt16List(s).At(i)) }
func (s Fruits_List) ToArray() []Fruits {
return *(*[]Fruits)(unsafe.Pointer(C.UInt16List(s).ToEnumArray()))
}