Skip to content

Commit 74f6c85

Browse files
thirtytwobitsScott Dixon
andauthored
Fix for #378 (#390)
Adding HasFixedPortID = false for types that do not have a fixed port ID Co-authored-by: Scott Dixon <thirtytwobits@Scotts-MacBook-Pro.local>
1 parent d89ce9f commit 74f6c85

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ nunavut_out
5858
.hypothesis
5959

6060
.ropeproject
61+
62+
#clangd
63+
.cache

src/nunavut/lang/cpp/templates/ServiceType.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ struct {{service_name}}
2525
struct _traits_
2626
{
2727
_traits_() = delete;
28+
{%- if T.has_fixed_port_id %}
29+
static constexpr bool HasFixedPortID = true;
30+
static constexpr {{ typename_unsigned_port }} FixedPortId = {{ T.fixed_port_id }}U;
31+
{%- else %}
32+
static constexpr bool HasFixedPortID = false;
33+
{%- endif %}
2834

2935
static constexpr bool IsServiceType = true;
3036
static constexpr bool IsService = true;
3137
static constexpr bool IsRequest = false;
3238
static constexpr bool IsResponse = false;
39+
40+
static constexpr const char* FullNameAndVersion() { return "{{ T }}"; }
3341
};
3442
};
3543

verification/cpp/suite/test_constant.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const bool regulated::basics::Service::Response_0_1::_traits_::IsResponse;
3030
const bool regulated::basics::Service::Response_0_1::_traits_::IsServiceType;
3131
const bool regulated::basics::Service_0_1::_traits_::IsService;
3232
const bool regulated::basics::Service_0_1::_traits_::IsServiceType;
33+
const bool regulated::basics::Service_0_1::_traits_::HasFixedPortID;
34+
const std::uint16_t regulated::basics::Service_0_1::_traits_::FixedPortId;
3335

3436
const std::size_t regulated::basics::Struct__0_1::_traits_::ArrayCapacity::i10_4;
3537
const std::size_t regulated::basics::Struct__0_1::_traits_::ArrayCapacity::f16_le2;
@@ -101,6 +103,10 @@ TEST(ConstantTests, Service)
101103
// Type parameters.
102104
EXPECT_TRUE(regulated::basics::Service_0_1::_traits_::IsService);
103105
EXPECT_TRUE(regulated::basics::Service_0_1::_traits_::IsServiceType);
106+
EXPECT_TRUE(regulated::basics::Service_0_1::_traits_::HasFixedPortID);
107+
EXPECT_THAT(regulated::basics::Service_0_1::_traits_::FixedPortId, 300);
108+
EXPECT_THAT(regulated::basics::Service_0_1::_traits_::FullNameAndVersion(),
109+
StrEq("regulated.basics.Service.0.1"));
104110

105111
EXPECT_FALSE(regulated::basics::Service::Request_0_1::_traits_::IsService);
106112
EXPECT_TRUE(regulated::basics::Service::Request_0_1::_traits_::IsServiceType);

verification/cpp/suite/test_serialization.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ static_assert(
2929
regulated::basics::Service_0_1::_traits_::IsServiceType,
3030
"Service is a service type");
3131

32+
static_assert(
33+
regulated::basics::Service_0_1::_traits_::HasFixedPortID,
34+
"Service has a fixed port ID");
35+
3236
static_assert(
3337
not regulated::basics::Service_0_1::Request::_traits_::IsService,
3438
"Request is not a service");

0 commit comments

Comments
 (0)