Add docstrings to schema.capnp

Add docstrings to schema.capnp

# Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
# Licensed under the MIT License:
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

using Cxx = import "/capnp/c++.capnp";

@0xa93fc509624c72d9;
$Cxx.namespace("capnp::schema");

using Id = UInt64;
# The globally-unique ID of a file, type, or annotation.

struct Node {
  id @0 :Id;

  displayName @1 :Text;
  # Name to present to humans to identify this Node.  You should not attempt to parse this.  Its
  # format could change.  It is not guaranteed to be unique.
  #
  # (On Zooko's triangle, this is the node's nickname.)

  displayNamePrefixLength @2 :UInt32;
  # If you want a shorter version of `displayName` (just naming this node, without its surrounding
  # scope), chop off this many characters from the beginning of `displayName`.

  scopeId @3 :Id;
  # ID of the lexical parent node.  Typically, the scope node will have a NestedNode pointing back
  # at this node, but robust code should avoid relying on this (and, in fact, group nodes are not
  # listed in the outer struct's nestedNodes, since they are listed in the fields).  `scopeId` is
  # zero if the node has no parent, which is normally only the case with files, but should be
  # allowed for any kind of node (in order to make runtime type generation easier).

  parameters @32 :List(Parameter);
  # If this node is parameterized (generic), the list of parameters. Empty for non-generic types.

  isGeneric @33 :Bool;
  # True if this node is generic, meaning that it or one of its parent scopes has a non-empty
  # `parameters`.

  struct Parameter {
    # Information about one of the node's parameters.

    name @0 :Text;
  }

  nestedNodes @4 :List(NestedNode);
  # List of nodes nested within this node, along with the names under which they were declared.

  struct NestedNode {
    name @0 :Text;
    # Unqualified symbol name.  Unlike Node.displayName, this *can* be used programmatically.
    #
    # (On Zooko's triangle, this is the node's petname according to its parent scope.)

    id @1 :Id;
    # ID of the nested node.  Typically, the target node's scopeId points back to this node, but
    # robust code should avoid relying on this.
  }

  annotations @5 :List(Annotation);
  # Annotations applied to this node.

  union {
    # Info specific to each kind of node.

    file @6 :Void;

    struct :group {
      dataWordCount @7 :UInt16;
      # Size of the data section, in words.

      pointerCount @8 :UInt16;
      # Size of the pointer section, in pointers (which are one word each).

      preferredListEncoding @9 :ElementSize;
      # The preferred element size to use when encoding a list of this struct.  If this is anything
      # other than `inlineComposite` then the struct is one word or less in size and is a candidate
      # for list packing optimization.

      isGroup @10 :Bool;
      # If true, then this "struct" node is actually not an independent node, but merely represents
      # some named union or group within a particular parent struct.  This node's scopeId refers
      # to the parent struct, which may itself be a union/group in yet another struct.
      #
      # All group nodes share the same dataWordCount and pointerCount as the top-level
      # struct, and their fields live in the same ordinal and offset spaces as all other fields in
      # the struct.
      #
      # Note that a named union is considered a special kind of group -- in fact, a named union
      # is exactly equivalent to a group that contains nothing but an unnamed union.

      discriminantCount @11 :UInt16;
      # Number of fields in this struct which are members of an anonymous union, and thus may
      # overlap.  If this is non-zero, then a 16-bit discriminant is present indicating which
      # of the overlapping fields is active.  This can never be 1 -- if it is non-zero, it must be
      # two or more.
      #
      # Note that the fields of an unnamed union are considered fields of the scope containing the
      # union -- an unnamed union is not its own group.  So, a top-level struct may contain a
      # non-zero discriminant count.  Named unions, on the other hand, are equivalent to groups
      # containing unnamed unions.  So, a named union has its own independent schema node, with
      # `isGroup` = true.

      discriminantOffset @12 :UInt32;
      # If `discriminantCount` is non-zero, this is the offset of the union discriminant, in
      # multiples of 16 bits.

      fields @13 :List(Field);
      # Fields defined within this scope (either the struct's top-level fields, or the fields of
      # a particular group; see `isGroup`).
      #
      # The fields are sorted by ordinal number, but note that because groups share the same
      # ordinal space, the field's index in this list is not necessarily exactly its ordinal.
      # On the other hand, the field's position in this list does remain the same even as the
      # protocol evolves, since it is not possible to insert or remove an earlier ordinal.
      # Therefore, for most use cases, if you want to identify a field by number, it may make the
      # most sense to use the field's index in this list rather than its ordinal.
    }

    enum :group {
      enumerants@14 :List(Enumerant);
      # Enumerants ordered by numeric value (ordinal).
    }

    interface :group {
      methods @15 :List(Method);
      # Methods ordered by ordinal.

      superclasses @31 :List(Superclass);
      # Superclasses of this interface.
    }

    const :group {
      type @16 :Type;
      value @17 :Value;
    }

    annotation :group {
      type @18 :Type;

      targetsFile @19 :Bool;
      targetsConst @20 :Bool;
      targetsEnum @21 :Bool;
      targetsEnumerant @22 :Bool;
      targetsStruct @23 :Bool;
      targetsField @24 :Bool;
      targetsUnion @25 :Bool;
      targetsGroup @26 :Bool;
      targetsInterface @27 :Bool;
      targetsMethod @28 :Bool;
      targetsParam @29 :Bool;
      targetsAnnotation @30 :Bool;
    }
  }
}

struct NodeDoc {
  # separate carrier for documentation comments on Nodes,
  # to keep them out of the binary descriptors

  id @0 :Id;
  # ID should exist as Node in the same request

  docComment @1 :Text;

  fieldDocs @2 :List(FieldDoc);
  # valid only if Node is a "struct"
}

struct Field {
  # Schema for a field of a struct.

  name @0 :Text;

  codeOrder @1 :UInt16;
  # Indicates where this member appeared in the code, relative to other members.
  # Code ordering may have semantic relevance -- programmers tend to place related fields
  # together.  So, using code ordering makes sense in human-readable formats where ordering is
  # otherwise irrelevant, like JSON.  The values of codeOrder are tightly-packed, so the maximum
  # value is count(members) - 1.  Fields that are members of a union are only ordered relative to
  # the other members of that union, so the maximum value there is count(union.members).

  annotations @2 :List(Annotation);

  const noDiscriminant :UInt16 = 0xffff;

  discriminantValue @3 :UInt16 = Field.noDiscriminant;
  # If the field is in a union, this is the value which the union's discriminant should take when
  # the field is active.  If the field is not in a union, this is 0xffff.

  union {
    slot :group {
      # A regular, non-group, non-fixed-list field.

      offset @4 :UInt32;
      # Offset, in units of the field's size, from the beginning of the section in which the field
      # resides.  E.g. for a UInt32 field, multiply this by 4 to get the byte offset from the
      # beginning of the data section.

      type @5 :Type;
      defaultValue @6 :Value;

      hadExplicitDefault @10 :Bool;
      # Whether the default value was specified explicitly.  Non-explicit default values are always
      # zero or empty values.  Usually, whether the default value was explicit shouldn't matter.
      # The main use case for this flag is for structs representing method parameters:
      # explicitly-defaulted parameters may be allowed to be omitted when calling the method.
    }

    group :group {
      # A group.

      typeId @7 :Id;
      # The ID of the group's node.
    }
  }

  ordinal :union {
    implicit @8 :Void;
    explicit @9 :UInt16;
    # The original ordinal number given to the field.  You probably should NOT use this; if you need
    # a numeric identifier for a field, use its position within the field array for its scope.
    # The ordinal is given here mainly just so that the original schema text can be reproduced given
    # the compiled version -- i.e. so that `capnp compile -ocapnp` can do its job.
  }
}

struct FieldDoc {
  # separate container to carry field docstrings

  codeOrder @0 :UInt16;
  docComment @1 :Text;
}

struct Enumerant {
  # Schema for member of an enum.

  name @0 :Text;

  codeOrder @1 :UInt16;
  # Specifies order in which the enumerants were declared in the code.
  # Like Struct.Field.codeOrder.

  annotations @2 :List(Annotation);
}

struct Superclass {
  id @0 :Id;
  brand @1 :Brand;
}

struct Method {
  # Schema for method of an interface.

  name @0 :Text;

  codeOrder @1 :UInt16;
  # Specifies order in which the methods were declared in the code.
  # Like Struct.Field.codeOrder.

  implicitParameters @7 :List(Node.Parameter);
  # The parameters listed in [] (typically, type / generic parameters), whose bindings are intended
  # to be inferred rather than specified explicitly, although not all languages support this.

  paramStructType @2 :Id;
  # ID of the parameter struct type.  If a named parameter list was specified in the method
  # declaration (rather than a single struct parameter type) then a corresponding struct type is
  # auto-generated.  Such an auto-generated type will not be listed in the interface's
  # `nestedNodes` and its `scopeId` will be zero -- it is completely detached from the namespace.
  # (Awkwardly, it does of course inherit generic parameters from the method's scope, which makes
  # this a situation where you can't just climb the scope chain to find where a particular
  # generic parameter was introduced. Making the `scopeId` zero was a mistake.)

  paramBrand @5 :Brand;
  # Brand of param struct type.

  resultStructType @3 :Id;
  # ID of the return struct type; similar to `paramStructType`.

  resultBrand @6 :Brand;
  # Brand of result struct type.

  annotations @4 :List(Annotation);
}

struct Type {
  # Represents a type expression.

  union {
    # The ordinals intentionally match those of Value.

    void @0 :Void;
    bool @1 :Void;
    int8 @2 :Void;
    int16 @3 :Void;
    int32 @4 :Void;
    int64 @5 :Void;
    uint8 @6 :Void;
    uint16 @7 :Void;
    uint32 @8 :Void;
    uint64 @9 :Void;
    float32 @10 :Void;
    float64 @11 :Void;
    text @12 :Void;
    data @13 :Void;

    list :group {
      elementType @14 :Type;
    }

    enum :group {
      typeId @15 :Id;
      brand @21 :Brand;
    }
    struct :group {
      typeId @16 :Id;
      brand @22 :Brand;
    }
    interface :group {
      typeId @17 :Id;
      brand @23 :Brand;
    }

