Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
dfccbd4a
Commit
dfccbd4a
authored
Aug 14, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parse test
parent
4a8da46d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
Parse.cs
StackExchange.Redis.Tests/Parse.cs
+83
-0
No files found.
StackExchange.Redis.Tests/Parse.cs
0 → 100644
View file @
dfccbd4a
using
System
;
using
System.Buffers
;
using
System.Text
;
using
Xunit
;
using
Xunit.Abstractions
;
namespace
StackExchange.Redis.Tests
{
public
class
Parse
:
TestBase
{
public
Parse
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
public
void
EvilParse
()
{
ReadOnlySequence
<
byte
>
buffer
=
new
ReadOnlySequence
<
byte
>(
Encoding
.
ASCII
.
GetBytes
(
$"$4\r\nPING\r\n$4\r\nPONG\r\n"
));
var
reader
=
new
BufferReader
(
buffer
);
RawResult
result
;
int
found
=
0
;
while
(!(
result
=
PhysicalConnection
.
TryParseResult
(
buffer
,
ref
reader
,
false
,
null
,
false
)).
IsNull
)
{
Writer
.
WriteLine
(
$"
{
result
}
-
{
result
.
GetString
()}
"
);
found
++;
}
Assert
.
Equal
(
2
,
found
);
}
class
FragmentedSegment
:
ReadOnlySequenceSegment
<
byte
>
{
public
new
FragmentedSegment
Next
{
get
=>
(
FragmentedSegment
)
base
.
Next
;
set
=>
base
.
Next
=
value
;
}
public
new
ReadOnlyMemory
<
byte
>
Memory
{
get
=>
base
.
Memory
;
set
=>
base
.
Memory
=
value
;
}
public
new
long
RunningIndex
{
get
=>
base
.
RunningIndex
;
set
=>
base
.
RunningIndex
=
value
;
}
}
[
Fact
]
public
void
EvilParse2
()
{
var
bytes
=
Encoding
.
ASCII
.
GetBytes
(
$"$4\r\nPING\r\n$4\r\nPONG\r\n"
);
FragmentedSegment
chain
=
null
,
tail
=
null
;
for
(
int
i
=
0
;
i
<
bytes
.
Length
;
i
++)
{
var
next
=
new
FragmentedSegment
();
next
.
RunningIndex
=
i
;
next
.
Memory
=
new
ReadOnlyMemory
<
byte
>(
bytes
,
i
,
1
);
if
(
tail
==
null
)
{
chain
=
next
;
}
else
{
tail
.
Next
=
next
;
}
tail
=
next
;
}
ReadOnlySequence
<
byte
>
buffer
=
new
ReadOnlySequence
<
byte
>(
chain
,
0
,
tail
,
0
);
Writer
.
WriteLine
(
$"chain:
{
buffer
.
Length
}
"
);
var
reader
=
new
BufferReader
(
buffer
);
RawResult
result
;
int
found
=
0
;
while
(!(
result
=
PhysicalConnection
.
TryParseResult
(
buffer
,
ref
reader
,
false
,
null
,
false
)).
IsNull
)
{
Writer
.
WriteLine
(
$"
{
result
}
-
{
result
.
GetString
()}
"
);
found
++;
}
Assert
.
Equal
(
2
,
found
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment