def write_vr_length(tag, vr, length)
      # Encode the length value (cover both scenarios of 2 and 4 bytes):
      length4 = @stream.encode(length, "SL")
      length2 = @stream.encode(length, "US")
      # Structure will differ, dependent on whether we have explicit or implicit encoding:
      # *****EXPLICIT*****:
      if @explicit == true
        # Step 1: Write VR (if it is to be written)
        unless ITEM_TAGS.include?(tag)
          # Write data element VR (2 bytes - since we are not dealing with an item related element):
          add_encoded(@stream.encode(vr, "STR"))
        end
        # Step 2: Write length
        # Three possible structures for value length here, dependent on data element vr:
        case vr
          when "OB","OW","OF","SQ","UN","UT"
            if @enc_image # (4 bytes)
              # Item under an encapsulated Pixel Data (7FE0,0010).
              add_encoded(length4)
            else # (6 bytes total)
              # Two reserved bytes first:
              add_encoded(@stream.encode("00"*2, "HEX"))
              # Value length (4 bytes):
              add_encoded(length4)
            end
          when ITEM_VR # (4 bytes)
            # For the item elements: "FFFE,E000", "FFFE,E00D" and "FFFE,E0DD"
            add_encoded(length4)
          else # (2 bytes)
            # For all the other data element vr, value length is 2 bytes:
            add_encoded(length2)
        end
      else
        # *****IMPLICIT*****:
        # No VR written.
        # Writing value length (4 bytes):
        add_encoded(length4)
      end
    end
def write_vr_length(tag, vr, length)
      # Encode the length value (cover both scenarios of 2 and 4 bytes):
      length4 = @stream.encode(length, "SL")
      length2 = @stream.encode(length, "US")
      # Structure will differ, dependent on whether we have explicit or implicit encoding:
      # *****EXPLICIT*****:
      if @explicit == true
        # Step 1: Write VR (if it is to be written)
        unless ITEM_TAGS.include?(tag)
          # Write data element VR (2 bytes - since we are not dealing with an item related element):
          add_encoded(@stream.encode(vr, "STR"))
        end
        # Step 2: Write length
        # Three possible structures for value length here, dependent on data element vr:
        case vr
          when "OB","OW","OF","SQ","UN","UT"
            if @enc_image # (4 bytes)
              # Item under an encapsulated Pixel Data (7FE0,0010).
              add_encoded(length4)
            else # (6 bytes total)
              # Two reserved bytes first:
              add_encoded(@stream.encode("00"*2, "HEX"))
              # Value length (4 bytes):
              add_encoded(length4)
            end
          when ITEM_VR # (4 bytes)
            # For the item elements: "FFFE,E000", "FFFE,E00D" and "FFFE,E0DD"
            add_encoded(length4)
          else # (2 bytes)
            # For all the other data element vr, value length is 2 bytes:
            add_encoded(length2)
        end
      else
        # *****IMPLICIT*****:
        # No VR written.
        # Writing value length (4 bytes):
        add_encoded(length4)
      end
    end
Encodes and writes the value representation (if it is to be written) and length value.
 The encoding scheme to be applied here depends on explicitness, data element type and vr.

 @param [String] tag the tag of this data element
 @param [String] vr the value representation of this data element
 @param [Integer] length the data element's length