meta/meta.go

41 lines
791 B
Go
Raw Permalink Normal View History

2023-09-01 01:37:06 +03:00
package meta
func ReadGeneric(r Reader, createFunc StructFactory, field string) (Readable, error) {
2023-09-01 01:37:06 +03:00
if err := r.BeginContainer(field); err != nil {
return nil, err
}
var classId uint32
if err := r.ReadUint32(&classId, ""); err != nil {
return nil, err
}
s, err := createFunc(classId)
2023-09-01 01:37:06 +03:00
if err != nil {
return nil, err
}
if err := s.ReadFields(r); err != nil {
2023-09-01 01:37:06 +03:00
return nil, err
}
if err := r.EndContainer(); err != nil {
return nil, err
}
return s, nil
}
func WriteGeneric(w Writer, s WritableClass, field string) error {
if err := w.BeginCollection(s.FieldsCount()+1, field); err != nil {
2023-09-01 01:37:06 +03:00
return err
}
if err := w.WriteUint32(s.ClassId(), ""); err != nil {
return err
}
if err := s.WriteFields(w); err != nil {
2023-09-01 01:37:06 +03:00
return err
}
return w.EndCollection()
}