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
e400ca9e
Commit
e400ca9e
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Trying to eliminate a weird bug in the StringSerializer
parent
03a2acd1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/StringSerializer.kt
+4
-9
4 additions, 9 deletions
...quassel/protocol/primitive/serializer/StringSerializer.kt
with
4 additions
and
9 deletions
lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/StringSerializer.kt
+
4
−
9
View file @
e400ca9e
...
@@ -24,13 +24,14 @@ abstract class StringSerializer(
...
@@ -24,13 +24,14 @@ abstract class StringSerializer(
}
}
)
)
private
val
charBuffer
=
ThreadLocal
<
CharBuffer
>()
//
private val charBuffer = ThreadLocal<CharBuffer>()
object
UTF16
:
StringSerializer
(
Charsets
.
UTF_16BE
)
object
UTF16
:
StringSerializer
(
Charsets
.
UTF_16BE
)
object
UTF8
:
StringSerializer
(
Charsets
.
UTF_8
)
object
UTF8
:
StringSerializer
(
Charsets
.
UTF_8
)
object
C
:
StringSerializer
(
Charsets
.
ISO_8859_1
,
trailingNullByte
=
true
)
object
C
:
StringSerializer
(
Charsets
.
ISO_8859_1
,
trailingNullByte
=
true
)
private
inline
fun
charBuffer
(
len
:
Int
):
CharBuffer
{
private
inline
fun
charBuffer
(
len
:
Int
):
CharBuffer
{
/*
if (charBuffer.get() == null)
if (charBuffer.get() == null)
charBuffer.set(CharBuffer.allocate(1024))
charBuffer.set(CharBuffer.allocate(1024))
val buf = if (len >= 1024)
val buf = if (len >= 1024)
...
@@ -40,9 +41,10 @@ abstract class StringSerializer(
...
@@ -40,9 +41,10 @@ abstract class StringSerializer(
buf.clear()
buf.clear()
buf.limit(len)
buf.limit(len)
return buf
return buf
*/
return
CharBuffer
.
allocate
(
len
)
}
}
@Synchronized
override
fun
serialize
(
buffer
:
ChainedByteBuffer
,
data
:
String
?,
features
:
Quassel_Features
)
{
override
fun
serialize
(
buffer
:
ChainedByteBuffer
,
data
:
String
?,
features
:
Quassel_Features
)
{
if
(
data
==
null
)
{
if
(
data
==
null
)
{
IntSerializer
.
serialize
(
buffer
,
-
1
,
features
)
IntSerializer
.
serialize
(
buffer
,
-
1
,
features
)
...
@@ -50,7 +52,6 @@ abstract class StringSerializer(
...
@@ -50,7 +52,6 @@ abstract class StringSerializer(
val
charBuffer
=
charBuffer
(
data
.
length
)
val
charBuffer
=
charBuffer
(
data
.
length
)
charBuffer
.
put
(
data
)
charBuffer
.
put
(
data
)
charBuffer
.
flip
()
charBuffer
.
flip
()
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
)
buffer
.
put
(
byteBuffer
)
buffer
.
put
(
byteBuffer
)
...
@@ -59,18 +60,15 @@ abstract class StringSerializer(
...
@@ -59,18 +60,15 @@ abstract class StringSerializer(
}
}
}
}
@Synchronized
fun
serialize
(
data
:
String
?):
ByteBuffer
=
if
(
data
==
null
)
{
fun
serialize
(
data
:
String
?):
ByteBuffer
=
if
(
data
==
null
)
{
ByteBuffer
.
allocate
(
0
)
ByteBuffer
.
allocate
(
0
)
}
else
{
}
else
{
val
charBuffer
=
charBuffer
(
data
.
length
)
val
charBuffer
=
charBuffer
(
data
.
length
)
charBuffer
.
put
(
data
)
charBuffer
.
put
(
data
)
charBuffer
.
flip
()
charBuffer
.
flip
()
encoder
.
reset
()
encoder
.
encode
(
charBuffer
)
encoder
.
encode
(
charBuffer
)
}
}
@Synchronized
fun
deserializeAll
(
buffer
:
ByteBuffer
):
String
?
{
fun
deserializeAll
(
buffer
:
ByteBuffer
):
String
?
{
val
len
=
buffer
.
remaining
()
val
len
=
buffer
.
remaining
()
return
if
(
len
==
-
1
)
{
return
if
(
len
==
-
1
)
{
...
@@ -79,7 +77,6 @@ abstract class StringSerializer(
...
@@ -79,7 +77,6 @@ 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
)
decoder
.
reset
()
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
)
...
@@ -88,7 +85,6 @@ abstract class StringSerializer(
...
@@ -88,7 +85,6 @@ abstract class StringSerializer(
}
}
}
}
@Synchronized
override
fun
deserialize
(
buffer
:
ByteBuffer
,
features
:
Quassel_Features
):
String
?
{
override
fun
deserialize
(
buffer
:
ByteBuffer
,
features
:
Quassel_Features
):
String
?
{
val
len
=
IntSerializer
.
deserialize
(
buffer
,
features
)
val
len
=
IntSerializer
.
deserialize
(
buffer
,
features
)
return
if
(
len
==
-
1
)
{
return
if
(
len
==
-
1
)
{
...
@@ -97,7 +93,6 @@ abstract class StringSerializer(
...
@@ -97,7 +93,6 @@ 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
)
decoder
.
reset
()
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