aboutsummaryrefslogtreecommitdiffstats
path: root/components/devtools/protocol.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2014-09-01 10:08:10 -0400
committerJosh Matthews <josh@joshmatthews.net>2014-09-18 15:06:40 -0400
commitbb9955c28132a0c6b2fa85187f6d4e1566d7db5e (patch)
tree65624e6c53a041b9abde45f31497aa7514b332cb /components/devtools/protocol.rs
parentcdb4037ca22409af50847321ce86653073df39e6 (diff)
downloadservo-bb9955c28132a0c6b2fa85187f6d4e1566d7db5e.tar.gz
servo-bb9955c28132a0c6b2fa85187f6d4e1566d7db5e.zip
Split devtools implementation into sensible modules.
Diffstat (limited to 'components/devtools/protocol.rs')
-rw-r--r--components/devtools/protocol.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/components/devtools/protocol.rs b/components/devtools/protocol.rs
new file mode 100644
index 00000000000..728e593040e
--- /dev/null
+++ b/components/devtools/protocol.rs
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/// Low-level wire protocol implementation. Currently only supports [JSON packets](https://wiki.mozilla.org/Remote_Debugging_Protocol_Stream_Transport#JSON_Packets).
+
+use serialize::{json, Encodable};
+use std::io::{IoError, TcpStream};
+
+pub trait JsonPacketSender {
+ fn write_json_packet<'a, T: Encodable<json::Encoder<'a>,IoError>>(&mut self, obj: &T);
+}
+
+impl JsonPacketSender for TcpStream {
+ fn write_json_packet<'a, T: Encodable<json::Encoder<'a>,IoError>>(&mut self, obj: &T) {
+ let s = json::encode(obj).replace("__type__", "type");
+ println!("<- {:s}", s);
+ self.write_str(s.len().to_string().as_slice()).unwrap();
+ self.write_u8(':' as u8).unwrap();
+ self.write_str(s.as_slice()).unwrap();
+ }
+}