extend Writable interface. WritableClass added
This commit is contained in:
parent
62a85e0392
commit
521d19d172
|
@ -3,7 +3,7 @@ package meta_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"git.bit5.ru/backend/meta/v3"
|
||||
"git.bit5.ru/backend/meta/v4"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module git.bit5.ru/backend/meta/v3
|
||||
module git.bit5.ru/backend/meta/v4
|
||||
|
||||
go 1.20
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ type Readable interface {
|
|||
type Writable interface {
|
||||
Write(Writer) error
|
||||
WriteFields(Writer) error
|
||||
FieldsCount() int
|
||||
}
|
||||
|
||||
type Struct interface {
|
||||
|
@ -77,7 +78,7 @@ type Struct interface {
|
|||
Writable
|
||||
}
|
||||
|
||||
type StructFactory func(classId uint32) (Struct, error)
|
||||
type StructFactory func(classId uint32) (Readable, error)
|
||||
|
||||
type Bitmasked interface {
|
||||
FieldChanged(index uint64) bool
|
||||
|
@ -85,3 +86,8 @@ type Bitmasked interface {
|
|||
HasChangedFields() bool
|
||||
FieldsMask() FieldsMask
|
||||
}
|
||||
|
||||
type WritableClass interface {
|
||||
Class
|
||||
Writable
|
||||
}
|
||||
|
|
12
meta.go
12
meta.go
|
@ -1,6 +1,6 @@
|
|||
package meta
|
||||
|
||||
func ReadStructGeneric(r Reader, createStruct StructFactory, field string) (Struct, error) {
|
||||
func ReadGeneric(r Reader, createFunc StructFactory, field string) (Readable, error) {
|
||||
if err := r.BeginContainer(field); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ func ReadStructGeneric(r Reader, createStruct StructFactory, field string) (Stru
|
|||
return nil, err
|
||||
}
|
||||
|
||||
s, err := createStruct(classId)
|
||||
s, err := createFunc(classId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.Read(r); err != nil {
|
||||
if err := s.ReadFields(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,14 @@ func ReadStructGeneric(r Reader, createStruct StructFactory, field string) (Stru
|
|||
return s, nil
|
||||
}
|
||||
|
||||
func WriteStructGeneric(w Writer, s Struct, field string) error {
|
||||
if err := w.BeginCollection(2, field); err != nil {
|
||||
func WriteGeneric(w Writer, s WritableClass, field string) error {
|
||||
if err := w.BeginCollection(s.FieldsCount()+1, field); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.WriteUint32(s.ClassId(), ""); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Write(w); err != nil {
|
||||
if err := s.WriteFields(w); err != nil {
|
||||
return err
|
||||
}
|
||||
return w.EndCollection()
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"git.bit5.ru/backend/meta/v3"
|
||||
"git.bit5.ru/backend/meta/v4"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"git.bit5.ru/backend/meta/v3"
|
||||
"git.bit5.ru/backend/meta/v4"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"git.bit5.ru/backend/meta/v3"
|
||||
"git.bit5.ru/backend/meta/v4"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package meta_test
|
||||
|
||||
import (
|
||||
"git.bit5.ru/backend/meta/v3"
|
||||
"git.bit5.ru/backend/meta/v4"
|
||||
)
|
||||
|
||||
type TestParent struct {
|
||||
|
|
Loading…
Reference in New Issue