Commit d0ab7eb
authored
WAMP Flatbuffers serialization test coverage; WAMP message classes refactoring (#1773)
Add complete FlatBuffers serialization support for all WAMP messages
This PR implements full FlatBuffers serialization/deserialization support
for all 23 WAMP message types, achieving 100% test coverage with zero
skipped tests.
## Overview
FlatBuffers provides zero-copy, high-performance serialization that's
particularly valuable for:
- High-throughput WAMP applications
- Low-latency message passing
- Embedded systems with memory constraints
- Cross-language interoperability
## Implementation
### Message Classes Refactored
All 23 WAMP message classes now implement:
- `build(builder, serializer)`: Serialize to FlatBuffers format
- `cast(buf)`: Deserialize from FlatBuffers bytes
- Lazy deserialization via `from_fbs` parameter
- Properties that defer FlatBuffers access until needed
### Categories Covered
**Category 1 (Neither Payload nor Forwarding) - 13 messages:**
- Session Lifecycle: Hello, Welcome, Abort, Challenge, Authenticate, Goodbye
- PubSub: Subscribe, Subscribed, Unsubscribe, Unsubscribed, Published
- RPC: Register, Registered, Unregister, Unregistered
**Category 3 (Forwarding Only) - 3 messages:**
- Cancel, Interrupt, EventReceived
**Category 4 (Both Payload and Forwarding) - 7 messages:**
- Error, Event, Publish, Call, Result, Invocation, Yield
### Zero-Copy Memory Access
Custom wrapper classes provide zero-copy access to message payloads:
- `ArgsAsBytes()`, `KwargsAsBytes()` for arguments
- `PayloadAsBytes()` for binary payloads
- `EncKeyAsBytes()` for encryption keys
Returns `memoryview` objects for direct buffer access without copying.
### Test Infrastructure
- Generated FlatBuffers test vectors for all 23 message types
- Comprehensive test suite: 529 tests passing, 0 skipped
- Test coverage includes:
- Serialization to bytes
- Deserialization from bytes
- Round-trip integrity
- Cross-serializer preservation
- Edge cases and error handling
## Architecture
### Message Union Pattern
All messages follow consistent two-level structure:
1. Inner message table (e.g., `Hello`, `Publish`, `Call`)
2. Outer `Message` union wrapper with message type enum
This enables efficient message type discrimination during deserialization.
### Serializer Integration
- `FlatBuffersSerializer` added to `autobahn.wamp.serializer`
- Integrated into `MESSAGE_TYPE_MAP` for automatic routing
- Compatible with existing serializer infrastructure
- Test vector generator supports FlatBuffers format
## Test Results
529 passed, 0 skipped, 12 warnings in 1.70s
All warnings are deprecation notices for FlatBuffers API usage (cosmetic).
## Known Limitations
1. **Hello/Welcome Roles**: Complex nested role structures (ClientRoles,
RouterRoles) have simplified serialization. Basic fields work correctly,
but full feature negotiation details are deferred for future enhancement.
2. **Deprecation Warnings**: 12 warnings for `builder.EndVector(len(...))`
usage. Trivial to fix in follow-up but doesn't affect functionality.
## Breaking Changes
None. This is purely additive - existing serializers (JSON, MsgPack, CBOR,
UBJSON) are unchanged and fully compatible.
## Migration Guide
No migration required. FlatBuffers support is opt-in:
```python
from autobahn.wamp.serializer import FlatBuffersSerializer
serializer = FlatBuffersSerializer()
serialized_bytes, is_binary = serializer.serialize(msg)
Files Changed
- autobahn/wamp/message.py: Added build()/cast() methods to all message classes
- autobahn/wamp/message_fbs.py: Custom wrapper classes for zero-copy access
- autobahn/wamp/serializer.py: FlatBuffersSerializer and MESSAGE_TYPE_MAP
- examples/serdes/gen_flatbuffers_testvectors.py: Test vector generator
- wamp-proto submodule: FlatBuffers test vectors for all message types
Related
- Fixes #1771
- Implements FlatBuffers serialization requested in community discussions
- Foundation for future high-performance WAMP router work
---
Note: This work was completed with AI assistance (Claude Code).1 parent c67ed62 commit d0ab7eb
125 files changed
Lines changed: 8464 additions & 4603 deletions
File tree
- .audit
- .github/workflows
- autobahn
- asyncio
- nvx
- test
- twisted
- wamp
- flatbuffers
- gen
- schema
- wamp
- proto
- websocket
- docs
- wamp
- examples
- benchmarks/serialization
- serdes
- tests
- flatbuffers
- reflection
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
70 | | - | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
| 79 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | | - | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | | - | |
| 70 | + | |
68 | 71 | | |
69 | 72 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | | - | |
| 79 | + | |
75 | 80 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
80 | 87 | | |
81 | | - | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | | - | |
| 91 | + | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
89 | 96 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
94 | 103 | | |
95 | | - | |
| 104 | + | |
96 | 105 | | |
97 | | - | |
| 106 | + | |
98 | 107 | | |
99 | 108 | | |
100 | 109 | | |
101 | | - | |
| 110 | + | |
102 | 111 | | |
103 | 112 | | |
104 | | - | |
| 113 | + | |
105 | 114 | | |
106 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
107 | 118 | | |
108 | 119 | | |
109 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
110 | 123 | | |
111 | | - | |
112 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
113 | 130 | | |
114 | 131 | | |
115 | 132 | | |
116 | 133 | | |
117 | | - | |
| 134 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
| 182 | + | |
184 | 183 | | |
185 | 184 | | |
186 | 185 | | |
| |||
- .ai+1-1
- testsuite/README.md+45-39
- testsuite/gen_validation_samples.py+91-4
- testsuite/singlemessage/advanced/cancel.json+47
- testsuite/singlemessage/advanced/eventreceived.json+46
- testsuite/singlemessage/advanced/interrupt.json+47
- testsuite/singlemessage/basic/abort.json+53
- testsuite/singlemessage/basic/authenticate.json+53
- testsuite/singlemessage/basic/call.json+69
- testsuite/singlemessage/basic/challenge.json+53
- testsuite/singlemessage/basic/error.json+55
- testsuite/singlemessage/basic/event.json+315-66
- testsuite/singlemessage/basic/goodbye.json+53
- testsuite/singlemessage/basic/hello.json+50
- testsuite/singlemessage/basic/invocation.json+54
- testsuite/singlemessage/basic/publish.json+358-38
- testsuite/singlemessage/basic/published.json+53
- testsuite/singlemessage/basic/register.json+65
- testsuite/singlemessage/basic/registered.json+53
- testsuite/singlemessage/basic/result.json+68
- testsuite/singlemessage/basic/subscribe.json+208
- testsuite/singlemessage/basic/subscribed.json+53
- testsuite/singlemessage/basic/unregister.json+47
- testsuite/singlemessage/basic/unregistered.json+52
- testsuite/singlemessage/basic/unsubscribe.json+53
- testsuite/singlemessage/basic/unsubscribed.json+52
- testsuite/singlemessage/basic/welcome.json+50
- testsuite/singlemessage/basic/yield.json+53
0 commit comments