    anyPointer :union {
      unconstrained :union {
        # A regular AnyPointer.
        #
        # The name "unconstrained" means as opposed to constraining it to match a type parameter.
        # In retrospect this name is probably a poor choice given that it may still be constrained
        # to be a struct, list, or capability.

        anyKind @18 :Void;       # truly AnyPointer
        struct @25 :Void;        # AnyStruct
        list @26 :Void;          # AnyList
        capability @27 :Void;    # Capability
      }

      parameter :group {
        # This is actually a reference to a type parameter defined within this scope.

        scopeId @19 :Id;
        # ID of the generic type whose parameter we're referencing. This should be a parent of the
        # current scope.

        parameterIndex @20 :UInt16;
        # Index of the parameter within the generic type's parameter list.
      }

      implicitMethodParameter :group {
        # This is actually a reference to an implicit (generic) parameter of a method. The only
        # legal context for this type to appear is inside Method.paramBrand or Method.resultBrand.

        parameterIndex @24 :UInt16;
      }
    }
  }
}

struct Brand {
  # Specifies bindings for parameters of generics. Since these bindings turn a generic into a
  # non-generic, we call it the "brand".

  scopes @0 :List(Scope);
  # For each of the target type and each of its parent scopes, a parameterization may be included
  # in this list. If no parameterization is included for a particular relevant scope, then either
  # that scope has no parameters or all parameters should be considered to be `AnyPointer`.

  struct Scope {
    scopeId @0 :Id;
    # ID of the scope to which these params apply.

    union {
      bind @1 :List(Binding);
      # List of parameter bindings.

      inherit @2 :Void;
      # The place where this Brand appears is actually within this scope or a sub-scope,
      # and the bindings for this scope should be inherited from the reference point.
    }
  }

  struct Binding {
    union {
      unbound @0 :Void;
      type @1 :Type;

      # TODO(someday): Allow non-type parameters? Unsure if useful.
    }
  }
}

struct Value {
  # Represents a value, e.g. a field default value, constant value, or annotation value.

  union {
    # The ordinals intentionally match those of Type.

    void @0 :Void;
    bool @1 :Bool;
    int8 @2 :Int8;
    int16 @3 :Int16;
    int32 @4 :Int32;
    int64 @5 :Int64;
    uint8 @6 :UInt8;
    uint16 @7 :UInt16;
    uint32 @8 :UInt32;
    uint64 @9 :UInt64;
    float32 @10 :Float32;
    float64 @11 :Float64;
    text @12 :Text;
    data @13 :Data;

    list @14 :AnyPointer;

    enum @15 :UInt16;
    struct @16 :AnyPointer;

    interface @17 :Void;
    # The only interface value that can be represented statically is "null", whose methods always
    # throw exceptions.

    anyPointer @18 :AnyPointer;
  }
}

struct Annotation {
  # Describes an annotation applied to a declaration.  Note AnnotationNode describes the
  # annotation's declaration, while this describes a use of the annotation.

  id @0 :Id;
  # ID of the annotation node.

  brand @2 :Brand;
  # Brand of the annotation.
  #
  # Note that the annotation itself is not allowed to be parameterized, but its scope might be.

  value @1 :Value;
}

enum ElementSize {
  # Possible element sizes for encoded lists.  These correspond exactly to the possible values of
  # the 3-bit element size component of a list pointer.

  empty @0;    # aka "void", but that's a keyword.
  bit @1;
  byte @2;
  twoBytes @3;
  fourBytes @4;
  eightBytes @5;
  pointer @6;
  inlineComposite @7;
}

struct CapnpVersion {
  major @0 :UInt16;
  minor @1 :UInt8;
  micro @2 :UInt8;
}

struct CodeGeneratorRequest {
  capnpVersion @2 :CapnpVersion;
  # Version of the `capnp` executable. Generally, code generators should ignore this, but the code
  # generators that ship with `capnp` itself will print a warning if this mismatches since that
  # probably indicates something is misconfigured.
  #
  # The first version of 'capnp' to set this was 0.6.0. So, if it's missing, the compiler version
  # is older than that.

  nodes @0 :List(Node);
  # All nodes parsed by the compiler, including for the files on the command line and their
  # imports.

  nodeDocs @3 :List(NodeDoc);
  # documentation comments for nodes, where present

  requestedFiles @1 :List(RequestedFile);
  # Files which were listed on the command line.

  struct RequestedFile {
    id @0 :Id;
    # ID of the file.

    filename @1 :Text;
    # Name of the file as it appeared on the command-line (minus the src-prefix).  You may use
    # this to decide where to write the output.

    imports @2 :List(Import);
    # List of all imported paths seen in this file.

    struct Import {
      id @0 :Id;
      # ID of the imported file.

      name @1 :Text;
      # Name which *this* file used to refer to the foreign file.  This may be a relative name.
      # This information is provided because it might be useful for code generation, e.g. to
      # generate #include directives in C++.  We don't put this in Node.file because this
      # information is only meaningful at compile time anyway.
      #
      # (On Zooko's triangle, this is the import's petname according to the importing file.)
    }
  }
}

# Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
# Licensed under the MIT License:
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

using Cxx = import "/capnp/c++.capnp";

@0xa93fc509624c72d9;
$Cxx.namespace("capnp::schema");

using Id = UInt64;
# The globally-unique ID of a file, type, or annotation.

struct Node {
  id @0 :Id;

  displayName @1 :Text;
  # Name to present to humans to identify this Node.  You should not attempt to parse this.  Its
  # format could change.  It is not guaranteed to be unique.
  #
  # (On Zooko's triangle, this is the node's nickname.)

  displayNamePrefixLength @2 :UInt32;
  # If you want a shorter version of `displayName` (just naming this node, without its surrounding
  # scope), chop off this many characters from the beginning of `displayName`.

  scopeId @3 :Id;
  # ID of the lexical parent node.  Typically, the scope node will have a NestedNode pointing back
  # at this node, but robust code should avoid relying on this (and, in fact, group nodes are not
  # listed in the outer struct's nestedNodes, since they are listed in the fields).  `scopeId` is
  # zero if the node has no parent, which is normally only the case with files, but should be
  # allowed for any kind of node (in order to make runtime type generation easier).

  parameters @32 :List(Parameter);
  # If this node is parameterized (generic), the list of parameters. Empty for non-generic types.

  isGeneric @33 :Bool;
  # True if this node is generic, meaning that it or one of its parent scopes has a non-empty
  # `parameters`.

  struct Parameter {
    # Information about one of the node's parameters.

    name @0 :Text;
  }

  nestedNodes @4 :List(NestedNode);
  # List of nodes nested within this node, along with the names under which they were declared.

  struct NestedNode {
    name @0 :Text;
    # Unqualified symbol name.  Unlike Node.displayName, this *can* be used programmatically.
    #
    # (On Zooko's triangle, this is the node's petname according to its parent scope.)

    id @1 :Id;
    # ID of the nested node.  Typically, the target node's scopeId points back to this node, but
    # robust code should avoid relying on this.
  }

  annotations @5 :List(Annotation);
  # Annotations applied to this node.

  union {
    # Info specific to each kind of node.

    file @6 :Void;

    struct :group {
      dataWordCount @7 :UInt16;
      # Size of the data section, in words.

      pointerCount @8 :UInt16;
      # Size of the pointer section, in pointers (which are one word each).

      preferredListEncoding @9 :ElementSize;
      # The preferred element size to use when encoding a list of this struct.  If this is anything
      # other than `inlineComposite` then the struct is one word or less in size and is a candidate
      # for list packing optimization.

      isGroup @10 :Bool;
      # If true, then this "struct" node is actually not an independent node, but merely represents
      # some named union or group within a particular parent struct.  This node's scopeId refers
      # to the parent struct, which may itself be a union/group in yet another struct.
      #
      # All group nodes share the same dataWordCount and pointerCount as the top-level
      # struct, and their fields live in the same ordinal and offset spaces as all other fields in
      # the struct.
      #
      # Note that a named union is considered a special kind of group -- in fact, a named union
      # is exactly equivalent to a group that contains nothing but an unnamed union.

      discriminantCount @11 :UInt16;
      # Number of fields in this struct which are members of an anonymous union, and thus may
      # overlap.  If this is non-zero, then a 16-bit discriminant is present indicating which
      # of the overlapping fields is active.  This can never be 1 -- if it is non-zero, it must be
      # two or more.
      #
      # Note that the fields of an unnamed union are considered fields of the scope containing the
      # union -- an unnamed union is not its own group.  So, a top-level struct may contain a
      # non-zero discriminant count.  Named unions, on the other hand, are equivalent to groups
      # containing unnamed unions.  So, a named union has its own independent schema node, with
      # `isGroup` = true.

      discriminantOffset @12 :UInt32;
      # If `discriminantCount` is non-zero, this is the offset of the union discriminant, in
      # multiples of 16 bits.

      fields @13 :List(Field);
      # Fields defined within this scope (either the struct's top-level fields, or the fields of
      # a particular group; see `isGroup`).
      #
      # The fields are sorted by ordinal number, but note that because groups share the same
      # ordinal space, the field's index in this list is not necessarily exactly its ordinal.
      # On the other hand, the field's position in this list does remain the same even as the
      # protocol evolves, since it is not possible to insert or remove an earlier ordinal.
      # Therefore, for most use cases, if you want to identify a field by number, it may make the
      # most sense to use the field's index in this list rather than its ordinal.
    }

    enum :group {
      enumerants@14 :List(Enumerant);
      # Enumerants ordered by numeric value (ordinal).
    }

    interface :group {
      methods @15 :List(Method);
      # Methods ordered by ordinal.

      superclasses @31 :List(Superclass);
      # Superclasses of this interface.
    }

    const :group {
      type @16 :Type;
      value @17 :Value;
    }

    annotation :group {
      type @18 :Type;

      targetsFile @19 :Bool;
      targetsConst @20 :Bool;
      targetsEnum @21 :Bool;
      targetsEnumerant @22 :Bool;
      targetsStruct @23 :Bool;
      targetsField @24 :Bool;
      targetsUnion @25 :Bool;
      targetsGroup @26 :Bool;
      targetsInterface @27 :Bool;
      targetsMethod @28 :Bool;
      targetsParam @29 :Bool;
      targetsAnnotation @30 :Bool;
    }
  }
}

struct Field {
  # Schema for a field of a struct.

  name @0 :Text;

