Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7f8ddeac
authored
Dec 16, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added little endian methods to ParsableByteArray.
parent
50d5cbea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
0 deletions
library/src/androidTest/java/com/google/android/exoplayer/util/ParsableByteArrayTest.java
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
library/src/androidTest/java/com/google/android/exoplayer/util/ParsableByteArrayTest.java
View file @
7f8ddeac
...
@@ -278,4 +278,48 @@ public class ParsableByteArrayTest extends TestCase {
...
@@ -278,4 +278,48 @@ public class ParsableByteArrayTest extends TestCase {
assertTrue
(
Arrays
.
equals
(
parsableByteArray
.
data
,
copy
));
assertTrue
(
Arrays
.
equals
(
parsableByteArray
.
data
,
copy
));
}
}
public
void
testReadLittleEndianLong
()
{
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
new
byte
[]{
0x01
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
(
byte
)
0xFF
});
assertEquals
(
0xFF00000000000001
L
,
byteArray
.
readLittleEndianLong
());
}
public
void
testReadLittleEndianUnsignedInt
()
{
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
new
byte
[]
{
0x10
,
0x00
,
0x00
,
(
byte
)
0xFF
});
assertEquals
(
0xFF000010
L
,
byteArray
.
readLittleEndianUnsignedInt
());
}
public
void
testReadLittleEndianInt
()
{
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
new
byte
[]{
0x01
,
0x00
,
0x00
,
(
byte
)
0xFF
});
assertEquals
(
0xFF000001
,
byteArray
.
readLittleEndianInt
());
}
public
void
testReadLittleEndianUnsignedInt24
()
{
byte
[]
data
=
{
0x01
,
0x02
,
(
byte
)
0xFF
};
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
data
);
assertEquals
(
0xFF0201
,
byteArray
.
readLittleEndianUnsignedInt24
());
}
public
void
testReadLittleEndianUnsignedShort
()
{
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
new
byte
[]{
0x01
,
(
byte
)
0xFF
,
0x02
,
(
byte
)
0xFF
});
assertEquals
(
0xFF01
,
byteArray
.
readLittleEndianUnsignedShort
());
assertEquals
(
0xFF02
,
byteArray
.
readLittleEndianUnsignedShort
());
}
public
void
testReadLittleEndianShort
()
{
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
new
byte
[]{
0x01
,
(
byte
)
0xFF
,
0x02
,
(
byte
)
0xFF
});
assertEquals
((
short
)
0xFF01
,
byteArray
.
readLittleEndianShort
());
assertEquals
((
short
)
0xFF02
,
byteArray
.
readLittleEndianShort
());
}
}
}
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
View file @
7f8ddeac
...
@@ -170,12 +170,22 @@ public final class ParsableByteArray {
...
@@ -170,12 +170,22 @@ public final class ParsableByteArray {
|
(
data
[
position
++]
&
0xFF
);
|
(
data
[
position
++]
&
0xFF
);
}
}
/** Reads the next two bytes as an unsigned value. */
public
int
readLittleEndianUnsignedShort
()
{
return
(
data
[
position
++]
&
0xFF
)
|
(
data
[
position
++]
&
0xFF
)
<<
8
;
}
/** Reads the next two bytes as an signed value. */
/** Reads the next two bytes as an signed value. */
public
short
readShort
()
{
public
short
readShort
()
{
return
(
short
)
((
data
[
position
++]
&
0xFF
)
<<
8
return
(
short
)
((
data
[
position
++]
&
0xFF
)
<<
8
|
(
data
[
position
++]
&
0xFF
));
|
(
data
[
position
++]
&
0xFF
));
}
}
/** Reads the next two bytes as a signed value. */
public
short
readLittleEndianShort
()
{
return
(
short
)
((
data
[
position
++]
&
0xFF
)
|
(
data
[
position
++]
&
0xFF
)
<<
8
);
}
/** Reads the next three bytes as an unsigned value. */
/** Reads the next three bytes as an unsigned value. */
public
int
readUnsignedInt24
()
{
public
int
readUnsignedInt24
()
{
return
(
data
[
position
++]
&
0xFF
)
<<
16
return
(
data
[
position
++]
&
0xFF
)
<<
16
...
@@ -183,6 +193,13 @@ public final class ParsableByteArray {
...
@@ -183,6 +193,13 @@ public final class ParsableByteArray {
|
(
data
[
position
++]
&
0xFF
);
|
(
data
[
position
++]
&
0xFF
);
}
}
/** Reads the next three bytes as an unsigned value in little endian order. */
public
int
readLittleEndianUnsignedInt24
()
{
return
(
data
[
position
++]
&
0xFF
)
|
(
data
[
position
++]
&
0xFF
)
<<
8
|
(
data
[
position
++]
&
0xFF
)
<<
16
;
}
/** Reads the next four bytes as an unsigned value. */
/** Reads the next four bytes as an unsigned value. */
public
long
readUnsignedInt
()
{
public
long
readUnsignedInt
()
{
return
(
data
[
position
++]
&
0xFF
L
)
<<
24
return
(
data
[
position
++]
&
0xFF
L
)
<<
24
...
@@ -191,6 +208,14 @@ public final class ParsableByteArray {
...
@@ -191,6 +208,14 @@ public final class ParsableByteArray {
|
(
data
[
position
++]
&
0xFF
L
);
|
(
data
[
position
++]
&
0xFF
L
);
}
}
/** Reads the next four bytes as an unsigned value in little endian order. */
public
long
readLittleEndianUnsignedInt
()
{
return
(
data
[
position
++]
&
0xFF
L
)
|
(
data
[
position
++]
&
0xFF
L
)
<<
8
|
(
data
[
position
++]
&
0xFF
L
)
<<
16
|
(
data
[
position
++]
&
0xFF
L
)
<<
24
;
}
/** Reads the next four bytes as a signed value. */
/** Reads the next four bytes as a signed value. */
public
int
readInt
()
{
public
int
readInt
()
{
return
(
data
[
position
++]
&
0xFF
)
<<
24
return
(
data
[
position
++]
&
0xFF
)
<<
24
...
@@ -199,6 +224,14 @@ public final class ParsableByteArray {
...
@@ -199,6 +224,14 @@ public final class ParsableByteArray {
|
(
data
[
position
++]
&
0xFF
);
|
(
data
[
position
++]
&
0xFF
);
}
}
/** Reads the next four bytes as an signed value in little endian order. */
public
int
readLittleEndianInt
()
{
return
(
data
[
position
++]
&
0xFF
)
|
(
data
[
position
++]
&
0xFF
)
<<
8
|
(
data
[
position
++]
&
0xFF
)
<<
16
|
(
data
[
position
++]
&
0xFF
)
<<
24
;
}
/** Reads the next eight bytes as a signed value. */
/** Reads the next eight bytes as a signed value. */
public
long
readLong
()
{
public
long
readLong
()
{
return
(
data
[
position
++]
&
0xFF
L
)
<<
56
return
(
data
[
position
++]
&
0xFF
L
)
<<
56
...
@@ -211,6 +244,18 @@ public final class ParsableByteArray {
...
@@ -211,6 +244,18 @@ public final class ParsableByteArray {
|
(
data
[
position
++]
&
0xFF
L
);
|
(
data
[
position
++]
&
0xFF
L
);
}
}
/** Reads the next eight bytes as a signed value in little endian order. */
public
long
readLittleEndianLong
()
{
return
(
data
[
position
++]
&
0xFF
L
)
|
(
data
[
position
++]
&
0xFF
L
)
<<
8
|
(
data
[
position
++]
&
0xFF
L
)
<<
16
|
(
data
[
position
++]
&
0xFF
L
)
<<
24
|
(
data
[
position
++]
&
0xFF
L
)
<<
32
|
(
data
[
position
++]
&
0xFF
L
)
<<
40
|
(
data
[
position
++]
&
0xFF
L
)
<<
48
|
(
data
[
position
++]
&
0xFF
L
)
<<
56
;
}
/** Reads the next four bytes, returning the integer portion of the fixed point 16.16 integer. */
/** Reads the next four bytes, returning the integer portion of the fixed point 16.16 integer. */
public
int
readUnsignedFixedPoint1616
()
{
public
int
readUnsignedFixedPoint1616
()
{
int
result
=
(
data
[
position
++]
&
0xFF
)
<<
8
int
result
=
(
data
[
position
++]
&
0xFF
)
<<
8
...
...
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