Skip to content

Commit

Permalink
add def.ErrUnsupportedLength as a error definition
Browse files Browse the repository at this point in the history
  • Loading branch information
shamaton committed Aug 25, 2024
1 parent 90d8baa commit ea02dc3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions def/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ var (
ErrLackDataLengthToSlice = fmt.Errorf("%wdata length lacks to create slice", ErrMsgpack)
ErrLackDataLengthToMap = fmt.Errorf("%wdata length lacks to create map", ErrMsgpack)
ErrUnsupportedType = fmt.Errorf("%wunsupported type", ErrMsgpack)
ErrUnsupportedLength = fmt.Errorf("%wunsupported length", ErrMsgpack)
ErrNotMatchLastIndex = fmt.Errorf("%wnot match last index", ErrMsgpack)
)
4 changes: 2 additions & 2 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (e *encoder) calcSize(rv reflect.Value) (int, error) {
ret += def.Byte4
} else {
// not supported error
return 0, fmt.Errorf("not support this array length : %d", l)
return 0, fmt.Errorf("array length %d is %w", l, def.ErrUnsupportedLength)
}

// func
Expand Down Expand Up @@ -201,7 +201,7 @@ func (e *encoder) calcSize(rv reflect.Value) (int, error) {
ret += def.Byte4
} else {
// not supported error
return 0, fmt.Errorf("not support this map length : %d", l)
return 0, fmt.Errorf("map length %d is %w", l, def.ErrUnsupportedLength)
}

if size, find := e.calcFixedMap(rv); find {
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e *encoder) calcStructArray(rv reflect.Value) (int, error) {
ret += def.Byte4
} else {
// not supported error
return 0, fmt.Errorf("not support this array length : %d", l)
return 0, fmt.Errorf("array length %d is %w", l, def.ErrUnsupportedLength)
}
return ret, nil
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (e *encoder) calcStructMap(rv reflect.Value) (int, error) {
ret += def.Byte4
} else {
// not supported error
return 0, fmt.Errorf("not support this array length : %d", l)
return 0, fmt.Errorf("map length %d is %w", l, def.ErrUnsupportedLength)
}
return ret, nil
}
Expand Down

0 comments on commit ea02dc3

Please sign in to comment.