  codeOrder @1 :UInt16;
  # Indicates where this member appeared in the code, relative to other members.
  # Code ordering may have semantic relevance -- programmers tend to place related fields
  # together.  So, using code ordering makes sense in human-readable formats where ordering is
  # otherwise irrelevant, like JSON.  The values of codeOrder are tightly-packed, so the maximum
  # value is count(members) - 1.  Fields that are members of a union are only ordered relative to
  # the other members of that union, so the maximum value there is count(union.members).

  annotations @2 :List(Annotation);

  const noDiscriminant :UInt16 = 0xffff;

  discriminantValue @3 :UInt16 = Field.noDiscriminant;
  # If the field is in a union, this is the value which the union's discriminant should take when
  # the field is active.  If the field is not in a union, this is 0xffff.

  union {
    slot :group {
      # A regular, non-group, non-fixed-list field.

      offset @4 :UInt32;
      # Offset, in units of the field's size, from the beginning of the section in which the field
      # resides.  E.g. for a UInt32 field, multiply this by 4 to get the byte offset from the
      # beginning of the data section.

      type @5 :Type;
      defaultValue @6 :Value;

      hadExplicitDefault @10 :Bool;
      # Whether the default value was specified explicitly.  Non-explicit default values are always
      # zero or empty values.  Usually, whether the default value was explicit shouldn't matter.
      # The main use case for this flag is for structs representing method parameters:
      # explicitly-defaulted parameters may be allowed to be omitted when calling the method.
    }

    group :group {
      # A group.

      typeId @7 :Id;
      # The ID of the group's node.
    }
  }

  ordinal :union {
    implicit @8 :Void;
    explicit @9 :UInt16;
    # The original ordinal number given to the field.  You probably should NOT use this; if you need
    # a numeric identifier for a field, use its position within the field array for its scope.
    # The ordinal is given here mainly just so that the original schema text can be reproduced given
    # the compiled version -- i.e. so that `capnp compile -ocapnp` can do its job.
  }
}

struct Enumerant {
  # Schema for member of an enum.

  name @0 :Text;

  codeOrder @1 :UInt16;
  # Specifies order in which the enumerants were declared in the code.
  # Like Struct.Field.codeOrder.

  annotations @2 :List(Annotation);
}

struct Superclass {
  id @0 :Id;
  brand @1 :Brand;
}

struct Method {
  # Schema for method of an interface.

  name @0 :Text;

  codeOrder @1 :UInt16;
  # Specifies order in which the methods were declared in the code.
  # Like Struct.Field.codeOrder.

  implicitParameters @7 :List(Node.Parameter);
  # The parameters listed in [] (typically, type / generic parameters), whose bindings are intended
  # to be inferred rather than specified explicitly, although not all languages support this.

  paramStructType @2 :Id;
  # ID of the parameter struct type.  If a named parameter list was specified in the method
  # declaration (rather than a single struct parameter type) then a corresponding struct type is
  # auto-generated.  Such an auto-generated type will not be listed in the interface's
  # `nestedNodes` and its `scopeId` will be zero -- it is completely detached from the namespace.
  # (Awkwardly, it does of course inherit generic parameters from the method's scope, which makes
  # this a situation where you can't just climb the scope chain to find where a particular
  # generic parameter was introduced. Making the `scopeId` zero was a mistake.)

  paramBrand @5 :Brand;
  # Brand of param struct type.

  resultStructType @3 :Id;
  # ID of the return struct type; similar to `paramStructType`.

  resultBrand @6 :Brand;
  # Brand of result struct type.

  annotations @4 :List(Annotation);
}

struct Type {
  # Represents a type expression.

  union {
    # The ordinals intentionally match those of Value.

    void @0 :Void;
    bool @1 :Void;
    int8 @2 :Void;
    int16 @3 :Void;
    int32 @4 :Void;
    int64 @5 :Void;
    uint8 @6 :Void;
    uint16 @7 :Void;
    uint32 @8 :Void;
    uint64 @9 :Void;
    float32 @10 :Void;
    float64 @11 :Void;
    text @12 :Void;
    data @13 :Void;

    list :group {
      elementType @14 :Type;
    }

    enum :group {
      typeId @15 :Id;
      brand @21 :Brand;
    }
    struct :group {
      typeId @16 :Id;
      brand @22 :Brand;
    }
    interface :group {
      typeId @17 :Id;
      brand @23 :Brand;
    }

    anyPointer :union {
      unconstrained :union {
        # A regular AnyPointer.
        #
        # The name "unconstrained" means as opposed to constraining it to match a type parameter.
        # In retrospect this name is probably a poor choice given that it may still be constrained
        # to be a struct, list, or capability.

        anyKind @18 :Void;       # truly AnyPointer
        struct @25 :Void;        # AnyStruct
        list @26 :Void;          # AnyList
        capability @27 :Void;    # Capability
      }

      parameter :group {
        # This is actually a reference to a type parameter defined within this scope.

        scopeId @19 :Id;
        # ID of the generic type whose parameter we're referencing. This should be a parent of the
        # current scope.

        parameterIndex @20 :UInt16;
        # Index of the parameter within the generic type's parameter list.
      }

      implicitMethodParameter :group {
        # This is actually a reference to an implicit (generic) parameter of a method. The only
        # legal context for this type to appear is inside Method.paramBrand or Method.resultBrand.

        parameterIndex @24 :UInt16;
      }
    }
  }
}

struct Brand {
  # Specifies bindings for parameters of generics. Since these bindings turn a generic into a
  # non-generic, we call it the "brand".

  scopes @0 :List(Scope);
  # For each of the target type and each of its parent scopes, a parameterization may be included
  # in this list. If no parameterization is included for a particular relevant scope, then either
  # that scope has no parameters or all parameters should be considered to be `AnyPointer`.

  struct Scope {
    scopeId @0 :Id;
    # ID of the scope to which these params apply.

    union {
      bind @1 :List(Binding);
      # List of parameter bindings.

      inherit @2 :Void;
      # The place where this Brand appears is actually within this scope or a sub-scope,
      # and the bindings for this scope should be inherited from the reference point.
    }
  }

  struct Binding {
    union {
      unbound @0 :Void;
      type @1 :Type;

      # TODO(someday): Allow non-type parameters? Unsure if useful.
    }
  }
}

struct Value {
  # Represents a value, e.g. a field default value, constant value, or annotation value.

  union {
    # The ordinals intentionally match those of Type.

    void @0 :Void;
    bool @1 :Bool;
    int8 @2 :Int8;
    int16 @3 :Int16;
    int32 @4 :Int32;
    int64 @5 :Int64;
    uint8 @6 :UInt8;
    uint16 @7 :UInt16;
    uint32 @8 :UInt32;
    uint64 @9 :UInt64;
    float32 @10 :Float32;
    float64 @11 :Float64;
    text @12 :Text;
    data @13 :Data;

    list @14 :AnyPointer;

    enum @15 :UInt16;
    struct @16 :AnyPointer;

    interface @17 :Void;
    # The only interface value that can be represented statically is "null", whose methods always
    # throw exceptions.

    anyPointer @18 :AnyPointer;
  }
}

struct Annotation {
  # Describes an annotation applied to a declaration.  Note AnnotationNode describes the
  # annotation's declaration, while this describes a use of the annotation.

  id @0 :Id;
  # ID of the annotation node.

  brand @2 :Brand;
  # Brand of the annotation.
  #
  # Note that the annotation itself is not allowed to be parameterized, but its scope might be.

  value @1 :Value;
}

enum ElementSize {
  # Possible element sizes for encoded lists.  These correspond exactly to the possible values of
  # the 3-bit element size component of a list pointer.

  empty @0;    # aka "void", but that's a keyword.
  bit @1;
  byte @2;
  twoBytes @3;
  fourBytes @4;
  eightBytes @5;
  pointer @6;
  inlineComposite @7;
}

struct CapnpVersion {
  major @0 :UInt16;
  minor @1 :UInt8;
  micro @2 :UInt8;
}

struct CodeGeneratorRequest {
  capnpVersion @2 :CapnpVersion;
  # Version of the `capnp` executable. Generally, code generators should ignore this, but the code
  # generators that ship with `capnp` itself will print a warning if this mismatches since that
  # probably indicates something is misconfigured.
  #
  # The first version of 'capnp' to set this was 0.6.0. So, if it's missing, the compiler version
  # is older than that.

  nodes @0 :List(Node);
  # All nodes parsed by the compiler, including for the files on the command line and their
  # imports.

  requestedFiles @1 :List(RequestedFile);
  # Files which were listed on the command line.

  struct RequestedFile {
    id @0 :Id;
    # ID of the file.

    filename @1 :Text;
    # Name of the file as it appeared on the command-line (minus the src-prefix).  You may use
    # this to decide where to write the output.

    imports @2 :List(Import);
    # List of all imported paths seen in this file.

    struct Import {
      id @0 :Id;
      # ID of the imported file.

      name @1 :Text;
      # Name which *this* file used to refer to the foreign file.  This may be a relative name.
      # This information is provided because it might be useful for code generation, e.g. to
      # generate #include directives in C++.  We don't put this in Node.file because this
      # information is only meaningful at compile time anyway.
      #
      # (On Zooko's triangle, this is the import's petname according to the importing file.)
    }
  }
}


Updated capnp schema to conform with new union rules

@0x934efea7f017fff0;

struct Person {
  id @0 :UInt32;
  name @1 :Text;
  email @2 :Text;
  phones @3 :List(PhoneNumber);

  struct PhoneNumber {
    number @0 :Text;
    type @1 :Type;

    enum Type {
      mobile @0;
      home @1;
      work @2;
    }
  }

  employment :union {
    unemployed @4 :Void;
    employer @5 :Text;
    school @6 :Text;
    selfEmployed @7 :Void;
    # We assume that a person is only one of these.
  }
}

struct AddressBook {
  people @0 :List(Person);
}

@0x934efea7f017fff0;

struct Person {
  id @0 :UInt32;
  name @1 :Text;
  email @2 :Text;
  phones @3 :List(PhoneNumber);

  struct PhoneNumber {
    number @0 :Text;
    type @1 :Type;

    enum Type {
      mobile @0;
      home @1;
      work @2;
    }
  }

  employment @4 union {
    unemployed @5 :Void;
    employer @6 :Text;
    school @7 :Text;
    selfEmployed @8 :Void;
    # We assume that a person is only one of these.
  }
}

