Documentation

Batteries.Data.ByteSlice

@[reducible, inline]
abbrev ByteSlice.isEmpty (s : ByteSlice) :
Bool

Test whether a byte slice is empty.

Equations
Instances For
    theorem ByteSlice.stop_eq_start_add_size (s : ByteSlice) :
    s.stop = s.start + s.size
    @[reducible, inline]
    abbrev ByteSlice.pop (s : ByteSlice) :
    ByteSlice

    Returns the subslice obtained by removing the last element.

    Equations
    • s.pop = s.slice 0 (s.size - 1)
    Instances For
      @[reducible, inline]
      abbrev ByteSlice.popFront (s : ByteSlice) :
      ByteSlice

      Returns the subslice obtained by removing the first element.

      Equations
      Instances For
        @[inline]
        def ByteSlice.foldlM {m : Type u_1 → Type u_2} {β : Type u_1} [Monad m] (s : ByteSlice) (f : βUInt8m β) (init : β) :
        m β

        Folds a monadic function over a ByteSubarray from left to right.

        Equations
        • s.foldlM f init = ByteArray.foldlM f init s.toByteArray s.start s.stop
        Instances For
          @[inline]
          def ByteSlice.foldl {β : Type u_1} (s : ByteSlice) (f : βUInt8β) (init : β) :
          β

          Folds a function over a ByteSubarray from left to right.

          Equations
          Instances For
            @[specialize #[]]
            def ByteSlice.forIn {m : Type u_1 → Type u_2} {β : Type u_1} [Monad m] (s : ByteSlice) (init : β) (f : UInt8βm (ForInStep β)) :
            m β

            Implementation of forIn for a ByteSlice.

            Equations
            Instances For
              def ByteSlice.forIn.loop {m : Type u_1 → Type u_2} {β : Type u_1} [Monad m] (s : ByteSlice) (f : UInt8βm (ForInStep β)) (i : Nat) (h : i s.size) (b : β) :
              m β

              Inner loop of the forIn implementation for ByteSlice.

              Equations
              Instances For
                @[implicit_reducible]
                instance ByteSlice.instForInUInt8OfMonad_batteries {m : Type u_1 → Type u_2} [Monad m] :
                ForIn m ByteSlice UInt8
                Equations
                @[implicit_reducible]
                instance ByteSlice.instStreamUInt8_batteries :
                Std.Stream ByteSlice UInt8
                Equations
                @[implicit_reducible]
                instance ByteSlice.instCoeByteArray_batteries :
                Coe ByteArray ByteSlice
                Equations
                @[deprecated ByteSlice (since := "2025-10-04")]

                A subarray of a ByteArray.

                • array : ByteArray

                  O(1). Get data array of a ByteSubarray.

                • start : Nat

                  O(1). Get start index of a ByteSubarray.

                • stop : Nat

                  O(1). Get stop index of a ByteSubarray.

                • start_le_stop : self.start self.stop

                  Start index is before stop index.

                • stop_le_array_size : self.stop self.array.size

                  Stop index is before end of data array.

                Instances For
                  @[deprecated ByteSlice.size (since := "2025-10-04")]

                  O(1). Get the size of a ByteSubarray.

                  Equations
                  Instances For
                    @[deprecated ByteSlice.isEmpty (since := "2025-10-04")]

                    O(1). Test if a ByteSubarray is empty.

                    Equations
                    Instances For
                      @[deprecated ByteSlice.stop_eq_start_add_size (since := "2025-10-04")]
                      @[deprecated ByteSlice.toByteArray (since := "2025-10-04")]

                      O(n). Extract a ByteSubarray to a ByteArray.

                      Equations
                      Instances For
                        @[inline, deprecated ByteSlice.get (since := "2025-10-04")]
                        def Batteries.ByteSubarray.get (self : ByteSubarray) (i : Fin self.size) :
                        UInt8

                        O(1). Get the element at index i from the start of a ByteSubarray.

                        Equations
                        Instances For
                          @[implicit_reducible]
                          instance Batteries.ByteSubarray.instGetElemNatUInt8LtSize :
                          GetElem ByteSubarray Nat UInt8 fun (self : ByteSubarray) (i : Nat) => i < self.size
                          Equations
                          @[inline, deprecated ByteSlice.pop (since := "2025-10-04")]

                          O(1). Pop the last element of a ByteSubarray.

                          Equations
                          • self.pop = if h : self.start = self.stop then self else { array := self.array, start := self.start, stop := self.stop - 1, start_le_stop := , stop_le_array_size := }
                          Instances For
                            @[inline, deprecated ByteSlice.popFront (since := "2025-10-04")]

                            O(1). Pop the first element of a ByteSubarray.

                            Equations
                            • self.popFront = if h : self.start = self.stop then self else { array := self.array, start := self.start + 1, stop := self.stop, start_le_stop := , stop_le_array_size := }
                            Instances For
                              @[inline, deprecated ByteSlice.foldlM (since := "2025-10-04")]
                              def Batteries.ByteSubarray.foldlM {m : Type u_1 → Type u_2} {β : Type u_1} [Monad m] (self : ByteSubarray) (f : βUInt8m β) (init : β) :
                              m β

                              Folds a monadic function over a ByteSubarray from left to right.

                              Equations
                              Instances For
                                @[inline, deprecated ByteSlice.foldl (since := "2025-10-04")]
                                def Batteries.ByteSubarray.foldl {β : Type u_1} (self : ByteSubarray) (f : βUInt8β) (init : β) :
                                β

                                Folds a function over a ByteSubarray from left to right.

                                Equations
                                Instances For
                                  @[specialize #[]]
                                  def Batteries.ByteSubarray.forIn {m : Type u_1 → Type u_2} {β : Type u_1} [Monad m] (self : ByteSubarray) (init : β) (f : UInt8βm (ForInStep β)) :
                                  m β

                                  Implementation of forIn for a ByteSubarray.

                                  Equations
                                  Instances For
                                    def Batteries.ByteSubarray.forIn.loop {m : Type u_1 → Type u_2} {β : Type u_1} [Monad m] (self : ByteSubarray) (f : UInt8βm (ForInStep β)) (i : Nat) (h : i self.size) (b : β) :
                                    m β

                                    Inner loop of the forIn implementation for ByteSubarray.

                                    Equations
                                    Instances For
                                      @[implicit_reducible]
                                      instance Batteries.ByteSubarray.instForInUInt8OfMonad {m : Type u_1 → Type u_2} [Monad m] :
                                      ForIn m ByteSubarray UInt8
                                      Equations
                                      @[implicit_reducible]
                                      Equations
                                      @[deprecated ByteArray.toByteSlice (since := "2025-10-04")]

                                      O(1). Coerce a byte array into a byte slice.

                                      Equations
                                      • array.toByteSubarray = { array := array, start := 0, stop := array.size, start_le_stop := , stop_le_array_size := }
                                      Instances For