Documentation
¶
Overview ¶
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Index ¶
- func ByteWidth(bitwidth uint) uint
- func ByteWidth16(value uint16) uint
- func ByteWidth32(value uint32) uint
- func ByteWidth64(value uint64) uint
- func TrimLeadingZeros(bytes []byte) []byte
- func Uint64[W Word[W]](value uint64) W
- type BigEndian
- func (p BigEndian) Add(o BigEndian) BigEndian
- func (p BigEndian) BigInt() *big.Int
- func (p BigEndian) ByteWidth() uint
- func (p BigEndian) Bytes() []byte
- func (p BigEndian) Cmp(o BigEndian) int
- func (p BigEndian) Cmp64(o uint64) int
- func (p BigEndian) Equals(o BigEndian) bool
- func (p BigEndian) FitsWithin(bitwidth uint) bool
- func (p *BigEndian) GobDecode(data []byte) error
- func (p *BigEndian) GobEncode() (data []byte, err error)
- func (p BigEndian) Hash() uint64
- func (p BigEndian) Inverse() BigEndian
- func (p BigEndian) IsOne() bool
- func (p BigEndian) IsZero() bool
- func (p BigEndian) Modulus() *big.Int
- func (p BigEndian) Mul(o BigEndian) BigEndian
- func (p BigEndian) PutBytes(bytes []byte) []byte
- func (p BigEndian) Rsh(n uint) BigEndian
- func (p BigEndian) SetBytes(bytes []byte) BigEndian
- func (p BigEndian) SetUint64(value uint64) BigEndian
- func (p BigEndian) String() string
- func (p BigEndian) Sub(o BigEndian) BigEndian
- func (p BigEndian) Text(base int) string
- func (p BigEndian) Uint64() uint64
- type DynamicWord
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteWidth ¶
ByteWidth returns the least number of bytes required to store an element of the given width.
func ByteWidth16 ¶
ByteWidth16 returns the bytewidth of the given uint16 value.
func ByteWidth32 ¶
ByteWidth32 returns the bytewidth of the given uint64 value.
func ByteWidth64 ¶
ByteWidth64 returns the bytewidth of the given uint64 value.
func TrimLeadingZeros ¶
TrimLeadingZeros any leading zeros from this array
Types ¶
type BigEndian ¶
type BigEndian struct {
// contains filtered or unexported fields
}
BigEndian captures the notion of an array of bytes represented in big endian form. This is really just a wrapper for convenience, and to help clarify the underlying byte order.
func NewBigEndian ¶
NewBigEndian constructs a new big endian byte array.
func (BigEndian) FitsWithin ¶
FitsWithin implementation for Word interface.
func (*BigEndian) GobEncode ¶
GobEncode a big endian word. This allows it to be marshalled into a binary form.
type DynamicWord ¶
type DynamicWord[T any] interface { Word[T] // Return minimal number of bytes required to store this word. This can be // defined as the length of bytes of this word, with all leading zero bytes // removed. For example, 0x1010 has a length of 2, 0x0010 has a length of 1 // whilst 0x0000 has a byte length of 0. Observe that, if the word is // encoded (e.g. in Montgomerry form), then this is the length of the // encoded bytes. ByteWidth() uint // Write contents of this word into given byte array. If the given byte // array is not big enough, a new array is allocated and returned. PutBytes([]byte) []byte }
DynamicWord is a word which has a dynamically sized representation, rather than a fixed-size representation. In particular, the dynamic word representing zero is always the empty byte array.
type Word ¶
type Word[T any] interface { fmt.Stringer // Return the value of this word as a big integer. BigInt() *big.Int // Cmp returns 1 if x > y, 0 if x = y, and -1 if x < y. Cmp(y T) int // Cmp64 returns 1 if x > y, 0 if x = y, and -1 if x < y. Cmp64(y uint64) int // Check whether two items are equal (or not). Equals(T) bool // Check whether this value fits within the given bitwidth. FitsWithin(uint) bool // Return a suitable hashcode. Hash() uint64 // Returns the raw bytes of this word. Observe that, if the word is encoded // (e.g. in Montgomerry form), then the *encoded* bytes are returned. Bytes() []byte // Check whether this word is zero, or not. IsZero() bool // Initialise this word from a set of raw bytes. SetBytes([]byte) T // Set this word to a uint64 value SetUint64(uint64) T // Returns value of word as an unsigned integer (truncated for 64bits). Uint64() uint64 }
Word abstracts a sequence of n bits.