-
-
Save Kimundi/8141115 to your computer and use it in GitHub Desktop.
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
use output_stream::OutputStream; | |
use message::Message; | |
use wire_type::LengthDelimited; | |
pub struct OutputCounter { | |
byte_count: uint, | |
nested: ~[uint] | |
} | |
impl OutputCounter { | |
pub fn new() -> OutputCounter { | |
OutputCounter{ byte_count: 0, nested: ~[] } | |
} | |
} | |
impl OutputStream for OutputCounter { | |
fn write_byte(&mut self, _: u8) { | |
self.byte_count += 1; | |
} | |
fn write_f64(&mut self, _: f64) { | |
self.byte_count += 8; | |
} | |
fn write_message(counter: &mut OutputCounter, msg: &Message) { | |
message.write_to_buffer(counter as &mut OutputStream); | |
} | |
fn write_nested(&mut self, field: uint, message: &Message) { | |
self.write_tag_and_wire_type(field as u64, LengthDelimited); | |
let prev_count = self.byte_count; | |
{ | |
write_message(self, message); | |
} | |
let nested_size = self.byte_count - prev_count; | |
self.write_u64(nested_size as u64); | |
self.nested.push(nested_size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment