-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(codecs):
LengthDelimitedEncoder
fix last message framing (#22536)
* fix(sink encoding): ensure last/only msg encoded Signed-off-by: callum-ryan <19956159+callum-ryan@users.noreply.github.com> * fix: readme newline Signed-off-by: callum-ryan <19956159+callum-ryan@users.noreply.github.com> * chore: add changelog entry Signed-off-by: callum-ryan <19956159+callum-ryan@users.noreply.github.com> * fix: use CARGO_MANIFEST_DIR for test data path Signed-off-by: callum-ryan <19956159+callum-ryan@users.noreply.github.com> --------- Signed-off-by: callum-ryan <19956159+callum-ryan@users.noreply.github.com> Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
- Loading branch information
1 parent
cba85ca
commit 7650fa2
Showing
9 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelog.d/22536_last_message_length_encoding_framing.fix.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix an issue where using the LengthDelimitedEncoder, the last or only message is not correctly framed. | ||
|
||
authors: callum-ryan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/ | ||
test_proto_pb2.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
generate-desc: | ||
protoc -I=. -o test_proto.desc test_proto.proto | ||
|
||
generate-pb2: | ||
@protoc --python_out=. test_proto.proto | ||
|
||
check-protobuf: | ||
@python3 -c "import google.protobuf" 2>/dev/null || (echo 'protobuf is NOT installed in python3 environment' && exit 1) | ||
|
||
generate-test-payload: check-protobuf generate-pb2 | ||
@python3 serialize.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Protobuf files for encoding tests | ||
|
||
These proto files are used in [src/sinks/util/encoding.rs](../../../src/sinks/util/encoding.rs) tests to confirm framing works as intended | ||
|
||
### Regenerate | ||
|
||
There is a Makefile to ease the process of compiling the test binary file. It requires `protobuf` to be installed in a python3 environment. | ||
|
||
* `make generate-test-payload` | ||
* this script will generate the required *_pb2.py and serialise a test message. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import test_proto_pb2 | ||
|
||
out_path = "test_proto.pb" | ||
|
||
user1 = test_proto_pb2.User( | ||
id="123", | ||
name="Alice", | ||
age=30, | ||
emails=["alice@example.com", "alice@work.com"] | ||
) | ||
|
||
single_binary_data = user1.SerializeToString() | ||
with open(out_path, "wb") as f: | ||
f.write(single_binary_data) | ||
|
||
print(f"Output: {out_path} size = {len(single_binary_data)} bytes") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
| | ||
test_proto.proto | ||
test_proto"T | ||
User | ||
id ( Rid | ||
name ( Rname | ||
age (Rage | ||
emails ( Remailsbproto3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
123Alice"alice@example.com"alice@work.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
package test_proto; | ||
|
||
// Define a User message | ||
message User { | ||
string id = 1; | ||
string name = 2; | ||
int32 age = 3; | ||
repeated string emails = 4; | ||
} |