struct AddressBook {
  people @0 :List(Person);
}


Added variable field in RealExpr and SetExpr (to explicitly distinguish between symbolic variables and references)

# The MIT License (MIT)
#
# Copyright (c) 2015 Andrey Bernstein and Niek J. Bouman
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
@0xdb1b4800e80dbd2d;
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("msg");
#
# COMMELEC message format v1.0
#
# Specified in Cap'n Proto's schema language (Requires Cap'n Proto v0.5
#   [ http://kentonv.github.io/capnproto/language.html ]
#
# Copyright (c) 2015 by Andrey Bernstein & Niek J. Bouman
#
# EPFL - Swiss Federal Institute of Technology Lausanne

#=====================================================
# Top-Level "Message" Type, Request and Advertisement
#=====================================================

struct Message {
    agentId                   @0 :UInt32;
    union {
      request                 @1 :Request;
      advertisement           @2 :Advertisement;
    }
}

struct Request {
    setpoint                  @0 :List(Float64);
}

struct Advertisement {
    pQProfile                 @0 :SetExpr;
    beliefFunction            @1 :SetExpr;
    costFunction              @2 :RealExpr;
    implementedSetpoint       @3 :List(Float64);
}

#==============================================
# Definition of RealExpr and its child structs
#==============================================

struct RealExpr {
    name                      @0 :Text;
    union {
      real                    @1 :Float64;
      polynomial              @2 :Polynomial;
      unaryOperation          @3 :UnaryOperation;
      binaryOperation         @4 :BinaryOperation;
      listOperation           @5 :ListOperation;
      caseDistinction         @6 :CaseDistinction(RealExpr);
      reference               @7 :Text;
      variable                @8 :Text;
     }
}

struct UnaryOperation {
    arg                       @0 :RealExpr;
    operation :union {
      negate                  @1  :Void;
      abs                     @2  :Void;
      sign                    @3  :Void;
      multInv                 @4  :Void;
      square                  @5  :Void;
      sqrt                    @6  :Void;
      sin                     @7  :Void;
      cos                     @8  :Void;
      tan                     @9  :Void;
      exp                     @10 :Void;
      ln                      @11 :Void;
      log10                   @12 :Void;
      round                   @13 :Void;
      floor                   @14 :Void;
      ceil                    @15 :Void;
    }
}

struct BinaryOperation {
    argA                      @0 :RealExpr;
    argB                      @1 :RealExpr;
    operation :union {
      sum                     @2 :Void;
      prod                    @3 :Void;
      pow                     @4 :Void;
      min                     @5 :Void;
      max                     @6 :Void;
      lessEqThan              @7 :Void; # expression yields a boolean
      greaterThan             @8 :Void; # expression yields a boolean
    }
}

struct ListOperation {
    args                      @0 :List(RealExpr);
    operation :union {
      sum                     @1 :Void;
      prod                    @2 :Void;
    }
}

struct Polynomial {
    variables                 @0 :List(Text);
    maxVarDegree              @1 :UInt8;
    coefficients              @2 :List(SparseCoeff);
}

struct SparseCoeff {
    offset                    @0 :UInt32;
    value                     @1 :Float64;
}

struct CaseDistinction(CaseType) {
    variables                 @0 :List(Text);
    cases                     @1 :List(ExprCase(CaseType));
}

struct ExprCase(CaseType) {
    # Representation of a single case for use in CaseDistinction
    # (order of evaluation follows List ordering)
    set                       @0 :SetExpr;
    expression                @1 :CaseType;
}

#=============================================
# Definition of SetExpr and its child structs
#=============================================

struct SetExpr {
    name                      @0 :Text;
    union {
      singleton               @1  :List(RealExpr); # dimension of the point equals the length of the list
      ball                    @2  :Ball;
      rectangle               @3  :List(BoundaryPair);
      convexPolytope          @4  :ConvexPolytope;
      intersection            @5  :List(SetExpr);
      caseDistinction         @6  :CaseDistinction(SetExpr);
      reference               @7  :Text;
      variable                @8  :Text;
    }
}

struct Ball {
    center                    @0 :List(RealExpr);
    radius                    @1 :RealExpr;
}

struct BoundaryPair {
    boundA                    @0 :RealExpr; # the "interpreter" is responsible for sorting
    boundB                    @1 :RealExpr; # the bounds, i.e., which bound is min and max
}

struct ConvexPolytope {
    # A convex polytope formed by linear constraints
    # In case of a polygon, i.e., a two-dimensional polytope, the
    # length of the inner list of field 'a' will be equal to two.
    a                         @0 :List(List(RealExpr));
    b                         @1 :List(RealExpr);
}

# The MIT License (MIT)
#
# Copyright (c) 2015 Andrey Bernstein and Niek J. Bouman
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
@0xdb1b4800e80dbd2d;
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("msg");
#
# COMMELEC message format v1.0
#
# Specified in Cap'n Proto's schema language (Requires Cap'n Proto v0.5
#   [ http://kentonv.github.io/capnproto/language.html ]
#
# Copyright (c) 2015 by Andrey Bernstein & Niek J. Bouman
#
# EPFL - Swiss Federal Institute of Technology Lausanne

#=====================================================
# Top-Level "Message" Type, Request and Advertisement
#=====================================================

struct Message {
    agentId                   @0 :UInt32;
    union {
      request                 @1 :Request;
      advertisement           @2 :Advertisement;
    }
}

struct Request {
    setpoint                  @0 :List(Float64);
}

struct Advertisement {
    pQProfile                 @0 :SetExpr;
    beliefFunction            @1 :SetExpr;
    costFunction              @2 :RealExpr;
    implementedSetpoint       @3 :List(Float64);
}

#==============================================
# Definition of RealExpr and its child structs
#==============================================

struct RealExpr {
    name                      @0 :Text;
    union {
      real                    @1 :Float64;
      polynomial              @2 :Polynomial;
      unaryOperation          @3 :UnaryOperation;
      binaryOperation         @4 :BinaryOperation;
      listOperation           @5 :ListOperation;
      caseDistinction         @6 :CaseDistinction(RealExpr);
      reference               @7 :Text;
     }
}

struct UnaryOperation {
    arg                       @0 :RealExpr;
    operation :union {
      negate                  @1  :Void;
      abs                     @2  :Void;
      sign                    @3  :Void;
      multInv                 @4  :Void;
      square                  @5  :Void;
      sqrt                    @6  :Void;
      sin                     @7  :Void;
      cos                     @8  :Void;
      tan                     @9  :Void;
      exp                     @10 :Void;
      ln                      @11 :Void;
      log10                   @12 :Void;
      round                   @13 :Void;
      floor                   @14 :Void;
      ceil                    @15 :Void;
    }
}

struct BinaryOperation {
    argA                      @0 :RealExpr;
    argB                      @1 :RealExpr;
    operation :union {
      sum                     @2 :Void;
      prod                    @3 :Void;
      pow                     @4 :Void;
      min                     @5 :Void;
      max                     @6 :Void;
      lessEqThan              @7 :Void; # expression yields a boolean
      greaterThan             @8 :Void; # expression yields a boolean
    }
}

struct ListOperation {
    args                      @0 :List(RealExpr);
    operation :union {
      sum                     @1 :Void;
      prod                    @2 :Void;
    }
}

struct Polynomial {
    variables                 @0 :List(Text);
    maxVarDegree              @1 :UInt8;
    coefficients              @2 :List(SparseCoeff);
}

struct SparseCoeff {
    offset                    @0 :UInt32;
    value                     @1 :Float64;
}

struct CaseDistinction(CaseType) {
    variables                 @0 :List(Text);
    cases                     @1 :List(ExprCase(CaseType));
}

struct ExprCase(CaseType) {
    # Representation of a single case for use in CaseDistinction
    # (order of evaluation follows List ordering)
    set                       @0 :SetExpr;
    expression                @1 :CaseType;
}

#=============================================
# Definition of SetExpr and its child structs
#=============================================

struct SetExpr {
    name                      @0 :Text;
    union {
      singleton               @1  :List(RealExpr); # dimension of the point equals the length of the list
      ball                    @2  :Ball;
      rectangle               @3  :List(BoundaryPair);
      convexPolytope          @4  :ConvexPolytope;
      intersection            @5  :List(SetExpr);
      caseDistinction         @6  :CaseDistinction(SetExpr);
      reference               @7  :Text;
    }
}

struct Ball {
    center                    @0 :List(RealExpr);
    radius                    @1 :RealExpr;
}

struct BoundaryPair {
    boundA                    @0 :RealExpr; # the "interpreter" is responsible for sorting
    boundB                    @1 :RealExpr; # the bounds, i.e., which bound is min and max
}

struct ConvexPolytope {
    # A convex polytope formed by linear constraints
    # In case of a polygon, i.e., a two-dimensional polytope, the
    # length of the inner list of field 'a' will be equal to two.
    a                         @0 :List(List(RealExpr));
    b                         @1 :List(RealExpr);
}


Added some more buffer data...

Added some more buffer data...

# This is the basic interface for manipulating the configuration of remote devices
interface Parameter {
	get @0 () -> (value :ParamStruct);
	struct ParamStruct {
		name @0 :Text;				# name of the parameter
		uid @1 :UInt64;				# UID of the parameter
		channel @2 :UInt8;			# channel to which the parameter applies (255 for all or none)
		value :union {				# value of the parameter
			switch @3 :Bool;
			signed8 @4 :Int8;
			signed16 @5 :Int16;
			signed32 @4 :Int32;
			signed64 @5 :Int64;
			unsigned8 @6 :UInt8;
			unsigned16 @7 :UInt16;
			unsigned32 @8 :UInt32;
			unsigned64 @9 :UInt64;
			floatNum @10 :Float32;
			doubleNum @11 :Float64;
			stringVal @12 :Text;
		}
	}

	set @1 (value :ParamStruct) -> (err :ParamErr);
	enum ParamErr {
		none @0;
		invalidParamName @1;
		invalidParamUID @2;
		invalidParamValue @3;
		invalidParamChannel @4;
		accessDenied @5;
		paramSetFail @6;
		invalidParamType @7;
	}

	list @2 () -> (List(ParamStruct)); # returns a list of valid parameters, with their current values
}

