def build_data_fragment(data_elements, presentation_context_id)
      # Set the transfer syntax to be used for encoding the data fragment:
      set_transfer_syntax(@presentation_contexts[presentation_context_id])
      # Endianness of data fragment:
      @outgoing.endian = @data_endian
      # Clear the outgoing binary string:
      @outgoing.reset
      # Build the last part first, the Data items:
      data_elements.each do |element|
        # Encode all tags (even tags which are empty):
        # Tag (4 bytes)
        @outgoing.add_last(@outgoing.encode_tag(element[0]))
        # Encode the value in advance of putting it into the message, so we know its length:
        vr = LIBRARY.element(element[0]).vr
        value = @outgoing.encode_value(element[1], vr)
        if @explicit
          # Type (VR) (2 bytes)
          @outgoing.encode_last(vr, "STR")
          # Length (2 bytes)
          @outgoing.encode_last(value.length, "US")
        else
          # Implicit:
          # Length (4 bytes)
          @outgoing.encode_last(value.length, "UL")
        end
        # Value (variable length)
        @outgoing.add_last(value)
      end
      # The rest of the data fragment will be built in reverse, all the time
      # putting the elements first in the outgoing binary string.
      # Big endian encoding from now on:
      @outgoing.endian = @net_endian
      # Flags (1 byte)
      @outgoing.encode_first("02", "HEX") # Data, last fragment (identifier)
      # Presentation context ID (1 byte)
      @outgoing.encode_first(presentation_context_id, "BY")
      # Length (of remaining data) (4 bytes)
      @outgoing.encode_first(@outgoing.string.length, "UL")
      # PRESENTATION DATA VALUE (the above)
      append_header(PDU_DATA)
    end
def build_data_fragment(data_elements, presentation_context_id)
      # Set the transfer syntax to be used for encoding the data fragment:
      set_transfer_syntax(@presentation_contexts[presentation_context_id])
      # Endianness of data fragment:
      @outgoing.endian = @data_endian
      # Clear the outgoing binary string:
      @outgoing.reset
      # Build the last part first, the Data items:
      data_elements.each do |element|
        # Encode all tags (even tags which are empty):
        # Tag (4 bytes)
        @outgoing.add_last(@outgoing.encode_tag(element[0]))
        # Encode the value in advance of putting it into the message, so we know its length:
        vr = LIBRARY.element(element[0]).vr
        value = @outgoing.encode_value(element[1], vr)
        if @explicit
          # Type (VR) (2 bytes)
          @outgoing.encode_last(vr, "STR")
          # Length (2 bytes)
          @outgoing.encode_last(value.length, "US")
        else
          # Implicit:
          # Length (4 bytes)
          @outgoing.encode_last(value.length, "UL")
        end
        # Value (variable length)
        @outgoing.add_last(value)
      end
      # The rest of the data fragment will be built in reverse, all the time
      # putting the elements first in the outgoing binary string.
      # Big endian encoding from now on:
      @outgoing.endian = @net_endian
      # Flags (1 byte)
      @outgoing.encode_first("02", "HEX") # Data, last fragment (identifier)
      # Presentation context ID (1 byte)
      @outgoing.encode_first(presentation_context_id, "BY")
      # Length (of remaining data) (4 bytes)
      @outgoing.encode_first(@outgoing.string.length, "UL")
      # PRESENTATION DATA VALUE (the above)
      append_header(PDU_DATA)
    end
Builds the binary string which is sent as a data fragment.

 === Notes

 * The style of encoding will depend on whether we have an implicit or explicit transfer syntax.

 === Parameters

 * <tt>data_elements</tt> -- An array of data elements.
 * <tt>presentation_context_id</tt> -- Presentation context ID byte (references a presentation context from the association).