Skip to content
Merged
Changes from 1 commit
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
Next Next commit
py: make bytes implement __{i,}add__
Signed-off-by: Sebastien Binet <binet@cern.ch>
  • Loading branch information
sbinet committed May 9, 2022
commit 6d34733eef7c2fc0cecf06de6f0ccc07292eccce
24 changes: 23 additions & 1 deletion py/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,27 @@ func (a Bytes) M__ge__(other Object) (Object, error) {
return NotImplemented, nil
}

func (a Bytes) M__add__(other Object) (Object, error) {
if b, ok := convertToBytes(other); ok {
o := make([]byte, len(a)+len(b))
copy(o[:len(a)], a)
copy(o[len(a):], b)
return Bytes(o), nil
}
return NotImplemented, nil
}

func (a Bytes) M__iadd__(other Object) (Object, error) {
if b, ok := convertToBytes(other); ok {
a = append(a, b...)
return a, nil
}
return NotImplemented, nil
}

// Check interface is satisfied
var _ richComparison = (Bytes)(nil)
var (
_ richComparison = (Bytes)(nil)
_ I__add__ = (Bytes)(nil)
_ I__iadd__ = (Bytes)(nil)
)