]> git.lizzy.rs Git - mt.git/blobdiff - serialize.fmt
Add WaitGroup to SerializePkt
[mt.git] / serialize.fmt
index 991c22b87d3cddaf9512a7d5bd0291838f9aeb12..2076552179ab9fc0d010b245f5389712f6db4c7a 100644 (file)
@@ -2,21 +2,21 @@
                _, err := w.Write([]byte{x})
                chk(err)
        }
-       
+
        func write16(w io.Writer, x uint16) {
                buf := make([]byte, 2)
                be.PutUint16(buf, x)
                _, err := w.Write(buf)
                chk(err)
        }
-       
+
        func write32(w io.Writer, x uint32) {
                buf := make([]byte, 4)
                be.PutUint32(buf, x)
                _, err := w.Write(buf)
                chk(err)
        }
-       
+
        func write64(w io.Writer, x uint64) {
                buf := make([]byte, 8)
                be.PutUint64(buf, x)
@@ -45,15 +45,11 @@ AOMsg       writeAOMsg(w, x)
 image/color.NRGBA      w.Write([]byte{x.A, x.R, x.G, x.B})
 
 map[uint16]*NodeMeta   {
-               w := zlib.NewWriter(w)
-
                if x == nil {
                        write8(w, 0)
                } else {
                        write8(w, 2)
-                       if len(x) > math.MaxUint16 {
-                               chk(ErrTooLong)
-                       }
+                       // len(map[uint16]...) always < math.MaxUint16
                        write16(w, uint16(len(x)))
                        keys := make([]uint16, 0, len(x))
                        for key := range x {
@@ -82,8 +78,6 @@ map[uint16]*NodeMeta  {
                                chk(serialize(w, x[key]))
                        }
                }
-
-               chk(w.Close())
        }
 
 map[[3]int16]*NodeMeta {
@@ -152,7 +146,7 @@ PointedThing        chk(writePointedThing(w, x))
                write16(w, uint16(len(x)))
                var b bytes.Buffer
                for i := range x {
-                       x[i].serialize(&b)
+                       x[i].Serialize(&b)
                }
                if b.Len() > math.MaxUint32 {
                        chk(ErrTooLong)