Skip to content

Commit

Permalink
Merge branch 'master' into async-server
Browse files Browse the repository at this point in the history
  • Loading branch information
einarmo committed Jul 29, 2024
2 parents 8d202e4 + bf23be4 commit 192e7af
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 50 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci_verify_clean_node_ids.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI verify cleanly generated node ids
'on':
workflow_call: null
jobs:
node_ids:
runs-on: ubuntu-latest
steps:
- name: Checkout (GitHub)
uses: actions/checkout@v4
- name: Install dependencies
run: npm install
working-directory: tools/schema/
- name: Regenerate node ids
run: node gen_node_ids
working-directory: tools/schema/
- name: Format generated code
run: rustfmt lib/src/types/node_ids.rs
- name: Verify generated code matches committed code
run: git status --porcelain
19 changes: 19 additions & 0 deletions .github/workflows/ci_verify_clean_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI verify cleanly generated types
'on':
workflow_call: null
jobs:
types:
runs-on: ubuntu-latest
steps:
- name: Checkout (GitHub)
uses: actions/checkout@v4
- name: Install dependencies
run: npm install
working-directory: tools/schema/
- name: Regenerate types
run: node gen_types
working-directory: tools/schema/
- name: Format generated code
run: rustfmt lib/src/types/service_types/mod.rs
- name: Verify generated code matches committed code
run: git status --porcelain
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ jobs:
verify-clean-address-space:
uses: ./.github/workflows/ci_verify_clean_address_space.yml

verify-clean-node-ids:
uses: ./.github/workflows/ci_verify_clean_node_ids.yml

verify-clean-supported-message:
uses: ./.github/workflows/ci_verify_clean_supported_message.yml

verify-clean-types:
uses: ./.github/workflows/ci_verify_clean_types.yml

verify-code-formatting:
uses: ./.github/workflows/ci_format_code.yml
15 changes: 11 additions & 4 deletions lib/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions lib/src/client/session/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ impl SessionConnector {
}
};

drop(activate_fut);

Ok((event_loop, id))
}

Expand Down
33 changes: 2 additions & 31 deletions lib/src/types/service_types/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use crate::types::{
enums::DeadbandType, AnonymousIdentityToken, ApplicationDescription, ApplicationType,
Argument, CallMethodRequest, DataChangeFilter, DataChangeTrigger, DataSetFieldFlags,
EndpointDescription, MessageSecurityMode, MonitoredItemCreateRequest, MonitoringMode,
MonitoringParameters, ReadValueId, ServerDiagnosticsSummaryDataType,
ServiceCounterDataType, ServiceFault, SignatureData, UserNameIdentityToken,
UserTokenPolicy, UserTokenType,
MonitoringParameters, ReadValueId, ServiceCounterDataType, ServiceFault, SignatureData,
UserNameIdentityToken, UserTokenPolicy, UserTokenType,
},
status_code::StatusCode,
string::UAString,
Expand Down Expand Up @@ -345,25 +344,6 @@ impl Into<CallMethodRequest> for (NodeId, NodeId, Option<Vec<Variant>>) {
}
}

impl Default for ServerDiagnosticsSummaryDataType {
fn default() -> Self {
ServerDiagnosticsSummaryDataType {
server_view_count: 0,
current_session_count: 0,
cumulated_session_count: 0,
security_rejected_session_count: 0,
rejected_session_count: 0,
session_timeout_count: 0,
session_abort_count: 0,
current_subscription_count: 0,
cumulated_subscription_count: 0,
publishing_interval_count: 0,
security_rejected_requests_count: 0,
rejected_requests_count: 0,
}
}
}

impl<'a> From<&'a str> for EndpointDescription {
fn from(v: &'a str) -> Self {
EndpointDescription::from((
Expand Down Expand Up @@ -476,15 +456,6 @@ impl From<(&str, DataTypeId)> for Argument {
}
}

impl Default for ServiceCounterDataType {
fn default() -> Self {
Self {
total_count: 0,
error_count: 0,
}
}
}

impl ServiceCounterDataType {
pub fn success(&mut self) {
self.total_count += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::types::{
};
use std::io::{Read, Write};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
#[serde(rename_all = "PascalCase")]
pub struct ServerDiagnosticsSummaryDataType {
pub server_view_count: u32,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/types/service_types/service_counter_data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::types::{
};
use std::io::{Read, Write};

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ServiceCounterDataType {
pub total_count: u32,
pub error_count: u32,
Expand Down
9 changes: 2 additions & 7 deletions lib/src/types/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use crate::types::{
///
/// As variants may be passed around a lot on the stack, Boxes are used for more complex types to
/// keep the size of this type down a bit, especially when used in arrays.
#[derive(PartialEq, Debug, Clone)]
#[derive(PartialEq, Debug, Clone, Default)]
pub enum Variant {
/// Empty type has no value. It is equivalent to a Null value (part 6 5.1.6)
#[default]
Empty,
/// Boolean
Boolean(bool),
Expand Down Expand Up @@ -685,12 +686,6 @@ impl BinaryEncoder<Variant> for Variant {
}
}

impl Default for Variant {
fn default() -> Self {
Variant::Empty
}
}

/// This implementation is mainly for debugging / convenience purposes, to eliminate some of the
/// noise in common types from using the Debug trait.
impl fmt::Display for Variant {
Expand Down
4 changes: 0 additions & 4 deletions rustfmt.toml

This file was deleted.

7 changes: 7 additions & 0 deletions tools/schema/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ function makeImportLookupMap(import_map) {
return result;
}

// Types that will be marked as Default constructable
const DEFAULT_TYPES = ["ReadValueId", "ServerDiagnosticsSummaryDataType", "ServiceCounterDataType"];

// Types that will be marked as JSON serializable. Serialization is for pubsub, and debugging purposes
const JSON_SERIALIZED_TYPES = [
"ReadValueId", "DataChangeFilter", "EventFilter", "SimpleAttributeOperand", "ContentFilter",
Expand Down Expand Up @@ -623,12 +626,16 @@ use std::io::{Read, Write};
contents += `/// ${structured_type.documentation}\n`;
}

const is_default_constructable = _.includes(DEFAULT_TYPES, structured_type.name);
const is_json_serializable = _.includes(JSON_SERIALIZED_TYPES, structured_type.name);

let derivations = "Debug, Clone, PartialEq";
if (is_json_serializable) {
derivations += ", Serialize, Deserialize";
}
if (is_default_constructable) {
derivations += ", Default";
}
contents += `#[derive(${derivations})]
`;

Expand Down

0 comments on commit 192e7af

Please sign in to comment.