TRE construction objects in sarpy.io.general.nitf_elements.tres.tre_elements

Module contained elements for defining TREs - really intended as read only objects.

class sarpy.io.general.nitf_elements.tres.tre_elements.TREElement

Bases: object

Basic TRE element class

add_field(attribute, typ_string, leng, value)

Add a field/attribute to the object - as we deserialize.

Parameters:
  • attribute (str) – The new field/attribute name for out object instance.

  • typ_string (str) – One of ‘s’ (string attribute), ‘d’ (integer attribute), or ‘b’ raw/bytes attribute

  • leng (int) – The length in bytes of the representation of this attribute

  • value (bytes) – The bytes array of the object we are deserializing

Return type:

None

add_loop(attribute, length, child_type, value, *args)

Add an attribute from a loop construct of a given type to the object - as we deserialize.

Parameters:
  • attribute (str) – The new field/attribute name for out object instance.

  • length (int) – The number of loop iterations present.

  • child_type (type) – The type of the child - must extend TREElement

  • value (bytes) – The bytes array of the object we are deserializing

  • args – Any optional positional arguments that the child_type constructor should have.

Return type:

None

to_dict()

Create a dictionary representation of the object.

Return type:

dict

get_bytes_length()

The length in bytes of the serialized representation.

Return type:

int

to_bytes()

Serialize to bytes.

Return type:

bytes

to_json()

Gets a json representation of this element.

Return type:

dict|list

class sarpy.io.general.nitf_elements.tres.tre_elements.TRELoop(length, child_type, value, start, *args, **kwargs)

Bases: TREElement

Provides the TRE loop construct

to_dict()

Create a dictionary representation of the object.

Return type:

dict

to_bytes()

Serialize to bytes.

Return type:

bytes

to_json()

Gets a json representation of this element.

Return type:

dict|list

add_field(attribute, typ_string, leng, value)

Add a field/attribute to the object - as we deserialize.

Parameters:
  • attribute (str) – The new field/attribute name for out object instance.

  • typ_string (str) – One of ‘s’ (string attribute), ‘d’ (integer attribute), or ‘b’ raw/bytes attribute

  • leng (int) – The length in bytes of the representation of this attribute

  • value (bytes) – The bytes array of the object we are deserializing

Return type:

None

add_loop(attribute, length, child_type, value, *args)

Add an attribute from a loop construct of a given type to the object - as we deserialize.

Parameters:
  • attribute (str) – The new field/attribute name for out object instance.

  • length (int) – The number of loop iterations present.

  • child_type (type) – The type of the child - must extend TREElement

  • value (bytes) – The bytes array of the object we are deserializing

  • args – Any optional positional arguments that the child_type constructor should have.

Return type:

None

get_bytes_length()

The length in bytes of the serialized representation.

Return type:

int

class sarpy.io.general.nitf_elements.tres.tre_elements.TREExtension(value)

Bases: TRE

Extend this object to provide concrete TRE implementations.

property TAG

The TRE tag.

Type:

str

property DATA: _data_type

The TRE data.

property EL

The TRE element length.

Type:

int

classmethod minimum_length()

The minimum size in bytes that takes to write this header element.

Return type:

int

get_bytes_length()

Get the length of the serialized bytes array

Return type:

int

to_bytes()

Write the object to a properly packed str.

Return type:

bytes

to_json()

Serialize element to a json representation. This is intended to allow a simple presentation of the element.

Return type:

dict

classmethod from_bytes(value, start)
Parameters:
  • value (bytes|str) – the header string to scrape

  • start (int) – the beginning location in the string