-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic support for server-side #4
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ extern crate octavo; | |
#[cfg(feature = "apple-auth")] | ||
extern crate crypto; | ||
|
||
use std::io::Write; | ||
use byteorder::{BigEndian, WriteBytesExt}; | ||
|
||
mod protocol; | ||
mod zrle; | ||
mod security; | ||
|
@@ -29,6 +32,37 @@ pub struct Rect { | |
pub height: u16 | ||
} | ||
|
||
impl Rect { | ||
/// Constructs new `Rect`. | ||
pub fn new(left: u16, top: u16, width: u16, height: u16) -> Self { | ||
Rect { | ||
left: left, | ||
top: top, | ||
width: width, | ||
height: height, | ||
} | ||
} | ||
|
||
/// Constructs new zero-sized `Rect` placed at (0, 0). | ||
pub fn new_empty() -> Self { | ||
Rect { | ||
left: 0, | ||
top: 0, | ||
width: 0, | ||
height: 0, | ||
} | ||
} | ||
|
||
/// Writes `Rect` to given stream. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also factor out reading a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already use the Message trait for parts of messages as well: https://github.com/whitequark/rust-vnc/blob/master/src/protocol.rs#L486-L514 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll move to to protocol and reexport in lib. |
||
fn write_to<W: Write>(&self, writer: &mut W) -> Result<()> { | ||
try!(writer.write_u16::<BigEndian>(self.left)); | ||
try!(writer.write_u16::<BigEndian>(self.top)); | ||
try!(writer.write_u16::<BigEndian>(self.width)); | ||
try!(writer.write_u16::<BigEndian>(self.height)); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Io(std::io::Error), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,40 @@ pub struct PixelFormat { | |
pub blue_shift: u8, | ||
} | ||
|
||
impl PixelFormat { | ||
/// Creates RGB pixel format with 4 bytes per pixel and 3 bytes of depth. | ||
pub fn new_rgb8888() -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two also should be constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same argument as in |
||
PixelFormat { | ||
bits_per_pixel: 32, | ||
depth: 24, | ||
big_endian: true, | ||
true_colour: true, | ||
red_max: 255, | ||
green_max: 255, | ||
blue_max: 255, | ||
red_shift: 0, | ||
green_shift: 8, | ||
blue_shift: 16, | ||
} | ||
} | ||
|
||
/// Creates BGR pixel format with 4 bytes per pixel and 3 bytes of depth. | ||
pub fn new_bgr8888() -> Self { | ||
PixelFormat { | ||
bits_per_pixel: 32, | ||
depth: 24, | ||
big_endian: true, | ||
true_colour: true, | ||
red_max: 255, | ||
green_max: 255, | ||
blue_max: 255, | ||
red_shift: 16, | ||
green_shift: 8, | ||
blue_shift: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Message for PixelFormat { | ||
fn read_from<R: Read>(reader: &mut R) -> Result<PixelFormat> { | ||
let pixel_format = PixelFormat { | ||
|
@@ -513,17 +547,17 @@ impl Message for C2S { | |
} | ||
|
||
#[derive(Debug)] | ||
pub struct Rectangle { | ||
pub struct RectangleHeader { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This renaming is no longer necessary as we have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it really is rectangle header. That's how RFC calls this. |
||
pub x_position: u16, | ||
pub y_position: u16, | ||
pub width: u16, | ||
pub height: u16, | ||
pub encoding: Encoding, | ||
} | ||
|
||
impl Message for Rectangle { | ||
fn read_from<R: Read>(reader: &mut R) -> Result<Rectangle> { | ||
Ok(Rectangle { | ||
impl Message for RectangleHeader { | ||
fn read_from<R: Read>(reader: &mut R) -> Result<RectangleHeader> { | ||
Ok(RectangleHeader { | ||
x_position: try!(reader.read_u16::<BigEndian>()), | ||
y_position: try!(reader.read_u16::<BigEndian>()), | ||
width: try!(reader.read_u16::<BigEndian>()), | ||
|
@@ -571,7 +605,7 @@ pub enum S2C { | |
// core spec | ||
FramebufferUpdate { | ||
count: u16, | ||
/* Vec<Rectangle> has to be read out manually */ | ||
// Vec<RectangleHeader> has to be read out manually | ||
}, | ||
SetColourMapEntries { | ||
first_colour: u16, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this a constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should it be? It is jet another way of construction just like
new
. Compiler should optimize it so in binary code it will be just in-place initialization.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if it's a constant then you can use it in other constants. Why have methods that always return the same value by design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, both approaches have small pros and cons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the pros of
new_empty()
? They should result in exact same machine code...