diff --git a/Capnp.Net.Runtime/DeserializerState.cs b/Capnp.Net.Runtime/DeserializerState.cs
index 1aee28e..eaa24f9 100644
--- a/Capnp.Net.Runtime/DeserializerState.cs
+++ b/Capnp.Net.Runtime/DeserializerState.cs
@@ -350,7 +350,7 @@ namespace Capnp
throw new DeserializationException("Error decoding double-far pointer: not followed by intra-segment pointer");
CurrentSegmentIndex = pointer1.TargetSegmentIndex;
- Offset = 0;
+ Offset = pointer1.LandingPadOffset;
pointer = pointer2;
offset = -1;
}
diff --git a/Capnp.Net.Runtime/Rpc/rpc.cs b/Capnp.Net.Runtime/Rpc/rpc.cs
index d2d8c5f..c48f8d0 100644
--- a/Capnp.Net.Runtime/Rpc/rpc.cs
+++ b/Capnp.Net.Runtime/Rpc/rpc.cs
@@ -1,3 +1,4 @@
+#pragma warning disable CS1591
using Capnp;
using Capnp.Rpc;
using System;
diff --git a/Capnp.Net.Runtime/SerializerState.cs b/Capnp.Net.Runtime/SerializerState.cs
index 293a424..cb219d1 100644
--- a/Capnp.Net.Runtime/SerializerState.cs
+++ b/Capnp.Net.Runtime/SerializerState.cs
@@ -375,7 +375,7 @@ namespace Capnp
farPtr2.SetFarPointer(target.SegmentIndex, target.Offset, false);
var farSpan = FarSpan(landingPadSlice.SegmentIndex);
farSpan[landingPadSlice.Offset] = farPtr2;
- targetPtr.Offset = target.Offset;
+ targetPtr.Offset = 0;
farSpan[landingPadSlice.Offset + 1] = targetPtr;
}
}
diff --git a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj
index 77462b1..86f1a6b 100644
--- a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj
+++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj
@@ -30,6 +30,10 @@
+
+
+
+
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded b/CapnpC.CSharp.Generator.Tests/Embedded
new file mode 100644
index 0000000..79d5e7d
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin
index 14f05c8..0195af5 100644
Binary files a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin
index dcc032a..5681502 100644
Binary files a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin
index 4a92c1a..6c81ea6 100644
Binary files a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin
index 45ae2c0..28fe926 100644
Binary files a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/rpc-csharp.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/rpc-csharp.capnp.bin
index 7209077..0a66adb 100644
Binary files a/CapnpC.CSharp.Generator.Tests/Embedded Resources/rpc-csharp.capnp.bin and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/rpc-csharp.capnp.bin differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin
index 66c8d13..199c9d3 100644
Binary files a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin differ
diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest1.capnp
similarity index 100%
rename from CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp
rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest1.capnp
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp
index fa0f149..730a740 100644
--- a/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Christian Köllner and contributors
+# Copyright (c) 2020 Christian Köllner and contributors
# This is a modified version of rpc.capnp, found in the original distribution
# Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
# Licensed under the MIT License:
@@ -110,6 +110,8 @@
# network at level 4. And since Cap'n Proto IPC is extremely fast, it may never make sense to
# bother implementing any other vat network protocol -- just use the correct container type and get
# it for free.
+# $$embed
+# #pragma warning disable CS1591
using CSharp = import "/csharp.capnp";
$CSharp.namespace("Capnp.Rpc");
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp
index 0a4a507..d68c71c 100644
--- a/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp
@@ -21,7 +21,7 @@
@0xd508eebdc2dc42b8;
-using Cxx = import "c++.capnp";
+using Cxx = import "/capnp/c++.capnp";
# Use a namespace likely to cause trouble if the generated code doesn't use fully-qualified
# names for stuff in the capnproto namespace.
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated-json.binary b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated-json.binary
new file mode 100644
index 0000000..6c54755
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated-json.binary differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json
new file mode 100644
index 0000000..bb51400
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json
@@ -0,0 +1,22 @@
+{ "names-can_contain!anything Really": "foo",
+ "flatFoo": 123,
+ "flatBar": "abc",
+ "renamed-flatBaz": {"hello": true},
+ "flatQux": "cba",
+ "pfx.foo": "this is a long string in order to force multi-line pretty printing",
+ "pfx.renamed-bar": 321,
+ "pfx.baz": {"hello": true},
+ "pfx.xfp.qux": "fed",
+ "union-type": "renamed-bar",
+ "barMember": 789,
+ "multiMember": "ghi",
+ "dependency": {"renamed-foo": "corge"},
+ "simpleGroup": {"renamed-grault": "garply"},
+ "enums": ["qux", "renamed-bar", "foo", "renamed-baz"],
+ "innerJson": [123, "hello", {"object": true}],
+ "testBase64": "ZnJlZA==",
+ "testHex": "706c756768",
+ "bUnion": "renamed-bar",
+ "bValue": 678,
+ "externalUnion": {"type": "bar", "value": "cba"},
+ "unionWithVoid": {"type": "voidValue"} }
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/binary b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/binary
new file mode 100644
index 0000000..ea39763
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/binary differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild
new file mode 100644
index 0000000..a909e97
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild
@@ -0,0 +1,161 @@
+# 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.
+
+# This file is intended to test that various error cases are detected as errors. The error
+# output is matched against a golden file. The file name has the .nobuild extension to make
+# sure that a build system which automatically builds .capnp files does not try to build this one.
+
+#
+
+@0xccd0890aa4926a9b;
+# Can't really test the missing-ID error because the output is intentionally unpredictable.
+
+const notType :Int32 = 123;
+annotation notFieldAnnotation(struct) :Int32;
+annotation fieldAnnotation(field) :Int32;
+
+struct Foo {
+ dupName @0 :Int32;
+ dupName @1 :Int32;
+ dupNumber1 @2 :Int32;
+ dupNumber2 @2 :Int32;
+
+ missingNumber @4 :Int32;
+ next @5 :Int32;
+
+ emptyUnion :union {}
+ emptyGroup :group {}
+
+ singletonUnion :union {
+ field @6 :Int32;
+ }
+
+ union {
+ dupName @7 :Int32;
+ f8 @8 :Int32;
+ }
+ union {
+ f9 @9 :Int32;
+ f10 @10 :Int32;
+ }
+
+ struct wrongTypeStyle {}
+ WrongFieldStyle @11 :Int32;
+ under_score @12 :Int32;
+
+ containsStruct :group {
+ f13 @13 :Int32;
+ struct CantNestHere {}
+ }
+
+ retroUnion @16! :union {
+ f14 @14 :Int32;
+ f15 @15 :Int32;
+ }
+
+ missingColonAndEclamation @18 union {
+ f19 @19 :Int32;
+ f20 @20 :Int32;
+ }
+
+ missingExclamation @21 :union {
+ f22 @22 :Int32;
+ f23 @23 :Int32;
+ }
+
+ missingColon @24! union {
+ f19 @25 :Int32;
+ f20 @26 :Int32;
+ }
+
+ unnamedInNamed :union {
+ f27 @27 :Int32;
+ f28 @28 :Int32;
+ union {
+ # content is ignored
+ }
+ }
+
+ listWithoutParam @31 :List;
+ listWithTooManyParams @32 :List(Int32, Int64);
+ listAnyPointer @33 :List(AnyPointer);
+ notAType @34 :notType;
+ noParams @35 :Foo(Int32);
+
+ defaultOutOfRange @36 :Int16 = 1234567;
+ defaultOutOfRange2 @37 :UInt16 = -1;
+ defaultWrongType @38 :Text = 123;
+ defaultWrongType2 @39 :Text = [123];
+ defaultWrongType3 @40 :Text = (foo = 123, bar = 456);
+ defaultTooBigToBeNegative @41 :Int64 = -0x8000000000000001;
+ defaultNotConstant @42 :Int32 = .Foo;
+ defaultConstantNotQualified @43 :Int32 = notType;
+
+ notAnnotation @44 :Int32 $Foo(123);
+ badAnnotation @45 :Int32 $notFieldAnnotation(123);
+ notVoidAnnotation @46 :Int32 $fieldAnnotation;
+
+ undefinedImport @17 :import "noshuchfile.capnp".Bar;
+ undefinedAbsolute @47 : .NoSuch;
+ undefinedRelative @29 :NoSuch;
+ undefinedMember @30 :Foo.NoSuch;
+}
+
+struct Bar {
+ x @3 :Text;
+ someGroup :group {
+ defaultMissingFieldName @2 :Bar = (x = "abcd", 456);
+ defaultNoSuchField @0 :Bar = (nosuchfield = 123);
+ defaultGroupMismatch @1 :Bar = (someGroup = 123);
+ }
+}
+
+
+using Bar;
+
+enum DupEnumerants {
+ dupName @0;
+ dupName @1;
+ dupNumber1 @2;
+ dupNumber2 @2;
+}
+
+const recursive: UInt32 = .recursive;
+
+struct Generic(T, U) {
+}
+
+struct UseGeneric {
+ tooFew @0 :Generic(Text);
+ tooMany @1 :Generic(Text, Data, List(Int32));
+ doubleBind @2 :Generic(Text, Data)(Data, Text);
+ primitiveBinding @3 :Generic(Text, Int32);
+}
+
+const embedBadType :UInt32 = embed "binary";
+const embedNoSuchFile :Data = embed "no-such-file";
+
+using Baz = import "nosuchfile-unused.capnp".Baz;
+# Check that an import in an unused `using` still reports error.
+
+interface TestInterface {
+ foo @0 (a :UInt32 = null);
+}
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt
new file mode 100644
index 0000000..ed238e4
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt
@@ -0,0 +1,60 @@
+file:74:30-32: error: As of Cap'n Proto v0.3, it is no longer necessary to assign numbers to unions. However, removing the number will break binary compatibility. If this is an old protocol and you need to retain compatibility, please add an exclamation point after the number to indicate that it is really needed, e.g. `foo @1! :union {`. If this is a new protocol or compatibility doesn't matter, just remove the @n entirely. Sorry for the inconvenience, and thanks for being an early adopter! :)
+file:74:30-32: error: As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon for named unions, e.g. `foo :union {`.
+file:79:23-25: error: As of Cap'n Proto v0.3, it is no longer necessary to assign numbers to unions. However, removing the number will break binary compatibility. If this is an old protocol and you need to retain compatibility, please add an exclamation point after the number to indicate that it is really needed, e.g. `foo @1! :union {`. If this is a new protocol or compatibility doesn't matter, just remove the @n entirely. Sorry for the inconvenience, and thanks for being an early adopter! :)
+file:84:17-19: error: As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon for named unions, e.g. `foo :union {`.
+file:132:7-10: error: 'using' declaration without '=' must specify a named declaration from a different scope.
+file:37:3-10: error: 'dupName' is already defined in this scope.
+file:36:3-10: error: 'dupName' previously defined here.
+file:52:5-12: error: 'dupName' is already defined in this scope.
+file:36:3-10: error: 'dupName' previously defined here.
+file:55:3-8: error: An unnamed union is already defined in this scope.
+file:51:3-8: error: Previously defined here.
+file:60:10-24: error: Type names must begin with a capital letter.
+file:61:3-18: error: Non-type names must begin with a lower-case letter.
+file:62:3-14: error: Cap'n Proto declaration names should use camelCase and must not contain underscores. (Code generators may convert names to the appropriate style for the target language.)
+file:66:5-27: error: This kind of declaration doesn't belong here.
+file:44:3-23: error: Union must have at least two members.
+file:45:3-23: error: Group must have at least one member.
+file:47: error: Union must have at least two members.
+file:92: error: Unions cannot contain unnamed unions.
+file:39:15-16: error: Duplicate ordinal number.
+file:38:15-16: error: Ordinal @2 originally used here.
+file:41:18-19: error: Skipped ordinal @3. Ordinals must be sequential with no holes.
+file:69:15-17: error: Union ordinal, if specified, must be greater than no more than one of its member ordinals (i.e. there can only be one field retroactively unionized).
+file:116:31-50: error: Import failed: noshuchfile.capnp
+file:118:26-32: error: Not defined: NoSuch
+file:119:28-34: error: 'Foo' has no member named 'NoSuch'
+file:97:25-29: error: 'List' requires exactly one parameter.
+file:98:30-48: error: Too many generic parameters.
+file:98:30-34: error: 'List' requires exactly one parameter.
+file:99:23-39: error: 'List(AnyPointer)' is not supported.
+file:100:17-24: error: 'notType' is not a type.
+file:101:17-27: error: Declaration does not accept generic parameters.
+file:103:34-41: error: Integer value out of range.
+file:104:37-38: error: Integer value out of range.
+file:105:32-35: error: Type mismatch; expected Text.
+file:106:33-38: error: Type mismatch; expected Text.
+file:107:33-55: error: Type mismatch; expected Text.
+file:108:43-61: error: Integer is too big to be negative.
+file:109:35-39: error: '.Foo' does not refer to a constant.
+file:110:44-51: error: Constant names must be qualified to avoid confusion. Please replace 'notType' with '.notType', if that's what you intended.
+file:117:28-34: error: Not defined: NoSuch
+file:112:29-32: error: 'Foo' is not an annotation.
+file:113:29-47: error: 'notFieldAnnotation' cannot be applied to this kind of declaration.
+file:114:33-48: error: 'fieldAnnotation' requires a value.
+file:126:35-46: error: Struct has no field named 'nosuchfield'.
+file:127:49-52: error: Type mismatch; expected group.
+file:125:52-55: error: Missing field name.
+file:136:3-10: error: 'dupName' is already defined in this scope.
+file:135:3-10: error: 'dupName' previously defined here.
+file:138:15-16: error: Duplicate ordinal number.
+file:137:15-16: error: Ordinal @2 originally used here.
+file:141:7-16: error: Declaration recursively depends on itself.
+file:147:14-27: error: Not enough generic parameters.
+file:148:15-47: error: Too many generic parameters.
+file:149:18-49: error: Double-application of generic parameters.
+file:150:38-43: error: Sorry, only pointer types can be used as generic parameters.
+file:153:30-44: error: Embeds can only be used when Text, Data, or a struct is expected.
+file:154:37-51: error: Couldn't read file for embed: no-such-file
+file:160:23-27: error: Only pointer parameters can declare their default as 'null'.
+file:156:20-45: error: Import failed: nosuchfile-unused.capnp
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/flat b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/flat
new file mode 100644
index 0000000..427fc31
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/flat differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/lists.binary b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/lists.binary
new file mode 100644
index 0000000..30ae630
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/lists.binary differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packed b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packed
new file mode 100644
index 0000000..8627833
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packed differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packedflat b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packedflat
new file mode 100644
index 0000000..7c304a9
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packedflat differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json
new file mode 100644
index 0000000..abf82d6
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json
@@ -0,0 +1,88 @@
+{ "voidField": null,
+ "boolField": true,
+ "int8Field": -123,
+ "int16Field": -12345,
+ "int32Field": -12345678,
+ "int64Field": "-123456789012345",
+ "uInt8Field": 234,
+ "uInt16Field": 45678,
+ "uInt32Field": 3456789012,
+ "uInt64Field": "12345678901234567890",
+ "float32Field": 1234.5,
+ "float64Field": -1.23e47,
+ "textField": "foo",
+ "dataField": [98, 97, 114],
+ "structField": {
+ "voidField": null,
+ "boolField": true,
+ "int8Field": -12,
+ "int16Field": 3456,
+ "int32Field": -78901234,
+ "int64Field": "56789012345678",
+ "uInt8Field": 90,
+ "uInt16Field": 1234,
+ "uInt32Field": 56789012,
+ "uInt64Field": "345678901234567890",
+ "float32Field": -1.2499999646475857e-10,
+ "float64Field": 345,
+ "textField": "baz",
+ "dataField": [113, 117, 120],
+ "structField": {
+ "voidField": null,
+ "boolField": false,
+ "int8Field": 0,
+ "int16Field": 0,
+ "int32Field": 0,
+ "int64Field": "0",
+ "uInt8Field": 0,
+ "uInt16Field": 0,
+ "uInt32Field": 0,
+ "uInt64Field": "0",
+ "float32Field": 0,
+ "float64Field": 0,
+ "textField": "nested",
+ "structField": {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "really nested", "enumField": "foo", "interfaceField": null},
+ "enumField": "foo",
+ "interfaceField": null },
+ "enumField": "baz",
+ "interfaceField": null,
+ "voidList": [null, null, null],
+ "boolList": [false, true, false, true, true],
+ "int8List": [12, -34, -128, 127],
+ "int16List": [1234, -5678, -32768, 32767],
+ "int32List": [12345678, -90123456, -2147483648, 2147483647],
+ "int64List": ["123456789012345", "-678901234567890", "-9223372036854775808", "9223372036854775807"],
+ "uInt8List": [12, 34, 0, 255],
+ "uInt16List": [1234, 5678, 0, 65535],
+ "uInt32List": [12345678, 90123456, 0, 4294967295],
+ "uInt64List": ["123456789012345", "678901234567890", "0", "18446744073709551615"],
+ "float32List": [0, 1234567, 9.9999999338158125e36, -9.9999999338158125e36, 9.99999991097579e-38, -9.99999991097579e-38],
+ "float64List": [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
+ "textList": ["quux", "corge", "grault"],
+ "dataList": [[103, 97, 114, 112, 108, 121], [119, 97, 108, 100, 111], [102, 114, 101, 100]],
+ "structList": [
+ {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "x structlist 1", "enumField": "foo", "interfaceField": null},
+ {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "x structlist 2", "enumField": "foo", "interfaceField": null},
+ {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "x structlist 3", "enumField": "foo", "interfaceField": null} ],
+ "enumList": ["qux", "bar", "grault"] },
+ "enumField": "corge",
+ "interfaceField": null,
+ "voidList": [null, null, null, null, null, null],
+ "boolList": [true, false, false, true],
+ "int8List": [111, -111],
+ "int16List": [11111, -11111],
+ "int32List": [111111111, -111111111],
+ "int64List": ["1111111111111111111", "-1111111111111111111"],
+ "uInt8List": [111, 222],
+ "uInt16List": [33333, 44444],
+ "uInt32List": [3333333333],
+ "uInt64List": ["11111111111111111111"],
+ "float32List": [5555.5, "Infinity", "-Infinity", "NaN"],
+ "float64List": [7777.75, "Infinity", "-Infinity", "NaN"],
+ "textList": ["plugh", "xyzzy", "thud"],
+ "dataList": [[111, 111, 112, 115], [101, 120, 104, 97, 117, 115, 116, 101, 100], [114, 102, 99, 51, 48, 57, 50]],
+ "structList": [
+ {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "structlist 1", "enumField": "foo", "interfaceField": null},
+ {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "structlist 2", "enumField": "foo", "interfaceField": null},
+ {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "structlist 3", "enumField": "foo", "interfaceField": null} ],
+ "enumList": ["foo", "garply"] }
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt
new file mode 100644
index 0000000..079ff8d
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt
@@ -0,0 +1,187 @@
+( voidField = void,
+ boolField = true,
+ int8Field = -123,
+ int16Field = -12345,
+ int32Field = -12345678,
+ int64Field = -123456789012345,
+ uInt8Field = 234,
+ uInt16Field = 45678,
+ uInt32Field = 3456789012,
+ uInt64Field = 12345678901234567890,
+ float32Field = 1234.5,
+ float64Field = -1.23e47,
+ textField = "foo",
+ dataField = "bar",
+ structField = (
+ voidField = void,
+ boolField = true,
+ int8Field = -12,
+ int16Field = 3456,
+ int32Field = -78901234,
+ int64Field = 56789012345678,
+ uInt8Field = 90,
+ uInt16Field = 1234,
+ uInt32Field = 56789012,
+ uInt64Field = 345678901234567890,
+ float32Field = -1.25e-10,
+ float64Field = 345,
+ textField = "baz",
+ dataField = "qux",
+ structField = (
+ voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "nested",
+ structField = (
+ voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "really nested",
+ enumField = foo,
+ interfaceField = void ),
+ enumField = foo,
+ interfaceField = void ),
+ enumField = baz,
+ interfaceField = void,
+ voidList = [void, void, void],
+ boolList = [false, true, false, true, true],
+ int8List = [12, -34, -128, 127],
+ int16List = [1234, -5678, -32768, 32767],
+ int32List = [12345678, -90123456, -2147483648, 2147483647],
+ int64List = [123456789012345, -678901234567890, -9223372036854775808, 9223372036854775807],
+ uInt8List = [12, 34, 0, 255],
+ uInt16List = [1234, 5678, 0, 65535],
+ uInt32List = [12345678, 90123456, 0, 4294967295],
+ uInt64List = [123456789012345, 678901234567890, 0, 18446744073709551615],
+ float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
+ float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
+ textList = ["quux", "corge", "grault"],
+ dataList = ["garply", "waldo", "fred"],
+ structList = [
+ ( voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "x structlist 1",
+ enumField = foo,
+ interfaceField = void ),
+ ( voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "x structlist 2",
+ enumField = foo,
+ interfaceField = void ),
+ ( voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "x structlist 3",
+ enumField = foo,
+ interfaceField = void ) ],
+ enumList = [qux, bar, grault] ),
+ enumField = corge,
+ interfaceField = void,
+ voidList = [void, void, void, void, void, void],
+ boolList = [true, false, false, true],
+ int8List = [111, -111],
+ int16List = [11111, -11111],
+ int32List = [111111111, -111111111],
+ int64List = [1111111111111111111, -1111111111111111111],
+ uInt8List = [111, 222],
+ uInt16List = [33333, 44444],
+ uInt32List = [3333333333],
+ uInt64List = [11111111111111111111],
+ float32List = [5555.5, inf, -inf, nan],
+ float64List = [7777.75, inf, -inf, nan],
+ textList = ["plugh", "xyzzy", "thud"],
+ dataList = ["oops", "exhausted", "rfc3092"],
+ structList = [
+ ( voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "structlist 1",
+ enumField = foo,
+ interfaceField = void ),
+ ( voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "structlist 2",
+ enumField = foo,
+ interfaceField = void ),
+ ( voidField = void,
+ boolField = false,
+ int8Field = 0,
+ int16Field = 0,
+ int32Field = 0,
+ int64Field = 0,
+ uInt8Field = 0,
+ uInt16Field = 0,
+ uInt32Field = 0,
+ uInt64Field = 0,
+ float32Field = 0,
+ float64Field = 0,
+ textField = "structlist 3",
+ enumField = foo,
+ interfaceField = void ) ],
+ enumList = [foo, garply] )
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented
new file mode 100644
index 0000000..c2840b4
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented-packed b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented-packed
new file mode 100644
index 0000000..c4a968e
Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented-packed differ
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.json b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.json
new file mode 100644
index 0000000..26cbfd0
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.json
@@ -0,0 +1 @@
+{"voidField":null,"boolField":true,"int8Field":-123,"int16Field":-12345,"int32Field":-12345678,"int64Field":"-123456789012345","uInt8Field":234,"uInt16Field":45678,"uInt32Field":3456789012,"uInt64Field":"12345678901234567890","float32Field":1234.5,"float64Field":-1.23e47,"textField":"foo","dataField":[98,97,114],"structField":{"voidField":null,"boolField":true,"int8Field":-12,"int16Field":3456,"int32Field":-78901234,"int64Field":"56789012345678","uInt8Field":90,"uInt16Field":1234,"uInt32Field":56789012,"uInt64Field":"345678901234567890","float32Field":-1.2499999646475857e-10,"float64Field":345,"textField":"baz","dataField":[113,117,120],"structField":{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"nested","structField":{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"really nested","enumField":"foo","interfaceField":null},"enumField":"foo","interfaceField":null},"enumField":"baz","interfaceField":null,"voidList":[null,null,null],"boolList":[false,true,false,true,true],"int8List":[12,-34,-128,127],"int16List":[1234,-5678,-32768,32767],"int32List":[12345678,-90123456,-2147483648,2147483647],"int64List":["123456789012345","-678901234567890","-9223372036854775808","9223372036854775807"],"uInt8List":[12,34,0,255],"uInt16List":[1234,5678,0,65535],"uInt32List":[12345678,90123456,0,4294967295],"uInt64List":["123456789012345","678901234567890","0","18446744073709551615"],"float32List":[0,1234567,9.9999999338158125e36,-9.9999999338158125e36,9.99999991097579e-38,-9.99999991097579e-38],"float64List":[0,123456789012345,1e306,-1e306,1e-306,-1e-306],"textList":["quux","corge","grault"],"dataList":[[103,97,114,112,108,121],[119,97,108,100,111],[102,114,101,100]],"structList":[{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"x structlist 1","enumField":"foo","interfaceField":null},{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"x structlist 2","enumField":"foo","interfaceField":null},{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"x structlist 3","enumField":"foo","interfaceField":null}],"enumList":["qux","bar","grault"]},"enumField":"corge","interfaceField":null,"voidList":[null,null,null,null,null,null],"boolList":[true,false,false,true],"int8List":[111,-111],"int16List":[11111,-11111],"int32List":[111111111,-111111111],"int64List":["1111111111111111111","-1111111111111111111"],"uInt8List":[111,222],"uInt16List":[33333,44444],"uInt32List":[3333333333],"uInt64List":["11111111111111111111"],"float32List":[5555.5,"Infinity","-Infinity","NaN"],"float64List":[7777.75,"Infinity","-Infinity","NaN"],"textList":["plugh","xyzzy","thud"],"dataList":[[111,111,112,115],[101,120,104,97,117,115,116,101,100],[114,102,99,51,48,57,50]],"structList":[{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"structlist 1","enumField":"foo","interfaceField":null},{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"structlist 2","enumField":"foo","interfaceField":null},{"voidField":null,"boolField":false,"int8Field":0,"int16Field":0,"int32Field":0,"int64Field":"0","uInt8Field":0,"uInt16Field":0,"uInt32Field":0,"uInt64Field":"0","float32Field":0,"float64Field":0,"textField":"structlist 3","enumField":"foo","interfaceField":null}],"enumList":["foo","garply"]}
diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.txt b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.txt
new file mode 100644
index 0000000..d738fb3
--- /dev/null
+++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.txt
@@ -0,0 +1 @@
+(voidField = void, boolField = true, int8Field = -123, int16Field = -12345, int32Field = -12345678, int64Field = -123456789012345, uInt8Field = 234, uInt16Field = 45678, uInt32Field = 3456789012, uInt64Field = 12345678901234567890, float32Field = 1234.5, float64Field = -1.23e47, textField = "foo", dataField = "bar", structField = (voidField = void, boolField = true, int8Field = -12, int16Field = 3456, int32Field = -78901234, int64Field = 56789012345678, uInt8Field = 90, uInt16Field = 1234, uInt32Field = 56789012, uInt64Field = 345678901234567890, float32Field = -1.25e-10, float64Field = 345, textField = "baz", dataField = "qux", structField = (voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "nested", structField = (voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "really nested", enumField = foo, interfaceField = void), enumField = foo, interfaceField = void), enumField = baz, interfaceField = void, voidList = [void, void, void], boolList = [false, true, false, true, true], int8List = [12, -34, -128, 127], int16List = [1234, -5678, -32768, 32767], int32List = [12345678, -90123456, -2147483648, 2147483647], int64List = [123456789012345, -678901234567890, -9223372036854775808, 9223372036854775807], uInt8List = [12, 34, 0, 255], uInt16List = [1234, 5678, 0, 65535], uInt32List = [12345678, 90123456, 0, 4294967295], uInt64List = [123456789012345, 678901234567890, 0, 18446744073709551615], float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37], float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306], textList = ["quux", "corge", "grault"], dataList = ["garply", "waldo", "fred"], structList = [(voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "x structlist 1", enumField = foo, interfaceField = void), (voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "x structlist 2", enumField = foo, interfaceField = void), (voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "x structlist 3", enumField = foo, interfaceField = void)], enumList = [qux, bar, grault]), enumField = corge, interfaceField = void, voidList = [void, void, void, void, void, void], boolList = [true, false, false, true], int8List = [111, -111], int16List = [11111, -11111], int32List = [111111111, -111111111], int64List = [1111111111111111111, -1111111111111111111], uInt8List = [111, 222], uInt16List = [33333, 44444], uInt32List = [3333333333], uInt64List = [11111111111111111111], float32List = [5555.5, inf, -inf, nan], float64List = [7777.75, inf, -inf, nan], textList = ["plugh", "xyzzy", "thud"], dataList = ["oops", "exhausted", "rfc3092"], structList = [(voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "structlist 1", enumField = foo, interfaceField = void), (voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "structlist 2", enumField = foo, interfaceField = void), (voidField = void, boolField = false, int8Field = 0, int16Field = 0, int32Field = 0, int64Field = 0, uInt8Field = 0, uInt16Field = 0, uInt32Field = 0, uInt64Field = 0, float32Field = 0, float64Field = 0, textField = "structlist 3", enumField = foo, interfaceField = void)], enumList = [foo, garply])
diff --git a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs
index c57b20b..7ef67e9 100644
--- a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs
+++ b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs
@@ -260,7 +260,14 @@
cu = cu.AddMembers(ns);
- return cu.NormalizeWhitespace(" ", Environment.NewLine).ToFullString();
+ string content = cu.NormalizeWhitespace(" ", Environment.NewLine).ToFullString();
+
+ if (!string.IsNullOrWhiteSpace(file.HeaderText))
+ {
+ content = file.HeaderText + content;
+ }
+
+ return content;
}
public IReadOnlyList Generate()
diff --git a/CapnpC.CSharp.Generator/Model/GenFile.cs b/CapnpC.CSharp.Generator/Model/GenFile.cs
index ac0c35d..468315e 100644
--- a/CapnpC.CSharp.Generator/Model/GenFile.cs
+++ b/CapnpC.CSharp.Generator/Model/GenFile.cs
@@ -14,6 +14,7 @@ namespace CapnpC.CSharp.Generator.Model
public bool? NullableEnable { get; set; }
public bool EmitNullableDirective { get; set; }
public bool EmitDomainClassesAndInterfaces { get; set; }
+ public string HeaderText { get; set; }
public SupportedAnnotations.TypeVisibility TypeVisibility { get; set; }
public IEnumerable NestedTypes { get => this.GetNestedTypes(); }
diff --git a/CapnpC.CSharp.Generator/Model/SchemaModel.cs b/CapnpC.CSharp.Generator/Model/SchemaModel.cs
index 8213ffd..2b75e7c 100644
--- a/CapnpC.CSharp.Generator/Model/SchemaModel.cs
+++ b/CapnpC.CSharp.Generator/Model/SchemaModel.cs
@@ -13,6 +13,7 @@ namespace CapnpC.CSharp.Generator.Model
readonly DefinitionManager _typeDefMgr = new DefinitionManager();
readonly Dictionary _id2node = new Dictionary();
+ readonly Dictionary _id2sourceInfo = new Dictionary();
public SchemaModel(Schema.CodeGeneratorRequest.Reader request)
{
@@ -51,6 +52,17 @@ namespace CapnpC.CSharp.Generator.Model
_id2node[node.Id] = node;
}
+ foreach (var reader in _request.SourceInfo)
+ {
+ var sourceInfo = new SourceInfo()
+ {
+ DocComment = reader.DocComment,
+ MemberDocComments = reader.Members.Select(m => m.DocComment).ToList()
+ };
+
+ _id2sourceInfo.Add(reader.Id, sourceInfo);
+ }
+
var requestedFiles = _request.RequestedFiles.ToDictionary(req => req.Id);
BuildPass1(requestedFiles);
BuildPass2(requestedFiles);
@@ -96,6 +108,10 @@ namespace CapnpC.CSharp.Generator.Model
file.EmitNullableDirective = GetEmitNullableDirective(node) ?? false;
file.EmitDomainClassesAndInterfaces = GetEmitDomainClassesAndInterfaces(node) ?? true;
file.TypeVisibility = GetTypeVisibility(node) ?? TypeVisibility.Public;
+ if (_id2sourceInfo.TryGetValue(node.Id, out var sourceInfo))
+ {
+ file.HeaderText = GetHeaderText(sourceInfo);
+ }
return ProcessNodePass1(id, name, state) as GenFile;
}
diff --git a/CapnpC.CSharp.Generator/Model/SourceInfo.cs b/CapnpC.CSharp.Generator/Model/SourceInfo.cs
new file mode 100644
index 0000000..28ac508
--- /dev/null
+++ b/CapnpC.CSharp.Generator/Model/SourceInfo.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace CapnpC.CSharp.Generator.Model
+{
+ class SourceInfo
+ {
+ public string DocComment { get; set; }
+ public IReadOnlyList MemberDocComments { get; set; }
+ }
+}
diff --git a/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs b/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs
index cd78387..5985170 100644
--- a/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs
+++ b/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
namespace CapnpC.CSharp.Generator.Model
@@ -130,5 +131,19 @@ namespace CapnpC.CSharp.Generator.Model
}
return null;
}
+
+ public static string GetHeaderText(SourceInfo sourceInfo)
+ {
+ if (sourceInfo.DocComment == null)
+ return null;
+
+ var lines = sourceInfo.DocComment
+ .Split('\n')
+ .Select(line => line.Trim())
+ .SkipWhile(line => !line.Equals("$$embed", StringComparison.OrdinalIgnoreCase))
+ .Skip(1);
+
+ return string.Join(Environment.NewLine, lines);
+ }
}
}
diff --git a/include/capnp/c++.capnp b/include/capnp/c++.capnp
new file mode 100644
index 0000000..2bda547
--- /dev/null
+++ b/include/capnp/c++.capnp
@@ -0,0 +1,26 @@
+# 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.
+
+@0xbdf87d7bb8304e81;
+$namespace("capnp::annotations");
+
+annotation namespace(file): Text;
+annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text;
diff --git a/scripts/regen-capnpbin.bat b/scripts/regen-capnpbin.bat
new file mode 100644
index 0000000..aa4d9bb
--- /dev/null
+++ b/scripts/regen-capnpbin.bat
@@ -0,0 +1,3 @@
+@echo off
+cd "%~dp0\..\CapnpC.CSharp.Generator.Tests\No Resources"
+for /f %%f in ('dir /b "*.capnp"') do capnp compile -o- %%f -I"..\..\include" > "..\Embedded Resources\%%f.bin"
\ No newline at end of file