Skip to content

Commit

Permalink
Prefer reparsing to prepending byte
Browse files Browse the repository at this point in the history
I must've missed the point of this section before, oops. I'd prefer not
to have the `start` var, but it's necessary because I can't subtract a
number from the iterator right now:

zeek/spicy#1920
  • Loading branch information
evantypanski committed Nov 8, 2024
1 parent f06caf6 commit 29c044d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions analyzer/resp.spicy
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ public type ServerMessages = unit {

public type ClientData = unit {
%synchronize-after = b"\x0d\x0a";

on %init() { self.start = self.input(); }

# Clients can only be an array or inline
ty: uint8 &convert=DataType($$);
ty: uint8 &convert=DataType($$) {
if (self.ty != DataType::ARRAY) {
# This is inline, so we need to reparse `ty`
self.set_input(self.start);
}
}
if (self.ty == DataType::ARRAY) {
multibulk: Array;
} else {
# HACK: If the type isn'tan array, this is just some random unserialized
# string until \r\n - do this by prepending the type to the remaining bytes.
# Formally in Redis code, that's an "inline command."
#
# As an extra point, this is handled in redis in `processInlineBuffer`,
# which has a hardcoded limit of 1024*64. That seems too big. We'll do 1024.
inline: RedisBytes &convert=(pack(cast<uint8>(self.ty), spicy::ByteOrder::Network) + $$) &max-size=1024;
inline: RedisBytes &max-size=1024;
};

var start: iterator<stream>;
var command: Redis::Command;

on %done {
Expand Down

0 comments on commit 29c044d

Please sign in to comment.