docstr: return new byteswapped object with given ``endianness``
  
  Guaranteed to make a copy even if endianness is the same as
  the current endianness.
  
  Parameters
  ----------
  endianness : None or string, optional
     endian code to which to swap.  None means swap from current
     endianness, and is the default
  
  Returns
  -------
  wstr : ``WrapStruct``
     ``WrapStruct`` object with given endianness
  
  Examples
  --------
  >>> wstr = WrapStruct()
  >>> wstr.endianness == native_code
  True
  >>> bs_wstr = wstr.as_byteswapped()
  >>> bs_wstr.endianness == swapped_code
  True
  >>> bs_wstr = wstr.as_byteswapped(swapped_code)
  >>> bs_wstr.endianness == swapped_code
  True
  >>> bs_wstr is wstr
  False
  >>> bs_wstr == wstr
  True
  
  If you write to the resulting byteswapped data, it does not
  change the original.
  
  >>> bs_wstr['integer'] = 3
  >>> bs_wstr == wstr
  False
  
  If you swap to the same endianness, it returns a copy
  
  >>> nbs_wstr = wstr.as_byteswapped(native_code)
  >>> nbs_wstr.endianness == native_code
  True
  >>> nbs_wstr is wstr
  False
docstr_tok: ["return","new","byteswapped","object","with","given","``","endianness","``","Guaranteed","to","make","a","copy","even","if","endianness","is","the","same","as","the","current","endianness",".","Parameters","--","--","--","--","--","endianness",":","None","or","string",",","optional","endian","code","to","which","to","swap",".","None","means","swap","from","current","endianness",",","and","is","the","default","Returns","--","--","--","-","wstr",":","``","WrapStruct","``","``","WrapStruct","``","object","with","given","endianness","Examples","--","--","--","--",">",">",">","wstr","=","WrapStruct","(",")",">",">",">","wstr.endianness","==","native_code","True",">",">",">","bs_wstr","=","wstr.as_byteswapped","(",")",">",">",">","bs_wstr.endianness","==","swapped_code","True",">",">",">","bs_wstr","=","wstr.as_byteswapped","(","swapped_code",")",">",">",">","bs_wstr.endianness","==","swapped_code","True",">",">",">","bs_wstr","is","wstr","False",">",">",">","bs_wstr","==","wstr","True","If","you","write","to","the","resulting","byteswapped","data",",","it","does","not","change","the","original",".",">",">",">","bs_wstr","[","'integer","'","]","=","3",">",">",">","bs_wstr","==","wstr","False","If","you","swap","to","the","same","endianness",",","it","returns","a","copy",">",">",">","nbs_wstr","=","wstr.as_byteswapped","(","native_code",")",">",">",">","nbs_wstr.endianness","==","native_code","True",">",">",">","nbs_wstr","is","wstr","False"]
code: def as_byteswapped(self, endianness=None):
      """return new byteswapped object with given ``endianness``
  
      Guaranteed to make a copy even if endianness is the same as
      the current endianness.
  
      Parameters
      ----------
      endianness : None or string, optional
         endian code to which to swap.  None means swap from current
         endianness, and is the default
  
      Returns
      -------
      wstr : ``WrapStruct``
         ``WrapStruct`` object with given endianness
  
      Examples
      --------
      >>> wstr = WrapStruct()
      >>> wstr.endianness == native_code
      True
      >>> bs_wstr = wstr.as_byteswapped()
      >>> bs_wstr.endianness == swapped_code
      True
      >>> bs_wstr = wstr.as_byteswapped(swapped_code)
      >>> bs_wstr.endianness == swapped_code
      True
      >>> bs_wstr is wstr
      False
      >>> bs_wstr == wstr
      True
  
      If you write to the resulting byteswapped data, it does not
      change the original.
  
      >>> bs_wstr['integer'] = 3
      >>> bs_wstr == wstr
      False
  
      If you swap to the same endianness, it returns a copy
  
      >>> nbs_wstr = wstr.as_byteswapped(native_code)
      >>> nbs_wstr.endianness == native_code
      True
      >>> nbs_wstr is wstr
      False
      """
      current = self.endianness
      if endianness is None:
          if current == native_code:
              endianness = swapped_code
          else:
              endianness = native_code
      else:
          endianness = endian_codes[endianness]
      if endianness == current:
          return self.copy()
      wstr_data = self._structarr.byteswap()
      return self.__class__(
          wstr_data.tobytes(), endianness, check=False
      )
  
imports: from __future__ import annotations
  import numpy
  from .None import imageglobals
  from .batteryrunners import BatteryRunner
  from .volumeutils import Recoder, endian_codes, native_code, pretty_mapping, swapped_code
label_desc: Use image node_id 22 for calling the WrapStruct obj's underlying member method code with example usage: obj.as_byteswapped(endianness) and returns: self, self