Index: chrome/common/extensions/docs/examples/extensions/native_messaging/echo.py |
diff --git a/chrome/common/extensions/docs/examples/extensions/native_messaging/echo.py b/chrome/common/extensions/docs/examples/extensions/native_messaging/echo.py |
index ffb6cefeb94761b5560cb555c9f9a0ab9ad5954f..d0be74bdfe9cb84b8767afe5f63676a2412c89f4 100755 |
--- a/chrome/common/extensions/docs/examples/extensions/native_messaging/echo.py |
+++ b/chrome/common/extensions/docs/examples/extensions/native_messaging/echo.py |
@@ -4,30 +4,23 @@ |
# found in the LICENSE file. |
# A simple native client in python. |
-# All this client does is echo the text it recieves back at the extension. |
+# All this client does is echo the text it receives back at the extension. |
import sys |
import struct |
-MESSAGE_TYPE_SEND_MESSAGE_REQUEST = 0 |
-MESSAGE_TYPE_SEND_MESSAGE_RESPONSE = 1 |
-MESSAGE_TYPE_CONNECT = 2 |
-MESSAGE_TYPE_CONNECT_MESSAGE = 3 |
- |
def Main(): |
message_number = 0 |
while 1: |
# Read the message type (first 4 bytes). |
- type_bytes = sys.stdin.read(4) |
+ text_length_bytes = sys.stdin.read(4) |
- if len(type_bytes) == 0: |
+ if len(text_length_bytes) == 0: |
break |
- message_type = struct.unpack('i', type_bytes)[0] |
- |
# Read the message length (4 bytes). |
- text_length = struct.unpack('i', sys.stdin.read(4))[0] |
+ text_length = struct.unpack('i', text_length_bytes)[0] |
# Read the text (JSON object) of the message. |
text = sys.stdin.read(text_length).decode('utf-8') |
@@ -35,16 +28,10 @@ def Main(): |
message_number += 1 |
response = '{{"id": {0}, "echo": {1}}}'.format(message_number, |
- text).encode('utf-8') |
- |
- # Choose the correct message type for the response. |
- if message_type == MESSAGE_TYPE_SEND_MESSAGE_REQUEST: |
- response_type = MESSAGE_TYPE_SEND_MESSAGE_RESPONSE |
- else: |
- response_type = MESSAGE_TYPE_CONNECT_MESSAGE |
+ text).encode('utf-8') |
try: |
- sys.stdout.write(struct.pack("II", response_type, len(response))) |
+ sys.stdout.write(struct.pack("I", len(response))) |
sys.stdout.write(response) |
sys.stdout.flush() |
except IOError: |