stackitem: make Buffer
an alias to []byte
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
1dfef4ba26
commit
6879f76a13
1 changed files with 10 additions and 14 deletions
|
@ -1019,20 +1019,16 @@ func (p *Pointer) Position() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffer represents represents Buffer stack item.
|
// Buffer represents represents Buffer stack item.
|
||||||
type Buffer struct {
|
type Buffer []byte
|
||||||
value []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBuffer returns a new Buffer object.
|
// NewBuffer returns a new Buffer object.
|
||||||
func NewBuffer(b []byte) *Buffer {
|
func NewBuffer(b []byte) *Buffer {
|
||||||
return &Buffer{
|
return (*Buffer)(&b)
|
||||||
value: b,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements Item interface.
|
// Value implements Item interface.
|
||||||
func (i *Buffer) Value() interface{} {
|
func (i *Buffer) Value() interface{} {
|
||||||
return i.value
|
return []byte(*i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements fmt.Stringer interface.
|
// String implements fmt.Stringer interface.
|
||||||
|
@ -1047,7 +1043,7 @@ func (i *Buffer) TryBool() (bool, error) {
|
||||||
|
|
||||||
// TryBytes implements Item interface.
|
// TryBytes implements Item interface.
|
||||||
func (i *Buffer) TryBytes() ([]byte, error) {
|
func (i *Buffer) TryBytes() ([]byte, error) {
|
||||||
return i.value, nil
|
return *i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryInteger implements Item interface.
|
// TryInteger implements Item interface.
|
||||||
|
@ -1067,7 +1063,7 @@ func (i *Buffer) Dup() Item {
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface.
|
// MarshalJSON implements the json.Marshaler interface.
|
||||||
func (i *Buffer) MarshalJSON() ([]byte, error) {
|
func (i *Buffer) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(hex.EncodeToString(i.value))
|
return json.Marshal(hex.EncodeToString(*i))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type implements Item interface.
|
// Type implements Item interface.
|
||||||
|
@ -1081,12 +1077,12 @@ func (i *Buffer) Convert(typ Type) (Item, error) {
|
||||||
case BufferT:
|
case BufferT:
|
||||||
return i, nil
|
return i, nil
|
||||||
case ByteArrayT:
|
case ByteArrayT:
|
||||||
return NewByteArray(slice.Copy(i.value)), nil
|
return NewByteArray(slice.Copy(*i)), nil
|
||||||
case IntegerT:
|
case IntegerT:
|
||||||
if len(i.value) > MaxBigIntegerSizeBits/8 {
|
if len(*i) > MaxBigIntegerSizeBits/8 {
|
||||||
return nil, errTooBigInteger
|
return nil, errTooBigInteger
|
||||||
}
|
}
|
||||||
return NewBigInteger(bigint.FromBytes(i.value)), nil
|
return NewBigInteger(bigint.FromBytes(*i)), nil
|
||||||
default:
|
default:
|
||||||
return nil, mkInvConversion(i, typ)
|
return nil, mkInvConversion(i, typ)
|
||||||
}
|
}
|
||||||
|
@ -1094,7 +1090,7 @@ func (i *Buffer) Convert(typ Type) (Item, error) {
|
||||||
|
|
||||||
// Len returns length of Buffer value.
|
// Len returns length of Buffer value.
|
||||||
func (i *Buffer) Len() int {
|
func (i *Buffer) Len() int {
|
||||||
return len(i.value)
|
return len(*i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy returns new deep copy of the provided item.
|
// DeepCopy returns new deep copy of the provided item.
|
||||||
|
@ -1141,7 +1137,7 @@ func deepCopy(item Item, seen map[Item]Item) Item {
|
||||||
case *ByteArray:
|
case *ByteArray:
|
||||||
return NewByteArray(slice.Copy(*it))
|
return NewByteArray(slice.Copy(*it))
|
||||||
case *Buffer:
|
case *Buffer:
|
||||||
return NewBuffer(slice.Copy(it.value))
|
return NewBuffer(slice.Copy(*it))
|
||||||
case Bool:
|
case Bool:
|
||||||
return it
|
return it
|
||||||
case *Pointer:
|
case *Pointer:
|
||||||
|
|
Loading…
Reference in a new issue