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
3d658a77
Commit
3d658a77
authored
Aug 14, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GetString(ReadOnlySequence<byte> buffer) API
parent
25e6f67a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
Format.cs
StackExchange.Redis/Format.cs
+20
-0
PhysicalConnection.cs
StackExchange.Redis/PhysicalConnection.cs
+2
-0
No files found.
StackExchange.Redis/Format.cs
View file @
3d658a77
using
System
;
using
System.Buffers
;
using
System.Globalization
;
using
System.Net
;
using
System.Numerics
;
...
...
@@ -261,5 +262,24 @@ internal static EndPoint TryParseEndPoint(string addressWithPort)
}
return
new
DnsEndPoint
(
addressPart
,
port
??
0
);
}
internal
static
string
GetString
(
ReadOnlySequence
<
byte
>
buffer
)
{
if
(
buffer
.
IsSingleSegment
)
return
GetString
(
buffer
.
First
.
Span
);
var
arr
=
ArrayPool
<
byte
>.
Shared
.
Rent
(
checked
((
int
)
buffer
.
Length
));
var
span
=
new
Span
<
byte
>(
arr
,
0
,
(
int
)
buffer
.
Length
);
buffer
.
CopyTo
(
span
);
string
s
=
GetString
(
span
);
ArrayPool
<
byte
>.
Shared
.
Return
(
arr
);
return
s
;
}
internal
static
unsafe
string
GetString
(
ReadOnlySpan
<
byte
>
span
)
{
fixed
(
byte
*
ptr
=
&
MemoryMarshal
.
GetReference
(
span
))
{
return
Encoding
.
UTF8
.
GetString
(
ptr
,
span
.
Length
);
}
}
}
}
StackExchange.Redis/PhysicalConnection.cs
View file @
3d658a77
...
...
@@ -1514,10 +1514,12 @@ private static RawResult ReadLineTerminatedString(ResultType type, ref BufferRea
reader
.
Consume
(
1
);
return
ReadArray
(
in
buffer
,
ref
reader
,
includeDetilInExceptions
,
server
);
default
:
// string s = Format.GetString(buffer);
if
(
allowInlineProtocol
)
return
ParseInlineProtocol
(
ReadLineTerminatedString
(
ResultType
.
SimpleString
,
ref
reader
));
throw
new
InvalidOperationException
(
"Unexpected response prefix: "
+
(
char
)
prefix
);
}
}
private
static
RawResult
ParseInlineProtocol
(
RawResult
line
)
{
if
(!
line
.
HasValue
)
return
RawResult
.
Nil
;
// incomplete line
...
...
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