Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/vendor
_*
go.sum
go.sum
go.sum
go.work
vendor/
_*
benchmark*
.claude*
claude*
CLAUDE*
coverage*
11 changes: 8 additions & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
stdErrors "github.com/bdlm/std/v2/errors"
)

/*
Internal errors
*/
// Internal errors
var (
// InvalidIndex - The specified index does not exist.
InvalidIndex stdErrors.Error
Expand All @@ -26,11 +24,18 @@ var (
// InvalidDataSet - An attempt was made to store a data set that is
// with the model type
InvalidDataSet stdErrors.Error

// InvalidSortFlagCombination - The specified sort flag combination is
// invalid for this model type or in conflict with another flag.
// E.g. SortByKey and SortByValue.
InvalidSortFlagCombination stdErrors.Error
)

func init() {
InvalidIndex = errors.New("specified index does not exist")
InvalidIndexType = errors.New("an invalid index datatype was used")
InvalidMethodContext = errors.New("a method was used in an invalid context")
ReadOnlyProperty = errors.New("cannot update a read-only property")
InvalidDataSet = errors.New("invalid data set for model type")
InvalidSortFlagCombination = errors.New("invalid sort flag combination")
}
8 changes: 4 additions & 4 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import (
)

func ExampleNew() {
mdl := model.New(stdModel.ModelTypeHash)
mdl := model.New(stdModel.ModelTypeHash, nil)
json.Unmarshal(
[]byte(`{"key1":"value1","key2":2,"key3":["one","two","three"],"key4":{"k1":"v1","k2":"v2"}}`),
&mdl,
)
var key, val interface{}
var key, val any
for mdl.Next(&key, &val) {
if "key3" == key.(string) || "key4" == key.(string) {
var k2, v2 interface{}
var k2, v2 any
var m2 stdModel.Model
m2, _ = val.(stdModel.Value).Model()
if nil == m2 {
data, hash, index := mdl.Data()
data, hash, index := mdl.GetData()
log.Debugf("\n\n\ndata: %v\nhash: %v\nindex: %v\n\n\n", data, hash, index)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bdlm/model
go 1.26.2

require (
github.com/bdlm/cast/v2 v2.1.0
github.com/bdlm/cast/v2 v2.1.4
github.com/bdlm/errors/v2 v2.1.2
github.com/bdlm/log/v2 v2.0.7
github.com/bdlm/std/v2 v2.1.0
Expand Down
22 changes: 9 additions & 13 deletions interface.marshaler.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package model

/*
Marshaler is the interface implemented by types that can serialize
themselves into a static byte array.
*/
// Marshaler is the interface implemented by types that can serialize
// themselves into a static byte array.
type Marshaler interface {
MarshalModel() ([]byte, error)
}

/*
Unmarshaler is the interface implemented by Models that can unmarshal a
serialized description of themselves. The input can be assumed to be a valid
encoding of a Model value. UnmarshalModel must copy the data if it wishes to
retain the data after returning.

By convention, to approximate the behavior of similar functionality in other
packges, Unmarshalers implement UnmarshalModel([]byte("null")) as a no-op.
*/
// Unmarshaler is the interface implemented by Models that can unmarshal a
// serialized description of themselves. The input can be assumed to be a valid
// encoding of a Model value. UnmarshalModel must copy the data if it wishes to
// retain the data after returning.
//
// By convention, to approximate the behavior of similar functionality in other
// packages, Unmarshalers implement UnmarshalModel([]byte("null")) as a no-op.
type Unmarshaler interface {
UnmarshalModel(bytes []byte) error
}
Loading