# This allows the device to interrupt the host (for example, data ready)
interface Interrupt {
	raise @0 (int :IntStruct) -> (ack :Bool);
	struct IntStruct {
		name @0 :Text;		# name of the interrupt
		UID @1 :UInt64;		# interrupt UID
		channel @2 :UInt8;	# channel that generated the interrupt (255 if no channel)
	}
}

# write and read buffers
interface Buffer {
	read @0 (buf :BufID;) -> (buf :BufStruct);
	struct BufID {
		channel @0 :UInt8;		# The device channel that the buffer either comes from or is intended for.
		bufNum @7 :Uint8;		# The buffer number (allows multiple buffers for a single channel)
		rate @1 :Float32;		# The sample rate of the buffer.
		startTime @2 :UInt64;	# The start time of the buffer, in microseconds since the epoch.
		size @3 :UInt32;		# Allocated size of the buffer, in samples
		contentSize @6 :UInt32;	# The number of samples currently in the buffer
		resolution @4 :UInt8;	# Size of a sample, in bits
		direction @5 :Bool;		# True for input buffer, false for output
		active @8 :Bool;		# Is the buffer currently being read from or written to?
	}
	struct BufStruct {
		ID @0 :BufID;			# The identity of the buffer
		contents @1 :Data;		# The data to be encoded
	}

	write @1 (buf :BufStruct) -> (err: BufErr);
	enum BufErr {
		none @0;
		bufDoesNotExist @1;
		bufEmpty @2;
		bufOverflow @3;
		bufWriteFail @4;
		invalidBufType @5;
	}

	list @2 () -> (List(BufID));
	listByChannel @3 (channel :UInt8;) -> (List(BufID));
}

# This is the basic interface for manipulating the configuration of remote devices
interface Parameter {
	get @0 () -> (value :ParamStruct);
	struct ParamStruct {
		name @0 :Text;				# name of the parameter
		uid @1 :UInt64;				# UID of the parameter
		channel @2 :UInt8;			# channel to which the parameter applies (255 for all or none)
		value :union {				# value of the parameter
			switch @3 :Bool;
			signed8 @4 :Int8;
			signed16 @5 :Int16;
			signed32 @4 :Int32;
			signed64 @5 :Int64;
			unsigned8 @6 :UInt8;
			unsigned16 @7 :UInt16;
			unsigned32 @8 :UInt32;
			unsigned64 @9 :UInt64;
			floatNum @10 :Float32;
			doubleNum @11 :Float64;
			stringVal @12 :Text;
		}
	}

	set @1 (value :ParamStruct) -> (err :ParamErr);
	enum ParamErr {
		none @0;
		invalidParamName @1;
		invalidParamUID @2;
		invalidParamValue @3;
		invalidParamChannel @4;
		accessDenied @5;
		paramSetFail @6;
		invalidParamType @7;
	}

	list @2 () -> (List(ParamStruct)); # returns a list of valid parameters, with their current values
}

# This allows the device to interrupt the host (for example, data ready)
interface Interrupt {
	raise @0 (int :IntStruct) -> (ack :Bool);
	struct IntStruct {
		name @0 :Text;		# name of the interrupt
		UID @1 :UInt64;		# interrupt UID
		channel @2 :UInt8;	# channel that generated the interrupt (255 if no channel)
	}
}

# write and read buffers
interface Buffer {
	read @0 (channel :Uint8;) -> (buf :BufStruct);
	struct BufID {
		channel @0 :UInt8;		# The device channel that the buffer either comes from or is intended for.
		rate @1 :Float32;		# The sample rate of the buffer.
		startTime @2 :UInt64;	# The start time of the buffer, in microseconds since the epoch.
		size @3 :UInt32;		# Size of the buffer, in samples
		resolution @4 :UInt8;	# Size of a sample, in bits
		direction @5 :Bool;		# True for input buffer, false for output
	}
	struct BufStruct {
		ID @0 :BufID;			# The identity of the buffer
		contents @1 :Data;		# The data to be encoded
	}

	write @1 (buf :BufStruct) -> (err: BufErr);
	enum BufErr {
		none @0;
		bufDoesNotExist @1;
		bufEmpty @2;
		bufOverflow @3;
		bufWriteFail @4;
		invalidBufType @5;
	}

	list @2 () -> (List(BufID));
}


shortDescription

shortDescription

@0xe6391d0709201983;

using Spk = import "/sandstorm/package.capnp";

const pkgdef :Spk.PackageDefinition = (
  id = "wfg1r0qra2ewyvns05r0rddqttt57qxurz3nz5z95rjnm63et7e0",

  manifest = (
    appTitle = (defaultText = "Groove Basin"),
    appVersion = 8,  # Increment this for every release.
    appMarketingVersion = (defaultText = "2016.02.06 (1.5.1+)"),

    metadata = (
      icons = (
        appGrid = (png = (dpi1x = embed "app-graphics/groovebasin-128.png",
                          dpi2x = embed "app-graphics/groovebasin-256.png")),
        grain = (png = (dpi1x = embed "app-graphics/groovebasin-24.png",
                        dpi2x = embed "app-graphics/groovebasin-48.png")),
        market = (png = (dpi1x = embed "app-graphics/groovebasin-150.png")),
      ),
      website = "http://groovebasin.com",
      codeUrl = "https://github.com/dwrensha/groovebasin",
      license = (openSource = mit),
      categories = [media,],
      author = (
        upstreamAuthor = "Andrew Kelley",
        contactEmail = "david@sandstorm.io",
        pgpSignature = embed "pgp-signature",
      ),
      pgpKeyring = embed "pgp-keyring",
      shortDescription = (defaultText = "Music player"),
      description = (defaultText = embed "description.md"),
      screenshots = [(width = 448, height = 311, png = embed "screenshot.png")],
      changeLog = (defaultText = embed "changeLog.md"),
    ),

    actions = [
      ( title = (defaultText = "New Music Library"),
        command = .myCommand,
        nounPhrase = (defaultText = "Music Library")
      )
    ],

    continueCommand = .myCommand
  ),

  sourceMap = (
    searchPath = [
      ( sourcePath = "." ),  # Search this directory first.
      ( sourcePath = "/opt/app"),
      ( sourcePath = "/",    # Then search the system root directory.
        hidePaths = [ "home", "proc", "sys",
                      "etc/passwd", "etc/nsswitch.conf"]
      )
    ]
  ),

  fileList = "sandstorm-files.list",

  alwaysInclude = [],

  bridgeConfig = (
    viewInfo = (
       permissions = [(name = "admin", title = (defaultText = "admin"),
                       description = (defaultText = "allows tag editing and track deletion")),
                      (name = "read", title = (defaultText = "read"),
                       description = (defaultText = "allows listening and downloading")),
                      (name = "add", title = (defaultText = "add"),
                       description = (defaultText = "allows track uploads")),
                      (name = "control", title = (defaultText = "control"),
                       description = (defaultText = "allows control of the audio stream")),
                      (name = "playlist", title = (defaultText = "playlist"),
                       description = (defaultText = "allows playlist editing"))],
       roles = [(title = (defaultText = "controller"),
                 permissions = .controllerPermissions,
                 verbPhrase = (defaultText = "can control the stream")),
                (title = (defaultText = "disc jockey"),
                 permissions = .djPermissions,
                 verbPhrase =
                    (defaultText = "can control the stream, upload tracks, and edit playlists"),
                 default = true),
                (title = (defaultText = "administrator"),
                 permissions = .adminPermissions,
                 verbPhrase = (defaultText = "can do anything")),
                (title = (defaultText = "listener"),
                 permissions = .listenerPermissions,
                 verbPhrase = (defaultText = "can only listen")),
                (title = (defaultText = "contributor"),
                 permissions = .contributorPermissions,
                 verbPhrase = (defaultText = "can upload tracks and edit playlists"))
                 ]
    )
  )
);

#                                                 admin | read |  add | control | playlist |
const controllerPermissions : List(Bool)       = [ false,  true, false,     true,    false];
const djPermissions : List(Bool)               = [ false,  true,  true,     true,    true];
const adminPermissions : List(Bool)            = [ true,   true,  true,      true,    true];
const listenerPermissions : List(Bool)         = [ false,  true, false,     false,    false];
const contributorPermissions : List(Bool)      = [ false,  true,  true,     false,    true];

const myCommand :Spk.Manifest.Command = (
  argv = ["/sandstorm-http-bridge", "10000", "--", "/bin/sh", "start.sh"],
  environ = [
    # Note that this defines the *entire* environment seen by your app.
    (key = "PATH", value = "/usr/local/bin:/usr/bin:/bin")
  ]
);

@0xe6391d0709201983;

using Spk = import "/sandstorm/package.capnp";

