Documentation

Init.Data.ByteArray.Basic

structure ByteArray :
Instances For
    @[extern lean_mk_empty_byte_array]
    Equations
      Instances For
        @[reducible, inline, deprecated ByteArray.emptyWithCapacity (since := "2025-03-12")]
        Equations
          Instances For
            Equations
              Instances For
                @[extern lean_byte_array_push]
                Equations
                  Instances For
                    @[extern lean_byte_array_size]
                    Equations
                      Instances For
                        @[extern lean_sarray_size]
                        Equations
                          Instances For
                            @[extern lean_byte_array_uget]
                            def ByteArray.uget (a : ByteArray) (i : USize) (h : i.toNat < a.size := by get_elem_tactic) :
                            Equations
                              Instances For
                                @[extern lean_byte_array_get]
                                Equations
                                  Instances For
                                    @[extern lean_byte_array_fget]
                                    def ByteArray.get (a : ByteArray) (i : Nat) (h : i < a.size := by get_elem_tactic) :
                                    Equations
                                      Instances For
                                        @[extern lean_byte_array_set]
                                        Equations
                                          Instances For
                                            @[extern lean_byte_array_fset]
                                            def ByteArray.set (a : ByteArray) (i : Nat) :
                                            UInt8(h : autoParam (i < a.size) _auto✝) → ByteArray
                                            Equations
                                              Instances For
                                                @[extern lean_byte_array_uset]
                                                def ByteArray.uset (a : ByteArray) (i : USize) :
                                                Equations
                                                  Instances For
                                                    @[extern lean_byte_array_hash]
                                                    Equations
                                                      Instances For
                                                        @[extern lean_byte_array_copy_slice]
                                                        def ByteArray.copySlice (src : ByteArray) (srcOff : Nat) (dest : ByteArray) (destOff len : Nat) (exact : Bool := true) :

                                                        Copy the slice at [srcOff, srcOff + len) in src to [destOff, destOff + len) in dest, growing dest if necessary. If exact is false, the capacity will be doubled when grown.

                                                        Equations
                                                          Instances For
                                                            Equations
                                                              Instances For
                                                                Equations
                                                                  Instances For
                                                                    Equations
                                                                      Instances For
                                                                        @[irreducible]
                                                                        Equations
                                                                          Instances For
                                                                            @[inline]
                                                                            def ByteArray.findIdx? (a : ByteArray) (p : UInt8Bool) (start : Nat := 0) :
                                                                            Equations
                                                                              Instances For
                                                                                @[irreducible, specialize #[]]
                                                                                Equations
                                                                                  Instances For
                                                                                    @[inline]
                                                                                    def ByteArray.findFinIdx? (a : ByteArray) (p : UInt8Bool) (start : Nat := 0) :
                                                                                    Equations
                                                                                      Instances For
                                                                                        @[irreducible, specialize #[]]
                                                                                        Equations
                                                                                          Instances For
                                                                                            @[inline]
                                                                                            unsafe def ByteArray.forInUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (b : β) (f : UInt8βm (ForInStep β)) :
                                                                                            m β

                                                                                            We claim this unsafe implementation is correct because an array cannot have more than usizeSz elements in our runtime. This is similar to the Array version.

                                                                                            TODO: avoid code duplication in the future after we improve the compiler.

                                                                                            Equations
                                                                                              Instances For
                                                                                                @[specialize #[]]
                                                                                                unsafe def ByteArray.forInUnsafe.loop {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (f : UInt8βm (ForInStep β)) (sz i : USize) (b : β) :
                                                                                                m β
                                                                                                Equations
                                                                                                  Instances For
                                                                                                    @[implemented_by ByteArray.forInUnsafe]
                                                                                                    def ByteArray.forIn {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (b : β) (f : UInt8βm (ForInStep β)) :
                                                                                                    m β

                                                                                                    Reference implementation for forIn

                                                                                                    Equations
                                                                                                      Instances For
                                                                                                        def ByteArray.forIn.loop {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (f : UInt8βm (ForInStep β)) (i : Nat) (h : i as.size) (b : β) :
                                                                                                        m β
                                                                                                        Equations
                                                                                                          Instances For
                                                                                                            instance ByteArray.instForInUInt8 {m : Type u_1 → Type u_2} :
                                                                                                            Equations
                                                                                                              @[inline]
                                                                                                              unsafe def ByteArray.foldlMUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
                                                                                                              m β

                                                                                                              See comment at forInUnsafe

                                                                                                              Equations
                                                                                                                Instances For
                                                                                                                  @[specialize #[]]
                                                                                                                  unsafe def ByteArray.foldlMUnsafe.fold {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (as : ByteArray) (i stop : USize) (b : β) :
                                                                                                                  m β
                                                                                                                  Equations
                                                                                                                    Instances For
                                                                                                                      @[implemented_by ByteArray.foldlMUnsafe]
                                                                                                                      def ByteArray.foldlM {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
                                                                                                                      m β

                                                                                                                      Reference implementation for foldlM

                                                                                                                      Equations
                                                                                                                        Instances For
                                                                                                                          def ByteArray.foldlM.loop {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (as : ByteArray) (stop : Nat) (h : stop as.size) (i j : Nat) (b : β) :
                                                                                                                          m β
                                                                                                                          Equations
                                                                                                                            Instances For
                                                                                                                              @[inline]
                                                                                                                              def ByteArray.foldl {β : Type v} (f : βUInt8β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
                                                                                                                              β
                                                                                                                              Equations
                                                                                                                                Instances For

                                                                                                                                  Iterator over the bytes (UInt8) of a ByteArray.

                                                                                                                                  Typically created by arr.iter, where arr is a ByteArray.

                                                                                                                                  An iterator is valid if the position i is valid for the array arr, meaning 0 ≤ i ≤ arr.size

                                                                                                                                  Most operations on iterators return arbitrary values if the iterator is not valid. The functions in the ByteArray.Iterator API should rule out the creation of invalid iterators, with two exceptions:

                                                                                                                                  • array : ByteArray

                                                                                                                                    The array the iterator is for.

                                                                                                                                  • idx : Nat

                                                                                                                                    The current position.

                                                                                                                                    This position is not necessarily valid for the array, for instance if one keeps calling Iterator.next when Iterator.atEnd is true. If the position is not valid, then the current byte is (default : UInt8).

                                                                                                                                  Instances For

                                                                                                                                    Creates an iterator at the beginning of an array.

                                                                                                                                    Equations
                                                                                                                                      Instances For
                                                                                                                                        @[reducible, inline]

                                                                                                                                        Creates an iterator at the beginning of an array.

                                                                                                                                        Equations
                                                                                                                                          Instances For

                                                                                                                                            The size of an array iterator is the number of bytes remaining.

                                                                                                                                            Equations

                                                                                                                                              Number of bytes remaining in the iterator.

                                                                                                                                              Equations
                                                                                                                                                Instances For

                                                                                                                                                  The current position.

                                                                                                                                                  This position is not necessarily valid for the array, for instance if one keeps calling Iterator.next when Iterator.atEnd is true. If the position is not valid, then the current byte is (default : UInt8).

                                                                                                                                                  Equations
                                                                                                                                                    Instances For
                                                                                                                                                      @[inline]

                                                                                                                                                      The byte at the current position.

                                                                                                                                                      On an invalid position, returns (default : UInt8).

                                                                                                                                                      Equations
                                                                                                                                                        Instances For
                                                                                                                                                          @[inline]

                                                                                                                                                          Moves the iterator's position forward by one byte, unconditionally.

                                                                                                                                                          It is only valid to call this function if the iterator is not at the end of the array, i.e. Iterator.atEnd is false; otherwise, the resulting iterator will be invalid.

                                                                                                                                                          Equations
                                                                                                                                                            Instances For
                                                                                                                                                              @[inline]

                                                                                                                                                              Decreases the iterator's position.

                                                                                                                                                              If the position is zero, this function is the identity.

                                                                                                                                                              Equations
                                                                                                                                                                Instances For
                                                                                                                                                                  @[inline]

                                                                                                                                                                  True if the iterator is past the array's last byte.

                                                                                                                                                                  Equations
                                                                                                                                                                    Instances For
                                                                                                                                                                      @[inline]

                                                                                                                                                                      True if the iterator is not past the array's last byte.

                                                                                                                                                                      Equations
                                                                                                                                                                        Instances For
                                                                                                                                                                          @[inline]

                                                                                                                                                                          The byte at the current position. -

                                                                                                                                                                          Equations
                                                                                                                                                                            Instances For
                                                                                                                                                                              @[inline]

                                                                                                                                                                              Moves the iterator's position forward by one byte. -

                                                                                                                                                                              Equations
                                                                                                                                                                                Instances For
                                                                                                                                                                                  @[inline]

                                                                                                                                                                                  True if the position is not zero.

                                                                                                                                                                                  Equations
                                                                                                                                                                                    Instances For
                                                                                                                                                                                      @[inline]

                                                                                                                                                                                      Moves the iterator's position to the end of the array.

                                                                                                                                                                                      Note that i.toEnd.atEnd is always true.

                                                                                                                                                                                      Equations
                                                                                                                                                                                        Instances For
                                                                                                                                                                                          @[inline]

                                                                                                                                                                                          Moves the iterator's position several bytes forward.

                                                                                                                                                                                          The resulting iterator is only valid if the number of bytes to skip is less than or equal to the number of bytes left in the iterator.

                                                                                                                                                                                          Equations
                                                                                                                                                                                            Instances For
                                                                                                                                                                                              @[inline]

                                                                                                                                                                                              Moves the iterator's position several bytes forward.

                                                                                                                                                                                              The resulting iterator is only valid if the number of bytes to skip is less than or equal to the number of bytes left in the iterator.

                                                                                                                                                                                              Equations
                                                                                                                                                                                                Instances For
                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                  Moves the iterator's position several bytes back.

                                                                                                                                                                                                  If asked to go back more bytes than available, stops at the beginning of the array.

                                                                                                                                                                                                  Equations
                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                      Converts a list of bytes into a ByteArray.

                                                                                                                                                                                                      Equations
                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                          Equations
                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                              Interpret a ByteArray of size 8 as a little-endian UInt64.

                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                Instances For

                                                                                                                                                                                                                  Interpret a ByteArray of size 8 as a big-endian UInt64.

                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                    Instances For