Skip to content

Commit

Permalink
Improve JSON serialization and deserialization (#28)
Browse files Browse the repository at this point in the history
 - Make all service types JSON serializable, behind a json feature.
 - Fixes and improvements to serialization of some core types, including a special JSON variant for extension object bodies.
 - Custom serializer for enums as numbers.
 - More tests.
  • Loading branch information
einarmo authored Sep 30, 2024
1 parent f2bde96 commit 12b1514
Show file tree
Hide file tree
Showing 316 changed files with 3,574 additions and 1,225 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci_code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ jobs:
- name: Test with profiling data
run: cargo llvm-cov --workspace --exclude opcua-crypto --codecov --output-path codecov.json

- name: Run crypto tests
run: cargo test -p opcua-crypto

- name: Run core tests
run: cargo test -p opcua-core

- name: Upload lcov to codecov.io
uses: codecov/codecov-action@v4
with:
Expand Down
163 changes: 159 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ futures = "0.3"
hashbrown = "0.14.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
serde_with = "3.9.0"
serde_yaml = "0.9"
log = "0.4"
regex = "1.7"
Expand Down
6 changes: 4 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ server = ["opcua-server", "opcua-nodes", "generated-address-space", "discovery-s
client = ["opcua-client"]
# Console logging just installs a logger that writes out to the screen, useful for general logging
console-logging = ["env_logger"]
# The json feature adds serialize/deserialize to all OPC-UA types.
json = ["opcua-types/json"]
# Includes all the code to populate the address space with the default node set. This is something that embedded
# systems may or may not require.
generated-address-space = ["opcua-server/generated-address-space"]
Expand Down Expand Up @@ -58,5 +60,5 @@ tempdir = "0.3"
tokio = { workspace = true }
tokio-util = { workspace = true }

# Include console-logging when building tests
opcua = { path = ".", features = ["console-logging"] }
# Include console-logging and json when building tests
opcua = { path = ".", features = ["console-logging", "json"] }
8 changes: 3 additions & 5 deletions opcua-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use opcua_xml::load_nodeset2_file;
use serde::{Deserialize, Serialize};
use syn::File;
pub use types::{
base_ignored_types, base_json_serialized_types, base_native_type_mappings,
basic_types_import_map, BsdTypeLoader, CodeGenItemConfig, GeneratedItem, ItemDefinition,
LoadedType, LoadedTypes, StructureField, StructureFieldType, StructuredType,
base_ignored_types, base_native_type_mappings, basic_types_import_map, BsdTypeLoader,
CodeGenItemConfig, GeneratedItem, ItemDefinition, LoadedType, LoadedTypes, StructureField,
StructureFieldType, StructuredType,
};
use types::{generate_types, ExternalType};
pub use utils::{create_module_file, GeneratedOutput};
Expand Down Expand Up @@ -165,8 +165,6 @@ pub struct TypeCodeGenTarget {
#[serde(default)]
pub ignore: Vec<String>,
#[serde(default)]
pub json_serialized_types: Vec<String>,
#[serde(default)]
pub types_import_map: HashMap<String, ExternalType>,
#[serde(default)]
pub default_excluded: HashSet<String>,
Expand Down
34 changes: 0 additions & 34 deletions opcua-codegen/src/types/base_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,40 +95,6 @@ pub fn basic_types_import_map() -> HashMap<String, ExternalType> {
.collect()
}

pub fn base_json_serialized_types() -> HashSet<String> {
[
"ReadValueId",
"DataChangeFilter",
"EventFilter",
"SimpleAttributeOperand",
"ContentFilter",
"ContentFilterElement",
"MonitoredItemNotification",
"ServerDiagnosticsSummaryDataType",
"EventFieldList",
"DataChangeTrigger",
"FilterOperator",
"TimestampsToReturn",
"MonitoringMode",
"ConfigurationVersionDataType",
"DataSetMetaDataType",
"StructureDescription",
"EnumDescription",
"SimpleTypeDescription",
"StructureDefinition",
"EnumDefinition",
"FieldMetaData",
"KeyValuePair",
"DataSetFieldFlags",
"StructureType",
"StructureField",
"EnumField",
]
.into_iter()
.map(|v| v.to_owned())
.collect()
}

pub fn base_native_type_mappings() -> HashMap<String, String> {
[
("String", "UAString"),
Expand Down
Loading

0 comments on commit 12b1514

Please sign in to comment.