const pkgdef :Spk.PackageDefinition = (
  id = "wfg1r0qra2ewyvns05r0rddqttt57qxurz3nz5z95rjnm63et7e0",

  manifest = (
    appTitle = (defaultText = "Groove Basin"),
    appVersion = 8,  # Increment this for every release.
    appMarketingVersion = (defaultText = "2016.02.06 (1.5.1+)"),

    metadata = (
      icons = (
        appGrid = (png = (dpi1x = embed "app-graphics/groovebasin-128.png",
                          dpi2x = embed "app-graphics/groovebasin-256.png")),
        grain = (png = (dpi1x = embed "app-graphics/groovebasin-24.png",
                        dpi2x = embed "app-graphics/groovebasin-48.png")),
        market = (png = (dpi1x = embed "app-graphics/groovebasin-150.png")),
      ),
      website = "http://groovebasin.com",
      codeUrl = "https://github.com/dwrensha/groovebasin",
      license = (openSource = mit),
      categories = [media,],
      author = (
        upstreamAuthor = "Andrew Kelley",
        contactEmail = "david@sandstorm.io",
        pgpSignature = embed "pgp-signature",
      ),
      pgpKeyring = embed "pgp-keyring",
      description = (defaultText = embed "description.md"),
      screenshots = [(width = 448, height = 311, png = embed "screenshot.png")],
      changeLog = (defaultText = embed "changeLog.md"),
    ),

    actions = [
      ( title = (defaultText = "New Music Library"),
        command = .myCommand,
        nounPhrase = (defaultText = "Music Library")
      )
    ],

    continueCommand = .myCommand
  ),

  sourceMap = (
    searchPath = [
      ( sourcePath = "." ),  # Search this directory first.
      ( sourcePath = "/opt/app"),
      ( sourcePath = "/",    # Then search the system root directory.
        hidePaths = [ "home", "proc", "sys",
                      "etc/passwd", "etc/nsswitch.conf"]
      )
    ]
  ),

  fileList = "sandstorm-files.list",

  alwaysInclude = [],

  bridgeConfig = (
    viewInfo = (
       permissions = [(name = "admin", title = (defaultText = "admin"),
                       description = (defaultText = "allows tag editing and track deletion")),
                      (name = "read", title = (defaultText = "read"),
                       description = (defaultText = "allows listening and downloading")),
                      (name = "add", title = (defaultText = "add"),
                       description = (defaultText = "allows track uploads")),
                      (name = "control", title = (defaultText = "control"),
                       description = (defaultText = "allows control of the audio stream")),
                      (name = "playlist", title = (defaultText = "playlist"),
                       description = (defaultText = "allows playlist editing"))],
       roles = [(title = (defaultText = "controller"),
                 permissions = .controllerPermissions,
                 verbPhrase = (defaultText = "can control the stream")),
                (title = (defaultText = "disc jockey"),
                 permissions = .djPermissions,
                 verbPhrase =
                    (defaultText = "can control the stream, upload tracks, and edit playlists"),
                 default = true),
                (title = (defaultText = "administrator"),
                 permissions = .adminPermissions,
                 verbPhrase = (defaultText = "can do anything")),
                (title = (defaultText = "listener"),
                 permissions = .listenerPermissions,
                 verbPhrase = (defaultText = "can only listen")),
                (title = (defaultText = "contributor"),
                 permissions = .contributorPermissions,
                 verbPhrase = (defaultText = "can upload tracks and edit playlists"))
                 ]
    )
  )
);

#                                                 admin | read |  add | control | playlist |
const controllerPermissions : List(Bool)       = [ false,  true, false,     true,    false];
const djPermissions : List(Bool)               = [ false,  true,  true,     true,    true];
const adminPermissions : List(Bool)            = [ true,   true,  true,      true,    true];
const listenerPermissions : List(Bool)         = [ false,  true, false,     false,    false];
const contributorPermissions : List(Bool)      = [ false,  true,  true,     false,    true];

const myCommand :Spk.Manifest.Command = (
  argv = ["/sandstorm-http-bridge", "10000", "--", "/bin/sh", "start.sh"],
  environ = [
    # Note that this defines the *entire* environment seen by your app.
    (key = "PATH", value = "/usr/local/bin:/usr/bin:/bin")
  ]
);


Add frameid to pc type

Add frameid to pc type

# Copyright 2016 - 2018  Ternaris.
# SPDX-License-Identifier: AGPL-3.0-only

@0xa1475499038e2711;

using import "/marv_nodes/types.capnp".Comment;
using import "/marv_nodes/types.capnp".File;
using import "/marv_nodes/types.capnp".GeoJson;
using import "/marv_pycapnp/types.capnp".Timedelta;
using import "/marv_pycapnp/types.capnp".Timestamp;
using import "/marv_pycapnp/types.capnp".TimelineEvent;

using Filesize = UInt64;
using RowId = UInt64;

enum Align {
  left @0;
  center @1;
  right @2;
}

enum Formatter {
  string @0;
  filesize @1;
  int @2;
  rellink @3;
  datetime @4;
  timedelta @5;
  link @6;
  route @7;
  distance @8;
  speed @9;
  acceleration @10;
}

struct Cell {
  union {
    void @0 :Void;
    text @1 :Text;
    bool @2 :Bool;
    uint64 @3 :UInt64;
    link @4 :Link;
    timedelta @5 :Timedelta;
    timestamp @6 :Timestamp;
    route @7 :Route;
  }
}

struct Link {
  href @0 :Text;
  target @1 :Text = "_blank";
  title @2 :Text;
  download @3 :Text;
}

struct Route {
  route @0 :Text;
  id @1 :Text;
  title @2 :Text;
}

struct Compare {
  sections @0 :List(Section);
  title @1 :Text;
  error @2 :Text;
}

struct Detail {
  sections @0 :List(Section);
  summary @1 :Section;
  title @2 :Text;
  error @3 :Text;
}

struct Section {
  title @0 :Text;
  widgets @1 :List(Widget);
}

struct Widget {
  title @0 :Text;
  union {
    void @1 :Void;
    custom @12 :Custom;
    dropdown @14 :Dropdown;
    gallery @2 :Gallery;
    image @3 :Image;
    keyval @4 :Keyval;
    link @13 :Link;
    mpld3 @5 :Text;  # marv-partial or json
    map @6 :Map;
    mapPartial @11 :Text;
    pre @7 :Pre;
    table @8 :Table;
    pointcloud @9 :Pointcloud;
    video @10 :Video;
    plotly @15: Text;  # marv-partial
    pdf @16 :Pdf;  # marv-partial
    eventlist @17 :Eventlist;
  }

  struct Custom {
    type @0 :Text;
    data @1 :Text;  # json
  }

  struct Gallery {
    images @0 :List(Image);
  }

  struct Image {
    src @0 :Text;
  }

  struct Keyval {
    items @0 :List(Item);

    struct Item {
      title @0 :Text;
      formatter @1 :Formatter;
      list @2 :Bool;
      cell @3 :Cell;
    }
  }

  struct Map {
    zoom @0 :Zoom;
    layers @1 :List(Layer);
    bgcolor @2 :List(UInt8) = [240, 240, 240, 255];  # rgba
    speed :group {
      min @3 :Float32 = 1.0;
      max @4 :Float32 = 1000.0;
      default @5 :Float32 = 1.0;
    }

    struct Layer {
      title @0 :Text;
      color @1 :List(UInt8);
      transform @2 :List(Float32) = [1, 0, 0, 0,
                                     0, 1, 0, 0,
                                     0, 0, 1, 0,
                                     0, 0, 0, 1];
      union {
        geojson @3 :GeoJson;
        tiles @4 :List(Tile);
      }
    }

    struct Tile {
      title @0 :Text;
      url @1 :Text;
      attribution @2: Text;
      zoom @3 :Zoom;
      retina @4 :UInt8 = 1;
    }

    struct Zoom {
      min @0 :Int8;
      max @1 :Int8;
    }
  }

  struct Dropdown {
    widgets @0 :List(Widget);
  }

  struct Pre {
    text @0 :Text;
  }

  struct Table {
    actions @0 :List(Action);
    columns @1 :List(Column);
    rows @2 :List(Row);
    sortcolumn @3 :Int16;
    sortorder @4 :Sortorder;

    struct Action {
      name @0 :Text;
      title @1 :Text;
      method @2 :HTTPMethod;
      data @3 :Text;

      enum HTTPMethod {
        post @0;
        get @1;
      }
    }

    struct Column {
      title @0 :Text;
      align @1 :Align;
      formatter @2 :Formatter;
      list @3 :Bool;
      sortkey @4 :Text;
    }

    struct Row {
      id @0 :RowId;
      cells @1 :List(Cell);
    }

    enum Sortorder {
      ascending @0;
      descending @1;
    }
  }

  struct Pointcloud {
    uri @0 :Text;
    # TODO: rename to blob or stream or src like for image and video?
    size @1 :UInt64;
    # Bytesize of point cloud stream blob
    pointsize @2 :Float32;
    transform @3 :List(Float32) = [1, 0, 0, 0,
                                   0, 1, 0, 0,
                                   0, 0, 1, 0,
                                   0, 0, 0, 1];
    speed :group {
      min @4 :Float32 = 1.0;
      max @5 :Float32 = 1000.0;
      default @6 :Float32 = 1.0;
    }
    rangex @7 :List(Float32);
    rangey @8 :List(Float32);
    rangez @9 :List(Float32);
    ranged @10 :List(Float32);
    frameid @11 :Text;
  }

  struct Video {
    src @0 :Text;
  }

  struct Pdf {
    src @0 :Text;
  }

  struct Eventlist {
    subtype @0: Text;
    events @1 :List(TimelineEvent);
  }
}

# Copyright 2016 - 2018  Ternaris.
# SPDX-License-Identifier: AGPL-3.0-only

@0xa1475499038e2711;

using import "/marv_nodes/types.capnp".Comment;
using import "/marv_nodes/types.capnp".File;
using import "/marv_nodes/types.capnp".GeoJson;
using import "/marv_pycapnp/types.capnp".Timedelta;
using import "/marv_pycapnp/types.capnp".Timestamp;
using import "/marv_pycapnp/types.capnp".TimelineEvent;

using Filesize = UInt64;
using RowId = UInt64;

enum Align {
  left @0;
  center @1;
  right @2;
}

enum Formatter {
  string @0;
  filesize @1;
  int @2;
  rellink @3;
  datetime @4;
  timedelta @5;
  link @6;
  route @7;
  distance @8;
  speed @9;
  acceleration @10;
}

struct Cell {
  union {
    void @0 :Void;
    text @1 :Text;
    bool @2 :Bool;
    uint64 @3 :UInt64;
    link @4 :Link;
    timedelta @5 :Timedelta;
    timestamp @6 :Timestamp;
    route @7 :Route;
  }
}

struct Link {
  href @0 :Text;
  target @1 :Text = "_blank";
  title @2 :Text;
  download @3 :Text;
}

struct Route {
  route @0 :Text;
  id @1 :Text;
  title @2 :Text;
}

struct Compare {
  sections @0 :List(Section);
  title @1 :Text;
  error @2 :Text;
}

struct Detail {
  sections @0 :List(Section);
  summary @1 :Section;
  title @2 :Text;
  error @3 :Text;
}

struct Section {
  title @0 :Text;
  widgets @1 :List(Widget);
}

struct Widget {
  title @0 :Text;
  union {
    void @1 :Void;
    custom @12 :Custom;
    dropdown @14 :Dropdown;
    gallery @2 :Gallery;
    image @3 :Image;
    keyval @4 :Keyval;
    link @13 :Link;
    mpld3 @5 :Text;  # marv-partial or json
    map @6 :Map;
    mapPartial @11 :Text;
    pre @7 :Pre;
    table @8 :Table;
    pointcloud @9 :Pointcloud;
    video @10 :Video;
    plotly @15: Text;  # marv-partial
    pdf @16 :Pdf;  # marv-partial
    eventlist @17 :Eventlist;
  }

