add equality checks and fuzz testing for chunk and storage data comparison

This commit is contained in:
adman
2026-05-03 18:34:21 +02:00
parent 5d3860b91e
commit aef9615476
6 changed files with 69 additions and 169 deletions
+17 -2
View File
@@ -7,8 +7,8 @@ type Chunk struct {
version string
}
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (err error) {
c := &Chunk{}
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (c *Chunk, err error) {
c = &Chunk{}
c.version = version
nSections := worldHeight / ChunkWidth
@@ -31,3 +31,18 @@ func (c *Chunk) WriteChunkData(w io.Writer) (err error) {
}
return
}
func (c *Chunk) Equals(other *Chunk) bool {
if c.version != other.version {
return false
}
if len(c.Sections) != len(other.Sections) {
return false
}
for i, s := range c.Sections {
if !SectionEquals(s, other.Sections[i]) {
return false
}
}
return true
}