@@ -79,7 +79,7 @@ pub struct Chunk {
7979}
8080
8181/// A section of a chunk, i.e. a 16*16*16 block area.
82- #[ derive( Clone , Debug , Default ) ]
82+ #[ derive( Clone , Debug , Default , PartialEq ) ]
8383pub struct Section {
8484 /// The number of non-empty blocks in the section, as sent to us by the
8585 /// server.
@@ -579,6 +579,7 @@ pub fn section_index(y: i32, min_y: i32) -> u32 {
579579#[ cfg( test) ]
580580mod tests {
581581 use super :: * ;
582+ use crate :: palette:: SectionPos ;
582583
583584 #[ test]
584585 fn test_section_index ( ) {
@@ -639,4 +640,33 @@ mod tests {
639640 ChunkPos :: new( 2 , -1 ) ,
640641 ) ;
641642 }
643+
644+ #[ test]
645+ fn serialize_and_deserialize_section ( ) {
646+ let mut states = PalettedContainer :: new ( ) ;
647+
648+ states. set (
649+ SectionPos :: new ( 1 , 2 , 3 ) ,
650+ BlockState :: try_from ( BlockState :: MAX_STATE ) . unwrap ( ) ,
651+ ) ;
652+ states. set (
653+ SectionPos :: new ( 4 , 5 , 6 ) ,
654+ BlockState :: try_from ( BlockState :: MAX_STATE ) . unwrap ( ) ,
655+ ) ;
656+ let biomes = PalettedContainer :: new ( ) ;
657+ let section = Section {
658+ block_count : 2 ,
659+ states,
660+ biomes,
661+ } ;
662+
663+ let mut buf = Vec :: new ( ) ;
664+ section. azalea_write ( & mut buf) . unwrap ( ) ;
665+
666+ let mut cur = Cursor :: new ( buf. as_slice ( ) ) ;
667+ let deserialized_section = Section :: azalea_read ( & mut cur) . unwrap ( ) ;
668+ assert_eq ! ( cur. position( ) , buf. len( ) as u64 ) ;
669+
670+ assert_eq ! ( section, deserialized_section) ;
671+ }
642672}
0 commit comments