From 2b6c456bf648e5a7b408b550649d409378e39539 Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Thu, 27 Dec 2012 06:16:16 -0600 Subject: Enhance auto_encode to take number of struct fields emit_struct and read_struct takes an additional len:uint parameter which tells us how many fields the struct we are working on has. This is required to implement an Encoder for the msgpack [1] serialization format. To serialize a struct with msgpack you have to use arrays and the size of the array has to be know before each of the elements are written out. JSON as an example doesn't have this problem as it uses '[' and ']' delimiters for arrays. [1]: www.msgpack.org --- src/libstd/ebml.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd/ebml.rs') diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 59e0a1e84fe..f782b6ff6a7 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -360,7 +360,7 @@ pub mod reader { f() } - fn read_struct(&self, name: &str, f: fn() -> T) -> T { + fn read_struct(&self, name: &str, _len: uint, f: fn() -> T) -> T { debug!("read_struct(name=%s)", name); f() } @@ -631,7 +631,7 @@ pub mod writer { } fn emit_rec(&self, f: fn()) { f() } - fn emit_struct(&self, _name: &str, f: fn()) { f() } + fn emit_struct(&self, _name: &str, _len: uint, f: fn()) { f() } fn emit_field(&self, name: &str, _idx: uint, f: fn()) { self._emit_label(name); f() -- cgit 1.4.1-3-g733a5