code: func writeSegment(w io.Writer, msg segment) (err error) {
  	if !msg.typ.isValid() {
  		return fmt.Errorf("[writeSegment] msg.typ %d not defined", msg.typ)
  	}
  	buf := &bytes.Buffer{}
  	buf.WriteByte(byte(msg.typ))
  	//name
  	if msg.typ.hasName() {
  		err = writeString1(buf, msg.name)
  		if err != nil {
  			fmt.Printf("error returned from writeString1i \n")
  			return
  		}
  	}
  
  	if msg.typ.hasMsg() {
  		err = writeMap(buf, msg.msg)
  		if err != nil {
  			fmt.Printf("error retruned from writeMap \n")
  			return
  		}
  	}
  
  	//写长度
  	err = binary.Write(w, binary.BigEndian, uint32(buf.Len()))
  	if err != nil {
  		fmt.Printf("[writeSegment] error writing to binary \n")
  		return
  	}
  
  	_, err = buf.WriteTo(w)
  	if err != nil {
  		fmt.Printf("[writeSegment] error writing to buffer \n")
  		return
  	}
  
  	return nil
  }
docs: //msg 在内部以下列3种类型表示(降低复杂度)
  // string
  // map[string]interface{}
  // []string