-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mobile: Use direct ByteBuffer to pass data between C++ and Java (#32715)
Signed-off-by: Fredy Wijaya <[email protected]>
- Loading branch information
Showing
15 changed files
with
154 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
mobile/library/java/io/envoyproxy/envoymobile/engine/ByteBuffers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.envoyproxy.envoymobile.engine; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class ByteBuffers { | ||
/** | ||
* Copies the specified `ByteBuffer` into a new `ByteBuffer`. The `ByteBuffer` created will | ||
* be backed by `byte[]`. | ||
*/ | ||
public static ByteBuffer copy(ByteBuffer byteBuffer) { | ||
byte[] bytes = new byte[byteBuffer.capacity()]; | ||
byteBuffer.get(bytes); | ||
return ByteBuffer.wrap(bytes); | ||
} | ||
|
||
private ByteBuffers() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
mobile/library/java/io/envoyproxy/envoymobile/engine/types/EnvoyHTTPFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
mobile/test/java/io/envoyproxy/envoymobile/engine/ByteBuffersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.envoyproxy.envoymobile.engine; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ByteBuffersTest { | ||
@Test | ||
public void testCopy() { | ||
ByteBuffer source = ByteBuffer.allocateDirect(3); | ||
source.put((byte)1); | ||
source.put((byte)2); | ||
source.put((byte)3); | ||
source.flip(); | ||
|
||
ByteBuffer dest = ByteBuffers.copy(source); | ||
source.flip(); | ||
assertThat(dest).isEqualTo(source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
mobile/test/java/io/envoyproxy/envoymobile/utilities/ByteBuffersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.envoyproxy.envoymobile.utilities; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class ByteBuffersTest {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters