@0xdbb9ad1f14bf0b36;  # unique file ID, generated by `capnp id`
struct Foo @0x8db435604d0d3723 <beginfold id='1'>{</beginfold id='1'> <endfold id='1'>}</endfold id='1'>

struct Person <beginfold id='1'>{</beginfold id='1'>
  name @0 :Text;
  birthdate @3 :Date;
  phones @2 :List(PhoneNumber);

  struct PhoneNumber <beginfold id='1'>{</beginfold id='1'>
    type @1 :Type;

    enum Type <beginfold id='1'>{</beginfold id='1'>
      mobile @0;
      home @1;
      work @2;
    <endfold id='1'>}</endfold id='1'>
  <endfold id='1'>}</endfold id='1'>
<endfold id='1'>}</endfold id='1'>

struct Dummy <beginfold id='1'>{</beginfold id='1'>
  byName @0 :Map(Text, Person);

  foo @0 :Int32 = 123;
  bar @1 :Text = "blah";
  baz @2 :List(Bool) = [ true, false, false, true ];
  qux @3 :Person = (name = "Bob", email = "bob@example.com");
  corge @4 :Void = void;
  grault @5 :Data = 0x"a1 40 33";

  union <beginfold id='1'>{</beginfold id='1'>
    circle @1 :Float64 = nan;      # radius
    square @2 :Float64 = 12.23e+2; # width
  <endfold id='1'>}</endfold id='1'>

  address :group <beginfold id='1'>{</beginfold id='1'>
    # Note:  This is a terrible way to use groups, and meant
    #        only to demonstrate the syntax.
    houseNumber @8 :UInt32 = 01238;
    city @10 :Text = "abc\ndef\p\xax\xabc";
  <endfold id='1'>}</endfold id='1'>
<endfold id='1'>}</endfold id='1'>

const pi :Float32 = 3.14159;
const foo :Int32 = 0x123;
const bar :SomeStruct = (id = .foo, message = .bar);

interface Directory extends(Node) <beginfold id='1'>{</beginfold id='1'>
  list @0 () -> (list :List(Entry));
  create @1 (name :Text) -> (file :File);
  delete @4 (name :Text);
  link @5 (name :Text, node :Node);
  read @1 (startAt :UInt64 = 0, amount :UInt64 = 0xffffffffffffffff)
       -> (data :Data);
<endfold id='1'>}</endfold id='1'>

interface Assignable(T) <beginfold id='1'>{</beginfold id='1'>
  # A generic interface, with non-generic methods.
  get @0 () -> (value :T);
  set @1 (value :T) -> ();
<endfold id='1'>}</endfold id='1'>

interface AssignableFactory <beginfold id='1'>{</beginfold id='1'>
  newAssignable @0 [T] (initialValue :T)
      -> (assignable :Assignable(T));
  # A generic method.
<endfold id='1'>}</endfold id='1'>

newUnsetAssignable @1 [T] () -> (assignable :Assignable(T));
getNamedAssignable @2 (name :Text) -> (assignable :Assignable);

struct Baz <beginfold id='1'>{</beginfold id='1'>
  bar @0 :Foo.Bar;

  using Foo.Bar;
  bar @0 :Bar;

  using T = Foo.Bar;
  bar @0 :T;

  baz @0 :import "bar.capnp".Baz;
  # Use type "Baz" defined in bar.capnp.
<endfold id='1'>}</endfold id='1'>

using Bar = import "bar.capnp";
using import "bar.capnp".Baz;

annotation foo(struct, enum) :Text;
# Declare an annotation 'foo' which applies to struct and enum types.

struct MyType $foo("bar") <beginfold id='1'>{</beginfold id='1'>
  # ...
<endfold id='1'>}</endfold id='1'>

annotation baz(*) :Int32;
annotation myAnnotation(struct) :Int32 $baz(10);

$baz(1);  # Annotate the file.

struct MyStruct $baz(2) <beginfold id='1'>{</beginfold id='1'>
  myField @0 :Text = "default" $baz(3);
  number @1 :Int32 $qux;
  myUnion :union $baz(4) <beginfold id='1'>{</beginfold id='1'>
    # ...
  <endfold id='1'>}</endfold id='1'>
<endfold id='1'>}</endfold id='1'>

interface MyInterface $baz(7) <beginfold id='1'>{</beginfold id='1'>
  myMethod @0 (myParam :Text $baz(9)) -> () $baz(8);
<endfold id='1'>}</endfold id='1'>

const myConst :Int32 = 123 $baz(11);

$corge(string = "hello", number = 123);
$grault();  # value defaults to 123