  struct Custom {
    type @0 :Text;
    data @1 :Text;  # json
  }

  struct Gallery {
    images @0 :List(Image);
  }

  struct Image {
    src @0 :Text;
  }

  struct Keyval {
    items @0 :List(Item);

    struct Item {
      title @0 :Text;
      formatter @1 :Formatter;
      list @2 :Bool;
      cell @3 :Cell;
    }
  }

  struct Map {
    zoom @0 :Zoom;
    layers @1 :List(Layer);
    bgcolor @2 :List(UInt8) = [240, 240, 240, 255];  # rgba
    speed :group {
      min @3 :Float32 = 1.0;
      max @4 :Float32 = 1000.0;
      default @5 :Float32 = 1.0;
    }

    struct Layer {
      title @0 :Text;
      color @1 :List(UInt8);
      transform @2 :List(Float32) = [1, 0, 0, 0,
                                     0, 1, 0, 0,
                                     0, 0, 1, 0,
                                     0, 0, 0, 1];
      union {
        geojson @3 :GeoJson;
        tiles @4 :List(Tile);
      }
    }

    struct Tile {
      title @0 :Text;
      url @1 :Text;
      attribution @2: Text;
      zoom @3 :Zoom;
      retina @4 :UInt8 = 1;
    }

    struct Zoom {
      min @0 :Int8;
      max @1 :Int8;
    }
  }

  struct Dropdown {
    widgets @0 :List(Widget);
  }

  struct Pre {
    text @0 :Text;
  }

  struct Table {
    actions @0 :List(Action);
    columns @1 :List(Column);
    rows @2 :List(Row);
    sortcolumn @3 :Int16;
    sortorder @4 :Sortorder;

    struct Action {
      name @0 :Text;
      title @1 :Text;
      method @2 :HTTPMethod;
      data @3 :Text;

      enum HTTPMethod {
        post @0;
        get @1;
      }
    }

    struct Column {
      title @0 :Text;
      align @1 :Align;
      formatter @2 :Formatter;
      list @3 :Bool;
      sortkey @4 :Text;
    }

    struct Row {
      id @0 :RowId;
      cells @1 :List(Cell);
    }

    enum Sortorder {
      ascending @0;
      descending @1;
    }
  }

  struct Pointcloud {
    uri @0 :Text;
    # TODO: rename to blob or stream or src like for image and video?
    size @1 :UInt64;
    # Bytesize of point cloud stream blob
    pointsize @2 :Float32;
    transform @3 :List(Float32) = [1, 0, 0, 0,
                                   0, 1, 0, 0,
                                   0, 0, 1, 0,
                                   0, 0, 0, 1];
    speed :group {
      min @4 :Float32 = 1.0;
      max @5 :Float32 = 1000.0;
      default @6 :Float32 = 1.0;
    }
    rangex @7 :List(Float32);
    rangey @8 :List(Float32);
    rangez @9 :List(Float32);
    ranged @10 :List(Float32);
  }

  struct Video {
    src @0 :Text;
  }

  struct Pdf {
    src @0 :Text;
  }

  struct Eventlist {
    subtype @0: Text;
    events @1 :List(TimelineEvent);
  }
}


remove quota field

remove quota field

@0xa9101b1fec595220;
using import "/blackrock/master.capnp".MasterConfig;
const gce :MasterConfig = (
  workerCount = 1,
  frontendCount = 1,
  frontendConfig = (
    baseUrl = "http://pdis.rocks",
    wildcardHost = "*.pdis.rocks",
    allowDemoAccounts = true,
    isTesting = true,
    outOfBeta = true,
    allowUninvited = true,
    replicasPerMachine = 2
  ),

  gce = (
        project = "blackrock-mark",
        zone = "asia-east1-a",
        instanceTypes = (
                storage = "n1-standard-1",
                worker = "n1-standard-1",
                frontend = "g1-small",
                mongo = "g1-small"
        )
  )
);

@0xa9101b1fec595220;
using import "/blackrock/master.capnp".MasterConfig;
const gce :MasterConfig = (
  workerCount = 1,
  frontendCount = 1,
  frontendConfig = (
    baseUrl = "http://pdis.rocks",
    wildcardHost = "*.pdis.rocks",
    allowDemoAccounts = true,
    quotaEnabled = false,
    isTesting = true,
    outOfBeta = true,
    allowUninvited = true,
    replicasPerMachine = 2
  ),

  gce = (
        project = "blackrock-mark",
        zone = "asia-east1-a",
        instanceTypes = (
                storage = "n1-standard-1",
                worker = "n1-standard-1",
                frontend = "g1-small",
                mongo = "g1-small"
        )
  )
);


aircraft.capnp: Add some interfaces for testing inheritance.

@0x832bcc6686a26d56;
# A schema with useful declarations for testing.
#
# This was originally copied from the Go implementation:
#
# https://github.com/zombiezen/go-capnproto2
#
# For now, a default values for pointer types have been commented out,
# so that the compiler plugin will not reject the schema in light of
# issue #28. These are marked with 'TODO#28' in the source.

const constDate :Zdate = (year = 2015, month = 8, day = 27);
const constList :List(Zdate) = [(year = 2015, month = 8, day = 27), (year = 2015, month = 8, day = 28)];
const constEnum :Airport = jfk;

struct Zdate {
  year  @0   :Int16;
  month @1   :UInt8;
  day   @2   :UInt8;
}

struct Zdata {
  data @0 :Data;
}

enum Airport {
  none @0;
  jfk @1;
  lax @2;
  sfo @3;
  luv @4;
  dfw @5;
  test @6;
  # test must be last because we use it to count
  # the number of elements in the Airport enum.
}

struct PlaneBase {
  name       @0: Text;
  homes      @1: List(Airport);
  rating     @2: Int64;
  canFly     @3: Bool;
  capacity   @4: Int64;
  maxSpeed   @5: Float64;
}

struct B737 {
  base @0: PlaneBase;
}

struct A320 {
  base @0: PlaneBase;
}

struct F16 {
  base @0: PlaneBase;
}

# need a struct with at least two pointers to catch certain bugs
struct Regression {
  base     @0: PlaneBase;
  b0       @1: Float64; # intercept
  beta     @2: List(Float64);
  planes   @3: List(Aircraft);
  ymu      @4: Float64; # y-mean in original space
  ysd      @5: Float64; # y-standard deviation in original space
}

struct Aircraft {
  #  so we can restrict
  #  and specify a Plane is required in
  #  certain places.

  union {
    void      @0: Void; # @0 will be the default, so always make @0 a Void.
    b737      @1: B737;
    a320      @2: A320;
    f16       @3: F16;
  }
}

struct Z {
  # Z must contain all types, as this is our
  # runtime type identification. It is a thin shim.

  union {
    void              @0: Void; # always first in any union.
    zz                @1: Z;    # any. fyi, this can't be 'z' alone.

    f64               @2: Float64;
    f32               @3: Float32;

    i64               @4: Int64;
    i32               @5: Int32;
    i16               @6: Int16;
    i8                @7: Int8;

    u64               @8:  UInt64;
    u32               @9:  UInt32;
    u16               @10: UInt16;
    u8                @11: UInt8;

    bool              @12: Bool;
    text              @13: Text;
    blob              @14: Data;

    f64vec            @15: List(Float64);
    f32vec            @16: List(Float32);

    i64vec            @17: List(Int64);
    i32vec            @18: List(Int32);
    i16vec            @19: List(Int16);
    i8vec             @20: List(Int8);

    u64vec            @21: List(UInt64);
    u32vec            @22: List(UInt32);
    u16vec            @23: List(UInt16);
    u8vec             @24: List(UInt8);

    boolvec           @39: List(Bool);
    datavec           @40: List(Data);
    textvec           @41: List(Text);

    zvec              @25: List(Z);
    zvecvec           @26: List(List(Z));

    zdate             @27: Zdate;
    zdata             @28: Zdata;

    aircraftvec       @29: List(Aircraft);
    aircraft          @30: Aircraft;
    regression        @31: Regression;
    planebase         @32: PlaneBase;
    airport           @33: Airport;
    b737              @34: B737;
    a320              @35: A320;
    f16               @36: F16;
    zdatevec          @37: List(Zdate);
    zdatavec          @38: List(Zdata);

    grp               :group {
      first           @42 :UInt64;
      second          @43 :UInt64;
    }

    echo              @44 :Echo;
    echoBases         @45 :EchoBases;
  }
}

# tests for Text/List(Text) recusion handling

struct Counter {
  size  @0: Int64;
  words @1: Text;
  wordlist @2: List(Text);
}

struct Bag {
  counter  @0: Counter;
}

struct Zserver {
   waitingjobs       @0: List(Zjob);
}

struct Zjob {
    cmd        @0: Text;
    args       @1: List(Text);
}

# versioning test structs

struct VerEmpty {
}

struct VerOneData {
    val @0: Int16;
}

struct VerTwoData {
    val @0: Int16;
    duo @1: Int64;
}

struct VerOnePtr {
    ptr @0: VerOneData;
}

struct VerTwoPtr {
       ptr1 @0: VerOneData;
       ptr2 @1: VerOneData;
}

struct VerTwoDataTwoPtr {
    val @0: Int16;
    duo @1: Int64;
    ptr1 @2: VerOneData;
    ptr2 @3: VerOneData;
}

struct HoldsVerEmptyList {
  mylist @0: List(VerEmpty);
}

struct HoldsVerOneDataList {
  mylist @0: List(VerOneData);
}

struct HoldsVerTwoDataList {
  mylist @0: List(VerTwoData);
}

struct HoldsVerOnePtrList {
  mylist @0: List(VerOnePtr);
}

struct HoldsVerTwoPtrList {
  mylist @0: List(VerTwoPtr);
}

struct HoldsVerTwoTwoList {
  mylist @0: List(VerTwoDataTwoPtr);
}

struct HoldsVerTwoTwoPlus {
  mylist @0: List(VerTwoTwoPlus);
}

struct VerTwoTwoPlus {
    val @0: Int16;
    duo @1: Int64;
    ptr1 @2: VerTwoDataTwoPtr;
    ptr2 @3: VerTwoDataTwoPtr;
    tre  @4: Int64;
    lst3 @5: List(Int64);
}

