Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
QuasselDroid-ng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
QuasselDroid-ng
Commits
f5aad82f
Commit
f5aad82f
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Attempt to fix encoder issues
parent
d6331244
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/StringSerializer.kt
+12
-11
12 additions, 11 deletions
...quassel/protocol/primitive/serializer/StringSerializer.kt
with
12 additions
and
11 deletions
lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/StringSerializer.kt
+
12
−
11
View file @
f5aad82f
...
@@ -11,21 +11,15 @@ import java.nio.charset.CharsetEncoder
...
@@ -11,21 +11,15 @@ import java.nio.charset.CharsetEncoder
import
kotlin.concurrent.getOrSet
import
kotlin.concurrent.getOrSet
abstract
class
StringSerializer
(
abstract
class
StringSerializer
(
private
val
encoder
:
CharsetEncoder
,
private
val
charset
:
Charset
,
private
val
decoder
:
CharsetDecoder
,
private
val
trailingNullBytes
:
Int
private
val
trailingNullBytes
:
Int
)
:
Serializer
<
String
?>
{
)
:
Serializer
<
String
?>
{
constructor
(
charset
:
Charset
,
trailingNullByte
:
Boolean
=
false
)
:
this
(
constructor
(
charset
:
Charset
,
trailingNullByte
:
Boolean
=
false
)
:
charset
.
newEncoder
(),
this
(
charset
,
if
(
trailingNullByte
)
1
else
0
)
charset
.
newDecoder
(),
if
(
trailingNullByte
)
{
1
}
else
{
0
}
)
private
val
charBuffer
=
ThreadLocal
<
CharBuffer
>()
private
val
charBuffer
=
ThreadLocal
<
CharBuffer
>()
private
val
encoder
=
ThreadLocal
<
CharsetEncoder
>()
private
val
decoder
=
ThreadLocal
<
CharsetDecoder
>()
object
UTF16
:
StringSerializer
(
Charsets
.
UTF_16BE
)
object
UTF16
:
StringSerializer
(
Charsets
.
UTF_16BE
)
object
UTF8
:
StringSerializer
(
Charsets
.
UTF_8
)
object
UTF8
:
StringSerializer
(
Charsets
.
UTF_8
)
...
@@ -45,6 +39,9 @@ abstract class StringSerializer(
...
@@ -45,6 +39,9 @@ abstract class StringSerializer(
return
buf
return
buf
}
}
private
inline
fun
encoder
()
=
encoder
.
getOrSet
(
charset
::
newEncoder
)
private
inline
fun
decoder
()
=
decoder
.
getOrSet
(
charset
::
newDecoder
)
override
fun
serialize
(
buffer
:
ChainedByteBuffer
,
data
:
String
?,
features
:
QuasselFeatures
)
=
override
fun
serialize
(
buffer
:
ChainedByteBuffer
,
data
:
String
?,
features
:
QuasselFeatures
)
=
try
{
try
{
if
(
data
==
null
)
{
if
(
data
==
null
)
{
...
@@ -53,6 +50,7 @@ abstract class StringSerializer(
...
@@ -53,6 +50,7 @@ abstract class StringSerializer(
val
charBuffer
=
charBuffer
(
data
.
length
)
val
charBuffer
=
charBuffer
(
data
.
length
)
charBuffer
.
put
(
data
)
charBuffer
.
put
(
data
)
charBuffer
.
flip
()
charBuffer
.
flip
()
val
encoder
=
encoder
()
encoder
.
reset
()
encoder
.
reset
()
val
byteBuffer
=
encoder
.
encode
(
charBuffer
)
val
byteBuffer
=
encoder
.
encode
(
charBuffer
)
IntSerializer
.
serialize
(
buffer
,
byteBuffer
.
remaining
()
+
trailingNullBytes
,
features
)
IntSerializer
.
serialize
(
buffer
,
byteBuffer
.
remaining
()
+
trailingNullBytes
,
features
)
...
@@ -71,6 +69,7 @@ abstract class StringSerializer(
...
@@ -71,6 +69,7 @@ abstract class StringSerializer(
val
charBuffer
=
charBuffer
(
data
.
length
)
val
charBuffer
=
charBuffer
(
data
.
length
)
charBuffer
.
put
(
data
)
charBuffer
.
put
(
data
)
charBuffer
.
flip
()
charBuffer
.
flip
()
val
encoder
=
encoder
()
encoder
.
reset
()
encoder
.
reset
()
encoder
.
encode
(
charBuffer
)
encoder
.
encode
(
charBuffer
)
}
}
...
@@ -86,6 +85,7 @@ abstract class StringSerializer(
...
@@ -86,6 +85,7 @@ abstract class StringSerializer(
val
limit
=
buffer
.
limit
()
val
limit
=
buffer
.
limit
()
buffer
.
limit
(
buffer
.
position
()
+
len
-
trailingNullBytes
)
buffer
.
limit
(
buffer
.
position
()
+
len
-
trailingNullBytes
)
val
charBuffer
=
charBuffer
(
len
)
val
charBuffer
=
charBuffer
(
len
)
val
decoder
=
decoder
()
decoder
.
reset
()
decoder
.
reset
()
decoder
.
decode
(
buffer
,
charBuffer
,
true
)
decoder
.
decode
(
buffer
,
charBuffer
,
true
)
buffer
.
limit
(
limit
)
buffer
.
limit
(
limit
)
...
@@ -106,6 +106,7 @@ abstract class StringSerializer(
...
@@ -106,6 +106,7 @@ abstract class StringSerializer(
val
limit
=
buffer
.
limit
()
val
limit
=
buffer
.
limit
()
buffer
.
limit
(
buffer
.
position
()
+
Math
.
max
(
0
,
len
-
trailingNullBytes
))
buffer
.
limit
(
buffer
.
position
()
+
Math
.
max
(
0
,
len
-
trailingNullBytes
))
val
charBuffer
=
charBuffer
(
len
)
val
charBuffer
=
charBuffer
(
len
)
val
decoder
=
decoder
()
decoder
.
decode
(
buffer
,
charBuffer
,
true
)
decoder
.
decode
(
buffer
,
charBuffer
,
true
)
buffer
.
limit
(
limit
)
buffer
.
limit
(
limit
)
buffer
.
position
(
buffer
.
position
()
+
trailingNullBytes
)
buffer
.
position
(
buffer
.
position
()
+
trailingNullBytes
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment