Skip to content

Commit

Permalink
Merge pull request #43 from ashquarky/datastore-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniElectra authored Jun 22, 2024
2 parents 83aaa71 + fc7bc30 commit 0fe0889
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
15 changes: 10 additions & 5 deletions datastore/types/datastore_change_meta_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type DataStoreChangeMetaParam struct {
DataType *types.PrimitiveU16
Status *types.PrimitiveU8
CompareParam *DataStoreChangeMetaCompareParam
PersistenceTarget *DataStorePersistenceTarget
PersistenceTarget *DataStorePersistenceTarget // * Revision 1
}

// WriteTo writes the DataStoreChangeMetaParam to the given writable
Expand All @@ -44,7 +44,10 @@ func (dscmp *DataStoreChangeMetaParam) WriteTo(writable types.Writable) {
dscmp.DataType.WriteTo(contentWritable)
dscmp.Status.WriteTo(contentWritable)
dscmp.CompareParam.WriteTo(contentWritable)
dscmp.PersistenceTarget.WriteTo(contentWritable)

if dscmp.StructureVersion >= 1 {
dscmp.PersistenceTarget.WriteTo(contentWritable)
}

content := contentWritable.Bytes()

Expand Down Expand Up @@ -127,9 +130,11 @@ func (dscmp *DataStoreChangeMetaParam) ExtractFrom(readable types.Readable) erro
return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.CompareParam. %s", err.Error())
}

err = dscmp.PersistenceTarget.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.PersistenceTarget. %s", err.Error())
if dscmp.StructureVersion >= 1 {
err = dscmp.PersistenceTarget.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.PersistenceTarget. %s", err.Error())
}
}

return nil
Expand Down
22 changes: 11 additions & 11 deletions datastore/types/datastore_meta_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type DataStoreMetaInfo struct {
DataID *types.PrimitiveU64
OwnerID *types.PID
Size *types.PrimitiveU32
DataType *types.PrimitiveU16
Name *types.String
DataType *types.PrimitiveU16
MetaBinary *types.QBuffer
Permission *DataStorePermission
DelPermission *DataStorePermission
Expand All @@ -39,8 +39,8 @@ func (dsmi *DataStoreMetaInfo) WriteTo(writable types.Writable) {
dsmi.DataID.WriteTo(contentWritable)
dsmi.OwnerID.WriteTo(contentWritable)
dsmi.Size.WriteTo(contentWritable)
dsmi.DataType.WriteTo(contentWritable)
dsmi.Name.WriteTo(contentWritable)
dsmi.DataType.WriteTo(contentWritable)
dsmi.MetaBinary.WriteTo(contentWritable)
dsmi.Permission.WriteTo(contentWritable)
dsmi.DelPermission.WriteTo(contentWritable)
Expand Down Expand Up @@ -87,14 +87,14 @@ func (dsmi *DataStoreMetaInfo) ExtractFrom(readable types.Readable) error {
return fmt.Errorf("Failed to extract DataStoreMetaInfo.Size. %s", err.Error())
}

err = dsmi.DataType.ExtractFrom(readable)
err = dsmi.Name.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreMetaInfo.DataType. %s", err.Error())
return fmt.Errorf("Failed to extract DataStoreMetaInfo.Name. %s", err.Error())
}

err = dsmi.Name.ExtractFrom(readable)
err = dsmi.DataType.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreMetaInfo.Name. %s", err.Error())
return fmt.Errorf("Failed to extract DataStoreMetaInfo.DataType. %s", err.Error())
}

err = dsmi.MetaBinary.ExtractFrom(readable)
Expand Down Expand Up @@ -178,8 +178,8 @@ func (dsmi *DataStoreMetaInfo) Copy() types.RVType {
copied.DataID = dsmi.DataID.Copy().(*types.PrimitiveU64)
copied.OwnerID = dsmi.OwnerID.Copy().(*types.PID)
copied.Size = dsmi.Size.Copy().(*types.PrimitiveU32)
copied.DataType = dsmi.DataType.Copy().(*types.PrimitiveU16)
copied.Name = dsmi.Name.Copy().(*types.String)
copied.DataType = dsmi.DataType.Copy().(*types.PrimitiveU16)
copied.MetaBinary = dsmi.MetaBinary.Copy().(*types.QBuffer)
copied.Permission = dsmi.Permission.Copy().(*DataStorePermission)
copied.DelPermission = dsmi.DelPermission.Copy().(*DataStorePermission)
Expand Down Expand Up @@ -222,11 +222,11 @@ func (dsmi *DataStoreMetaInfo) Equals(o types.RVType) bool {
return false
}

if !dsmi.DataType.Equals(other.DataType) {
if !dsmi.Name.Equals(other.Name) {
return false
}

if !dsmi.Name.Equals(other.Name) {
if !dsmi.DataType.Equals(other.DataType) {
return false
}

Expand Down Expand Up @@ -301,8 +301,8 @@ func (dsmi *DataStoreMetaInfo) FormatToString(indentationLevel int) string {
b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsmi.DataID))
b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dsmi.OwnerID.FormatToString(indentationLevel+1)))
b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsmi.Size))
b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsmi.DataType))
b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dsmi.Name))
b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsmi.DataType))
b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dsmi.MetaBinary))
b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dsmi.Permission.FormatToString(indentationLevel+1)))
b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dsmi.DelPermission.FormatToString(indentationLevel+1)))
Expand Down Expand Up @@ -354,8 +354,8 @@ func NewDataStoreMetaInfo() *DataStoreMetaInfo {
DataID: types.NewPrimitiveU64(0),
OwnerID: types.NewPID(0),
Size: types.NewPrimitiveU32(0),
DataType: types.NewPrimitiveU16(0),
Name: types.NewString(""),
DataType: types.NewPrimitiveU16(0),
MetaBinary: types.NewQBuffer(nil),
Permission: NewDataStorePermission(),
DelPermission: NewDataStorePermission(),
Expand Down
52 changes: 37 additions & 15 deletions datastore/types/datastore_search_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
)

Expand All @@ -27,13 +28,16 @@ type DataStoreSearchParam struct {
ResultRange *types.ResultRange
ResultOption *types.PrimitiveU8
MinimalRatingFrequency *types.PrimitiveU32
UseCache *types.PrimitiveBool
TotalCountEnabled *types.PrimitiveBool
DataTypes *types.List[*types.PrimitiveU16]
UseCache *types.PrimitiveBool // * Revision 1 or NEX 4.0
TotalCountEnabled *types.PrimitiveBool // * Revision 3 or NEX 4.0
DataTypes *types.List[*types.PrimitiveU16] // * Revision 2 or NEX 4.0
}

// WriteTo writes the DataStoreSearchParam to the given writable
func (dssp *DataStoreSearchParam) WriteTo(writable types.Writable) {
stream := writable.(*nex.ByteStreamOut)
libraryVersion := stream.LibraryVersions.DataStore

contentWritable := writable.CopyNew()

dssp.SearchTarget.WriteTo(contentWritable)
Expand All @@ -52,9 +56,18 @@ func (dssp *DataStoreSearchParam) WriteTo(writable types.Writable) {
dssp.ResultRange.WriteTo(contentWritable)
dssp.ResultOption.WriteTo(contentWritable)
dssp.MinimalRatingFrequency.WriteTo(contentWritable)
dssp.UseCache.WriteTo(contentWritable)
dssp.TotalCountEnabled.WriteTo(contentWritable)
dssp.DataTypes.WriteTo(contentWritable)

if dssp.StructureVersion >= 1 || libraryVersion.GreaterOrEqual("4.0.0") {
dssp.UseCache.WriteTo(contentWritable)
}

if dssp.StructureVersion >= 3 || libraryVersion.GreaterOrEqual("4.0.0") {
dssp.TotalCountEnabled.WriteTo(contentWritable)
}

if dssp.StructureVersion >= 2 || libraryVersion.GreaterOrEqual("4.0.0") {
dssp.DataTypes.WriteTo(contentWritable)
}

content := contentWritable.Bytes()

Expand All @@ -65,6 +78,9 @@ func (dssp *DataStoreSearchParam) WriteTo(writable types.Writable) {

// ExtractFrom extracts the DataStoreSearchParam from the given readable
func (dssp *DataStoreSearchParam) ExtractFrom(readable types.Readable) error {
stream := readable.(*nex.ByteStreamIn)
libraryVersion := stream.LibraryVersions.DataStore

var err error

err = dssp.ExtractHeaderFrom(readable)
Expand Down Expand Up @@ -152,19 +168,25 @@ func (dssp *DataStoreSearchParam) ExtractFrom(readable types.Readable) error {
return fmt.Errorf("Failed to extract DataStoreSearchParam.MinimalRatingFrequency. %s", err.Error())
}

err = dssp.UseCache.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreSearchParam.UseCache. %s", err.Error())
if dssp.StructureVersion >= 1 || libraryVersion.GreaterOrEqual("4.0.0") {
err = dssp.UseCache.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreSearchParam.UseCache. %s", err.Error())
}
}

err = dssp.TotalCountEnabled.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreSearchParam.TotalCountEnabled. %s", err.Error())
if dssp.StructureVersion >= 3 || libraryVersion.GreaterOrEqual("4.0.0") {
err = dssp.TotalCountEnabled.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreSearchParam.TotalCountEnabled. %s", err.Error())
}
}

err = dssp.DataTypes.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreSearchParam.DataTypes. %s", err.Error())
if dssp.StructureVersion >= 2 || libraryVersion.GreaterOrEqual("4.0.0") {
err = dssp.DataTypes.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreSearchParam.DataTypes. %s", err.Error())
}
}

return nil
Expand Down

0 comments on commit 0fe0889

Please sign in to comment.