# text handling

struct HoldsText {
       txt @0: Text;
       lst @1: List(Text);
       lstlst @2: List(List(Text));
}

# test that we avoid unnecessary truncation

struct WrapEmpty {
   mightNotBeReallyEmpty @0: VerEmpty;
}

struct Wrap2x2 {
   mightNotBeReallyEmpty @0: VerTwoDataTwoPtr;
}

struct Wrap2x2plus {
   mightNotBeReallyEmpty @0: VerTwoTwoPlus;
}

# test voids in a union

struct VoidUnion {
  union {
    a @0 :Void;
    b @1 :Void;
  }
}

# test List(List(Struct(List)))

struct Nester1Capn {
   strs  @0:   List(Text);
}

struct RWTestCapn {
   nestMatrix  @0:   List(List(Nester1Capn));
}

struct ListStructCapn {
   vec  @0:   List(Nester1Capn);
}

# test interfaces

interface Echo {
  echo @0 (in :Text) -> (out :Text);
}

struct Hoth {
  base @0 :EchoBase;
}

struct EchoBase {
  echo @0 :Echo;
}

# test List(Struct(Interface))

struct EchoBases {
	bases @0 :List(EchoBase);
}

# test transforms

struct StackingRoot {
  a @1 :StackingA;
  aWithDefault @0 :StackingA ;#TODO#28 = (num = 42);
}

struct StackingA {
  num @0 :Int32;
  b @1 :StackingB;
}

struct StackingB {
  num @0 :Int32;
}

interface CallSequence {
  getNumber @0 () -> (n :UInt32);
}

interface CounterFactory {
  newCounter @0 (start :UInt32) -> (counter :CallSequence);
}

interface CounterAcceptor {
  accept @0 (counter :CallSequence);
}

# test inheritance

interface Top {
	top @0 ();
}

interface Left extends(Top) {
	left @0 ();
}

interface Right extends(Top) {
	right @0 ();
}

interface Bottom extends(Left, Right) {
	bottom @0 ();
}

# test defaults

struct Defaults {
  text @0 :Text ;#TODO#28 = "foo";
  data @1 :Data ;#TODO#28 = "bar";
  float @2 :Float32 = 3.14;
  int @3 :Int32 = -123;
  uint @4 :UInt32 = 42;
}

# benchmarks

struct BenchmarkA {
  name     @0 :Text;
  birthDay @1 :Int64;
  phone    @2 :Text;
  siblings @3 :Int32;
  spouse   @4 :Bool;
  money    @5 :Float64;
}

@0x832bcc6686a26d56;
# A schema with useful declarations for testing.
#
# This is copied from the Go implementation:
#
# https://github.com/zombiezen/go-capnproto2
#
# For now, a default values for pointer types have been commented out,
# so that the compiler plugin will not reject the schema in light of
# issue #28. These are marked with 'TODO#28' in the source.

const constDate :Zdate = (year = 2015, month = 8, day = 27);
const constList :List(Zdate) = [(year = 2015, month = 8, day = 27), (year = 2015, month = 8, day = 28)];
const constEnum :Airport = jfk;

struct Zdate {
  year  @0   :Int16;
  month @1   :UInt8;
  day   @2   :UInt8;
}

struct Zdata {
  data @0 :Data;
}

enum Airport {
  none @0;
  jfk @1;
  lax @2;
  sfo @3;
  luv @4;
  dfw @5;
  test @6;
  # test must be last because we use it to count
  # the number of elements in the Airport enum.
}

struct PlaneBase {
  name       @0: Text;
  homes      @1: List(Airport);
  rating     @2: Int64;
  canFly     @3: Bool;
  capacity   @4: Int64;
  maxSpeed   @5: Float64;
}

struct B737 {
  base @0: PlaneBase;
}

struct A320 {
  base @0: PlaneBase;
}

struct F16 {
  base @0: PlaneBase;
}

# need a struct with at least two pointers to catch certain bugs
struct Regression {
  base     @0: PlaneBase;
  b0       @1: Float64; # intercept
  beta     @2: List(Float64);
  planes   @3: List(Aircraft);
  ymu      @4: Float64; # y-mean in original space
  ysd      @5: Float64; # y-standard deviation in original space
}

struct Aircraft {
  #  so we can restrict
  #  and specify a Plane is required in
  #  certain places.

  union {
    void      @0: Void; # @0 will be the default, so always make @0 a Void.
    b737      @1: B737;
    a320      @2: A320;
    f16       @3: F16;
  }
}

struct Z {
  # Z must contain all types, as this is our
  # runtime type identification. It is a thin shim.

  union {
    void              @0: Void; # always first in any union.
    zz                @1: Z;    # any. fyi, this can't be 'z' alone.

    f64               @2: Float64;
    f32               @3: Float32;

    i64               @4: Int64;
    i32               @5: Int32;
    i16               @6: Int16;
    i8                @7: Int8;

    u64               @8:  UInt64;
    u32               @9:  UInt32;
    u16               @10: UInt16;
    u8                @11: UInt8;

    bool              @12: Bool;
    text              @13: Text;
    blob              @14: Data;

    f64vec            @15: List(Float64);
    f32vec            @16: List(Float32);

    i64vec            @17: List(Int64);
    i32vec            @18: List(Int32);
    i16vec            @19: List(Int16);
    i8vec             @20: List(Int8);

    u64vec            @21: List(UInt64);
    u32vec            @22: List(UInt32);
    u16vec            @23: List(UInt16);
    u8vec             @24: List(UInt8);

    boolvec           @39: List(Bool);
    datavec           @40: List(Data);
    textvec           @41: List(Text);

    zvec              @25: List(Z);
    zvecvec           @26: List(List(Z));

    zdate             @27: Zdate;
    zdata             @28: Zdata;

    aircraftvec       @29: List(Aircraft);
    aircraft          @30: Aircraft;
    regression        @31: Regression;
    planebase         @32: PlaneBase;
    airport           @33: Airport;
    b737              @34: B737;
    a320              @35: A320;
    f16               @36: F16;
    zdatevec          @37: List(Zdate);
    zdatavec          @38: List(Zdata);

    grp               :group {
      first           @42 :UInt64;
      second          @43 :UInt64;
    }

    echo              @44 :Echo;
    echoBases         @45 :EchoBases;
  }
}

# tests for Text/List(Text) recusion handling

struct Counter {
  size  @0: Int64;
  words @1: Text;
  wordlist @2: List(Text);
}

struct Bag {
  counter  @0: Counter;
}

struct Zserver {
   waitingjobs       @0: List(Zjob);
}

struct Zjob {
    cmd        @0: Text;
    args       @1: List(Text);
}

# versioning test structs

struct VerEmpty {
}

struct VerOneData {
    val @0: Int16;
}

struct VerTwoData {
    val @0: Int16;
    duo @1: Int64;
}

struct VerOnePtr {
    ptr @0: VerOneData;
}

struct VerTwoPtr {
       ptr1 @0: VerOneData;
       ptr2 @1: VerOneData;
}

struct VerTwoDataTwoPtr {
    val @0: Int16;
    duo @1: Int64;
    ptr1 @2: VerOneData;
    ptr2 @3: VerOneData;
}

struct HoldsVerEmptyList {
  mylist @0: List(VerEmpty);
}

struct HoldsVerOneDataList {
  mylist @0: List(VerOneData);
}

struct HoldsVerTwoDataList {
  mylist @0: List(VerTwoData);
}

struct HoldsVerOnePtrList {
  mylist @0: List(VerOnePtr);
}

struct HoldsVerTwoPtrList {
  mylist @0: List(VerTwoPtr);
}

struct HoldsVerTwoTwoList {
  mylist @0: List(VerTwoDataTwoPtr);
}

struct HoldsVerTwoTwoPlus {
  mylist @0: List(VerTwoTwoPlus);
}

struct VerTwoTwoPlus {
    val @0: Int16;
    duo @1: Int64;
    ptr1 @2: VerTwoDataTwoPtr;
    ptr2 @3: VerTwoDataTwoPtr;
    tre  @4: Int64;
    lst3 @5: List(Int64);
}

# text handling

struct HoldsText {
       txt @0: Text;
       lst @1: List(Text);
       lstlst @2: List(List(Text));
}

# test that we avoid unnecessary truncation

struct WrapEmpty {
   mightNotBeReallyEmpty @0: VerEmpty;
}

struct Wrap2x2 {
   mightNotBeReallyEmpty @0: VerTwoDataTwoPtr;
}

struct Wrap2x2plus {
   mightNotBeReallyEmpty @0: VerTwoTwoPlus;
}

# test voids in a union

struct VoidUnion {
  union {
    a @0 :Void;
    b @1 :Void;
  }
}

# test List(List(Struct(List)))

struct Nester1Capn {
   strs  @0:   List(Text);
}

struct RWTestCapn {
   nestMatrix  @0:   List(List(Nester1Capn));
}

struct ListStructCapn {
   vec  @0:   List(Nester1Capn);
}

# test interfaces

interface Echo {
  echo @0 (in :Text) -> (out :Text);
}

struct Hoth {
  base @0 :EchoBase;
}

struct EchoBase {
  echo @0 :Echo;
}

# test List(Struct(Interface))

struct EchoBases {
	bases @0 :List(EchoBase);
}

# test transforms

struct StackingRoot {
  a @1 :StackingA;
  aWithDefault @0 :StackingA ;#TODO#28 = (num = 42);
}

struct StackingA {
  num @0 :Int32;
  b @1 :StackingB;
}

struct StackingB {
  num @0 :Int32;
}

interface CallSequence {
  getNumber @0 () -> (n :UInt32);
}

interface CounterFactory {
  newCounter @0 (start :UInt32) -> (counter :CallSequence);
}

interface CounterAcceptor {
  accept @0 (counter :CallSequence);
}

# test defaults

struct Defaults {
  text @0 :Text ;#TODO#28 = "foo";
  data @1 :Data ;#TODO#28 = "bar";
  float @2 :Float32 = 3.14;
  int @3 :Int32 = -123;
  uint @4 :UInt32 = 42;
}

# benchmarks

struct BenchmarkA {
  name     @0 :Text;
  birthDay @1 :Int64;
  phone    @2 :Text;
  siblings @3 :Int32;
  spouse   @4 :Bool;
  money    @5 :Float64;
}