Appreciate the reply Kenton, that got me to the solution I was looking for:
std::string type =
person_schema->getNested("type").asConst().as<capnp::Text>().cStr();
And will do on avoiding kj::_. Thanks again!
On Wednesday, June 8, 2022 at 11:13:56 AM UTC-7 [email protected] wrote:
> Hi Daniel,
>
> I think you can do:
>
> capnp::ConstSchema type =
> schema.getNested("Person").getNested("type").asConst();
>
> But it's been a long time since I touched this.
>
> By the way, please do not use stuff in kj::_ directly, that is a private
> namespace. To read a Maybe, use KJ_IF_MAYBE, KJ_ASSERT_NONNULL,
> KJ_UNWRAP_OR, etc.
>
> -Kenton
>
> On Wed, Jun 8, 2022 at 12:33 PM Daniel Koohmarey <
> [email protected]> wrote:
>
>> Given the following dummy schema test.capnp:
>> struct Person {
>> const type :Text = "person.type.example";
>> version @0 :UInt32;
>> name @1 :Text;
>> }
>>
>> At runtime, how can we read the default const value from a schema struct
>> (i.e the "person.type.example" above? (type is not considered a field
>> within the struct, but it does appear as a node in the proto):
>> std::string schema_filename = "test.capnp"; kj::ArrayPtr<const
>> kj::StringPtr> import_paths;
>> capnp::SchemaParser parser;
>> capnp::ParsedSchema schema = parser.parseDiskFile(
>> schema_filename.c_str(),
>>
>> schema_filename.c_str(), import_paths);
>> auto person_maybe = schema.findNested("Person");
>> auto* person_schema = kj::_::readMaybe(person_maybe);
>>
>> // how can I read "person.type.example" out of the Person struct?
>>
>> Any guidance on the matter is appreciated, thanks!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Cap'n Proto" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/capnproto/389bc2ea-3279-4ddc-b8cc-f554d636767fn%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/capnproto/389bc2ea-3279-4ddc-b8cc-f554d636767fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/capnproto/43e19d86-1979-4619-9e96-d8659acc07c5n%40googlegroups.com.