Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/PacketDecoder.java

Issue 517233002: DevTools socket tunnel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glue
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/PacketDecoder.java
diff --git a/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/PacketDecoder.java b/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/PacketDecoder.java
new file mode 100644
index 0000000000000000000000000000000000000000..d8e0dff56d4524064ea3734670d824991d607567
--- /dev/null
+++ b/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/PacketDecoder.java
@@ -0,0 +1,67 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.devtools_bridge;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Decodes data packets of SocketTunnelClient and SocketTunnelServer for tests.
+ */
+public final class PacketDecoder extends SocketTunnelBase.PacketDecoderBase {
+ private boolean mControlPacket = false;
+ private boolean mDataPacket;
+ private int mOpCode;
+ private int mConnectionId;
+ private byte[] mData;
+
+ protected void onReceivedDataPacket(int connectionId, byte[] data) {
+ mDataPacket = true;
+ mConnectionId = connectionId;
+ mData = data;
+ }
+
+ @Override
+ protected void onReceivedControlPacket(int connectionId, byte opCode) {
+ mControlPacket = true;
+ mOpCode = opCode;
+ mConnectionId = connectionId;
+ }
+
+ public static PacketDecoder tryDecode(ByteBuffer packet) throws SocketTunnelBase.ProtocolError {
+ PacketDecoder decoder = new PacketDecoder();
+ decoder.decodePacket(packet);
+ return decoder;
+ }
+
+ public static PacketDecoder decode(ByteBuffer packet) {
+ try {
+ return tryDecode(packet);
+ } catch (SocketTunnelBase.ProtocolError e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public boolean isControlPacket() {
+ return mControlPacket;
+ }
+
+ public boolean isDataPacket() {
+ return mDataPacket;
+ }
+
+ public int opCode() {
+ assert isControlPacket();
+ return mOpCode;
+ }
+
+ public int connectionId() {
+ return mConnectionId;
+ }
+
+ public byte[] data() {
+ assert isDataPacket();
+ return mData.clone();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698