module Tnetstring
Overview
Tnetstring decoder used by the mitmproxy flow analyzer.
Format (https://tnetstrings.info/):
mitmproxy ships a small extension over the base format: a ; type
byte denoting raw bytes alongside ,. We accept both and surface
them as Crystal String, which is what every caller of this module
wants today.
Defined in:
utils/tnetstring.crConstant Summary
-
BOOL_TYPE =
'!'.ord.to_u8 -
BYTES_TYPE =
';'.ord.to_u8 -
mitmproxy's tnetstring variant adds a separate
;type for raw bytes alongside the standard,string type. Decoding both as Crystal String is fine — they are interchangeable to the consumer; we only need to handle the type byte either way. -
COLON =
':'.ord.to_u8 -
DICT_TYPE =
'}'.ord.to_u8 -
FLOAT_TYP =
'^'.ord.to_u8 -
INT_TYPE =
'#'.ord.to_u8 -
LIST_TYPE =
']'.ord.to_u8 -
NULL_TYPE =
'~'.ord.to_u8 -
STR_TYPE =
','.ord.to_u8
Class Method Summary
- .encode(value : Value, io : IO) : Nil
-
.encode(value : Value) : Bytes
Encoder — currently used by specs to build flow fixtures programmatically, but kept in the production module so the implementation is exercised by the same tests as the decoder.
-
.parse(bytes : Bytes, pos : Int32 = 0) : Tuple(Value, Int32)
Parses one tnetstring value starting at byte offset
pos. -
.parse_all(bytes : Bytes) : Array(Value)
Parses every top-level tnetstring value in
bytes.
Class Method Detail
Encoder — currently used by specs to build flow fixtures programmatically, but kept in the production module so the implementation is exercised by the same tests as the decoder.
Parses one tnetstring value starting at byte offset pos.
Returns the decoded value and the next read position.
Parses every top-level tnetstring value in bytes. The mitmproxy
flow file format concatenates flows as a stream of dict values
with no framing beyond tnetstring itself.