|
| 1 | +/* |
| 2 | + This file is part of the Arduino_RPClite library. |
| 3 | +
|
| 4 | + Copyright (c) 2025 Arduino SA |
| 5 | +
|
| 6 | + This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + |
| 10 | +*/ |
| 11 | + |
1 | 12 | #include <Arduino_RPClite.h> |
2 | 13 | #include "DummyTransport.h" |
| 14 | +#include "decoder_tester.h" |
3 | 15 |
|
4 | 16 | // Shorthand |
5 | 17 | MsgPack::Packer packer; |
@@ -36,6 +48,35 @@ void runDecoderTest(const char* label) { |
36 | 48 | Serial.println("-- Done --\n"); |
37 | 49 | } |
38 | 50 |
|
| 51 | +void runDecoderConsumeTest(const char* label, size_t second_packet_sz) { |
| 52 | + Serial.println(label); |
| 53 | + |
| 54 | + print_buf(); |
| 55 | + DummyTransport dummy_transport(packer.data(), packer.size()); |
| 56 | + RpcDecoder<> decoder(dummy_transport); |
| 57 | + |
| 58 | + DecoderTester dt(decoder); |
| 59 | + |
| 60 | + while (!decoder.packet_incoming()) { |
| 61 | + Serial.println("Packet not ready"); |
| 62 | + decoder.decode(); |
| 63 | + delay(50); |
| 64 | + } |
| 65 | + |
| 66 | + size_t pack_size = decoder.get_packet_size(); |
| 67 | + Serial.print("1st Packet size: "); |
| 68 | + Serial.println(pack_size); |
| 69 | + |
| 70 | + Serial.print("Consuming 2nd packet of given size: "); |
| 71 | + Serial.println(second_packet_sz); |
| 72 | + |
| 73 | + dt.crop_bytes(second_packet_sz, pack_size); |
| 74 | + |
| 75 | + dt.print_raw_buf(); |
| 76 | + |
| 77 | + Serial.println("-- Done --\n"); |
| 78 | +} |
| 79 | + |
39 | 80 | void testNestedArrayRequest() { |
40 | 81 | packer.clear(); |
41 | 82 | MsgPack::arr_size_t outer_arr(3); |
@@ -120,6 +161,9 @@ void testMultipleRpcPackets() { |
120 | 161 | packer.serialize(req_sz, 0, 2, "echo", par_sz, "Hello", true); |
121 | 162 |
|
122 | 163 | runDecoderTest("== Test: Multiple RPCs in Buffer =="); |
| 164 | + |
| 165 | + runDecoderConsumeTest("== Test: Mid-buffer consume ==", 5); |
| 166 | + |
123 | 167 | } |
124 | 168 |
|
125 | 169 | // Binary parameter (e.g., binary blob) |
@@ -170,6 +214,8 @@ void testCombinedComplexBuffer() { |
170 | 214 |
|
171 | 215 | void setup() { |
172 | 216 | Serial.begin(115200); |
| 217 | + while(!Serial); |
| 218 | + |
173 | 219 | delay(1000); |
174 | 220 | Serial.println("=== RPC Decoder Nested Tests ==="); |
175 | 221 |
|
|
0 commit comments