mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Stringify all Redis-RESP serialized data
This commit is contained in:
parent
a4ce682bc9
commit
b34d3ff2f0
5 changed files with 67 additions and 26 deletions
|
@ -430,36 +430,78 @@ function bulk_string_content(bulk: RESP::BulkString): bytes {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Returns the bytes string value of this, or Null if it cannot.
|
# Returns the bytes string value of this, or Null if it cannot.
|
||||||
function stringify(data: RESP::Data): optional<bytes> {
|
function stringify(data: RESP::Data): bytes {
|
||||||
if (data?.simple_error)
|
if (data?.simple_string)
|
||||||
return data.simple_error.content;
|
|
||||||
else if (data?.bulk_error)
|
|
||||||
return bulk_string_content(data.bulk_error);
|
|
||||||
else if (data?.simple_string)
|
|
||||||
return data.simple_string.content;
|
return data.simple_string.content;
|
||||||
|
else if (data?.simple_error)
|
||||||
|
return data.simple_error.content;
|
||||||
|
else if (data?.integer)
|
||||||
|
return data.integer.val;
|
||||||
else if (data?.bulk_string)
|
else if (data?.bulk_string)
|
||||||
return bulk_string_content(data.bulk_string);
|
return bulk_string_content(data.bulk_string);
|
||||||
else if (data?.verbatim_string)
|
else if (data?.array) {
|
||||||
return bulk_string_content(data.verbatim_string);
|
|
||||||
else if (data?.boolean)
|
|
||||||
return data.boolean.val ? b"T" : b"F";
|
|
||||||
else if (data?.array || data?.push) {
|
|
||||||
local res = b"[";
|
local res = b"[";
|
||||||
local first = True;
|
local first = True;
|
||||||
for (ele in data?.array ? data.array.elements : data.push.elements) {
|
for (ele in data.array.elements) {
|
||||||
if (!first)
|
if (!first)
|
||||||
res += b", ";
|
res += b", ";
|
||||||
local ele_stringified = stringify(ele);
|
res += stringify(ele);
|
||||||
if (!ele_stringified)
|
first = False;
|
||||||
return Null;
|
}
|
||||||
res += *ele_stringified;
|
res += b"]";
|
||||||
|
return res;
|
||||||
|
} else if (data?.null)
|
||||||
|
return b"null";
|
||||||
|
else if (data?.boolean)
|
||||||
|
return data.boolean.val ? b"T" : b"F";
|
||||||
|
else if (data?.double)
|
||||||
|
return data.double.val;
|
||||||
|
else if (data?.big_num)
|
||||||
|
return data.big_num.val;
|
||||||
|
else if (data?.bulk_error)
|
||||||
|
return bulk_string_content(data.bulk_error);
|
||||||
|
else if (data?.verbatim_string)
|
||||||
|
return bulk_string_content(data.verbatim_string);
|
||||||
|
else if (data?.map_) {
|
||||||
|
local res = b"{";
|
||||||
|
local first = True;
|
||||||
|
local i = 0;
|
||||||
|
while (i < data.map_.num_elements) {
|
||||||
|
if (!first)
|
||||||
|
res += b", ";
|
||||||
|
res += stringify(data.map_.raw_data[i]);
|
||||||
|
res += b": ";
|
||||||
|
res += stringify(data.map_.raw_data[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
first = False;
|
||||||
|
}
|
||||||
|
res += b"}";
|
||||||
|
return res;
|
||||||
|
} else if (data?.set_) {
|
||||||
|
local res = b"(";
|
||||||
|
local first = True;
|
||||||
|
for (ele in data.set_.elements) {
|
||||||
|
if (!first)
|
||||||
|
res += b", ";
|
||||||
|
res += stringify(ele);
|
||||||
|
first = False;
|
||||||
|
}
|
||||||
|
res += b")";
|
||||||
|
return res;
|
||||||
|
} else if (data?.push) {
|
||||||
|
local res = b"[";
|
||||||
|
local first = True;
|
||||||
|
for (ele in data.push.elements) {
|
||||||
|
if (!first)
|
||||||
|
res += b", ";
|
||||||
|
res += stringify(ele);
|
||||||
first = False;
|
first = False;
|
||||||
}
|
}
|
||||||
res += b"]";
|
res += b"]";
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Null;
|
throw "unknown RESP type";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Gets the server reply in a simpler form
|
# Gets the server reply in a simpler form
|
||||||
|
|
|
@ -149,7 +149,7 @@ type SimpleString = unit(is_error: bool) {
|
||||||
};
|
};
|
||||||
|
|
||||||
type Integer = unit {
|
type Integer = unit {
|
||||||
int: RedisBytes &convert=$$.to_int(10);
|
val: RedisBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
type BulkString = unit(is_error: bool) {
|
type BulkString = unit(is_error: bool) {
|
||||||
|
@ -178,11 +178,10 @@ type Boolean = unit {
|
||||||
};
|
};
|
||||||
|
|
||||||
type Double = unit {
|
type Double = unit {
|
||||||
val: RedisBytes &convert=$$.to_real();
|
val: RedisBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
type BigNum = unit {
|
type BigNum = unit {
|
||||||
# Big num can be very big so leave it in bytes.
|
|
||||||
val: RedisBytes;
|
val: RedisBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
Got published data!, [value=<uninitialized>]
|
Got published data!, [value=[subscribe, Foo, 1]]
|
||||||
Got published data!, [value=<uninitialized>]
|
Got published data!, [value=[psubscribe, F*, 2]]
|
||||||
Got published data!, [value=[message, Foo, Hi:)]]
|
Got published data!, [value=[message, Foo, Hi:)]]
|
||||||
Got published data!, [value=[pmessage, F*, Foo, Hi:)]]
|
Got published data!, [value=[pmessage, F*, Foo, Hi:)]]
|
||||||
Got published data!, [value=[pmessage, F*, Foobar, Hello!]]
|
Got published data!, [value=[pmessage, F*, Foobar, Hello!]]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
Got published data!, [value=<uninitialized>]
|
Got published data!, [value=[subscribe, Foo, 1]]
|
||||||
Got published data!, [value=<uninitialized>]
|
Got published data!, [value=[psubscribe, F*, 2]]
|
||||||
Got published data!, [value=[message, Foo, Hi there :)]]
|
Got published data!, [value=[message, Foo, Hi there :)]]
|
||||||
Got published data!, [value=[pmessage, F*, Foo, Hi there :)]]
|
Got published data!, [value=[pmessage, F*, Foo, Hi there :)]]
|
||||||
Got published data!, [value=[pmessage, F*, FeeFooFiiFum, Hello! :)]]
|
Got published data!, [value=[pmessage, F*, FeeFooFiiFum, Hello! :)]]
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#open XXXX-XX-XX-XX-XX-XX
|
#open XXXX-XX-XX-XX-XX-XX
|
||||||
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p cmd.name cmd.key cmd.value success reply.value
|
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p cmd.name cmd.key cmd.value success reply.value
|
||||||
#types time string addr port addr port string string string bool string
|
#types time string addr port addr port string string string bool string
|
||||||
XXXXXXXXXX.XXXXXX ClEkJM2Vm5giqnMf4h 127.0.0.1 60833 127.0.0.1 6379 PUBLISH - - T -
|
XXXXXXXXXX.XXXXXX ClEkJM2Vm5giqnMf4h 127.0.0.1 60833 127.0.0.1 6379 PUBLISH - - T 2
|
||||||
XXXXXXXXXX.XXXXXX C4J4Th3PJpwUYZZ6gc 127.0.0.1 60837 127.0.0.1 6379 PUBLISH - - T -
|
XXXXXXXXXX.XXXXXX C4J4Th3PJpwUYZZ6gc 127.0.0.1 60837 127.0.0.1 6379 PUBLISH - - T 1
|
||||||
XXXXXXXXXX.XXXXXX CtPZjS20MLrsMUOJi2 127.0.0.1 60838 127.0.0.1 6379 SET sanity_check you_are_sane T OK
|
XXXXXXXXXX.XXXXXX CtPZjS20MLrsMUOJi2 127.0.0.1 60838 127.0.0.1 6379 SET sanity_check you_are_sane T OK
|
||||||
XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 60831 127.0.0.1 6379 SUBSCRIBE - - - -
|
XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 60831 127.0.0.1 6379 SUBSCRIBE - - - -
|
||||||
XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 60831 127.0.0.1 6379 PSUBSCRIBE - - - -
|
XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 60831 127.0.0.1 6379 PSUBSCRIBE - - - -
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue