bremen_matt
bremen_matt

Reputation: 7369

Define a type alias in Cap'n Proto

I do not understand how one would export a type alias in Cap'n Proto.

The simplest example I can think of is a point cloud. Suppose we have a schema such as

struct Point {
    x @0: Float32 = 0;
    y @1: Float32 = 0;
}

and then I want to also export a list of those points as a fixed type:

struct Point {
    x @0: Float32 = 0;
    y @1: Float32 = 0;
}

using PointCloud = List(Point);

It seems to me (based on the generated code) that the PointCloud type is not exported as part of the schema. It seems that that PointCloud is only usable interally in the schema file.

How can I export this alias so that it is usable externally?

Upvotes: 0

Views: 260

Answers (2)

Jeff Venable
Jeff Venable

Reputation: 1

If you're using golang, generics cover this using the base capnp types in the code generator; e.g.:

type Point_List = capnp.StructList[Point]

Other language code generators may do something similar; you'll need to review their output as applicable.

Upvotes: 0

bremen_matt
bremen_matt

Reputation: 7369

I stumbled across the roadmap, and there there is the statement:

Type aliases: Ability to define a type which is just an alias of some other type, and have it show up as e.g. a typedef in languages that support that. (The current using keyword is intended only for local use and does not affect code generation.)

So perhaps this is the answer to my question... It is simply not currently supported.

Upvotes: 0

Related Questions