- Server-057: extend []-suffix normalization to AddItemBulk/AddBufferedItem so bulk-added array tags bind write-capable handles (authz check, worker bind, and registration kept consistent); update gateway.md + client READMEs. Tests: AddItemBulk/AddBufferedItem wiring. - Server-058: assert []-fallback-resolved bare array names are still denied when out of read/write scope and that MaxWriteClassification is enforced on suffixed array registrations. - Contracts-023/024/025: round-trip + field-19 descriptor pin for MxSparseArray; document MxSparseArray in docs/Contracts.md; enumerate it in the protocol-version-3 test summary. - Tests-040: add wiring tests for the six uncovered sparse-write arms (WriteSecured, Write2, WriteSecured2, Write2Bulk, WriteSecuredBulk, WriteSecured2Bulk). dotnet build + targeted tests green (184 passed).
6.8 KiB
Protobuf Contracts
The contracts project contains the public gRPC API and the gateway-to-worker
IPC messages. The .proto files are the source of truth; generated C# files are
recreated by the contracts project build.
Files
src/ZB.MOM.WW.MxGateway.Contracts/Protos/mxaccess_gateway.proto defines the public
MxAccessGateway gRPC service, command payloads, command replies, event DTOs,
MxValue, MxArray, MxSparseArray, and MxStatusProxy.
MxValue carries a kind oneof with arms for all scalar and array types. One
arm is sparse_array_value = 19 (field number 19), which carries an
MxSparseArray. MxSparseArray is a write-only value type: the gateway accepts
it on every write variant (Write, Write2, WriteSecured, WriteSecured2,
and the corresponding *BulkEntry shapes), expands it into a full,
default-filled MxArray before forwarding to the worker, and rejects it on
read or event paths. The worker never receives or produces it.
MxSparseArray has three fields: element_data_type (1, the MxDataType of
every element), total_length (2, the length of the expanded full array), and
elements (3, repeated MxSparseElement). Each MxSparseElement has index
(1, zero-based position in the expanded array) and value (2, a scalar
MxValue). Indices not mentioned in elements take the element type's default
value — they are reset, not preserved. See gateway.md section
"MxSparseArray — default-fill partial array writes" for the expansion rules,
validation constraints, and the scope requirements per write variant.
The public command model includes bulk subscription command kinds for
AddItemBulk, AdviseItemBulk, RemoveItemBulk, UnAdviseItemBulk,
SubscribeBulk, and UnsubscribeBulk. These commands are normal unary
Invoke payloads. They do not add separate gRPC methods, and they return a
BulkSubscribeReply containing per-item SubscribeResult records with
ServerHandle, TagAddress, ItemHandle, WasSuccessful, and
ErrorMessage.
The gateway forwards each bulk command as one worker command. The worker runs
the corresponding MXAccess AddItem, Advise, UnAdvise, and RemoveItem
calls sequentially on the session STA and preserves input order in the result
list.
The command model also includes bulk write/read command kinds:
WriteBulk, Write2Bulk, WriteSecuredBulk, WriteSecured2Bulk, and
ReadBulk. They are unary Invoke payloads on the same MxAccessGateway
surface (not separate gRPC methods) and exist so a caller can submit one list
of items per round trip while preserving MXAccess parity per entry.
-
WriteBulkCommand/Write2BulkCommand/WriteSecuredBulkCommand/WriteSecured2BulkCommandeach carry aserver_handleand arepeatedlist of entries (WriteBulkEntry,Write2BulkEntry,WriteSecuredBulkEntry,WriteSecured2BulkEntry). Each entry mirrors the single-item command shape —item_handle+value(+timestamp_valueon the*2variants, +current_user_id/verifier_user_idon the secured variants). All four replies useBulkWriteReply, which carriesrepeated BulkWriteResult. ABulkWriteResulthasserver_handle,item_handle,was_successful,optional int32 hresult,repeated MxStatusProxy statuses, anderror_message. Per-entry failures populateerror_message+hresultand never raise — callers iterate and inspect each entry. The credential-sensitive redaction rules forWriteSecured/WriteSecured2apply to everyvalueinsideWriteSecuredBulkEntryandWriteSecured2BulkEntry. -
ReadBulkCommandcarriesserver_handle,repeated string tag_addresses, anduint32 timeout_ms(0 means use the gateway-configured default). The reply isBulkReadReplycarryingrepeated BulkReadResult. ABulkReadResulthasserver_handle,tag_address,item_handle,was_successful,was_cached,value,quality,source_timestamp,repeated MxStatusProxy statuses, anderror_message. MXAccess has no synchronousRead, soReadBulkis dual-mode per entry: when a tag is already advised in the session the worker returns the cachedOnDataChangepayload without touching the subscription (was_cached = true); otherwise the worker takes a fullAddItem+Advise+ wait-for-first-OnDataChange+UnAdvise+RemoveItemsnapshot lifecycle and returns the result (was_cached = false). The asymmetry thatBulkReadResulthas nohresultfield is intentional —ReadBulkoutcomes are timeout / cache / lifecycle states rather than MXAccess COM return codes.
See gateway.md for the full cached-vs-snapshot ReadBulk lifecycle and the
per-command scope requirements, and docs/DesignDecisions.md "Bulk Command
Family" for the rationale behind the per-entry result shape (independent
success tracking, input-order preservation, no partial-failure exceptions).
src/ZB.MOM.WW.MxGateway.Contracts/Protos/mxaccess_worker.proto defines the named-pipe
worker IPC envelope and control messages. It imports
mxaccess_gateway.proto so the worker and gateway use the same command, reply,
event, value, and status shapes.
src/ZB.MOM.WW.MxGateway.Contracts/Protos/galaxy_repository.proto defines the
GalaxyRepository service used by clients to browse the Galaxy Repository
(deployed object hierarchy and dynamic attributes). The service is metadata-
only and does not share types with mxaccess_gateway.proto. See
Galaxy Repository Browse for the RPC catalog and
behavior.
Generated C# output is written to src/ZB.MOM.WW.MxGateway.Contracts/Generated/. Do not
hand-edit generated files.
Client generation inputs are published through
clients/proto/proto-inputs.json and the descriptor set under
clients/proto/descriptors/. See
Client Proto Generation for language-specific
generation inputs, output directories, and golden protobuf JSON fixtures.
Generation
Run the contracts build to regenerate C# protobuf and gRPC code:
dotnet build src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj
Run the focused contract tests after changing either .proto file:
dotnet test src/ZB.MOM.WW.MxGateway.Tests/ZB.MOM.WW.MxGateway.Tests.csproj --filter ProtobufContractRoundTripTests
The full solution build also regenerates the C# contracts before compiling gateway and test projects:
dotnet build src/ZB.MOM.WW.MxGateway.slnx
Regenerate the client descriptor after changing either .proto file:
powershell -ExecutionPolicy Bypass -File scripts/publish-client-proto-inputs.ps1