Freeciv-3.3: generate_packets.Field Class Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Static Public Attributes
generate_packets.Field Class Reference

## Public Member Functions

"typing.Iterable[Field]" | parse (cls, ScriptConfig cfg, str line, typing.Callable[[str], RawFieldType] resolve_type)
| __init__ (self, ScriptConfig cfg, str name, FieldType type_info, FieldFlags flags)
bool | is_key (self)
bool | diff (self)
"typing.AbstractSet[str]" | all_caps (self)
bool | complex (self)
bool | is_compatible (self, "Field" other)
bool | present_with_caps (self, typing.Container[str] caps)
str | get_declaration (self)
str | get_param (self)
str | get_handle_arg (self, str packet)
str | get_init (self)
str | get_copy (self, str dest, str src)
str | get_fill (self)
str | get_free (self)
str | get_hash (self)
bool | folded_into_head (self)
str | get_cmp_wrapper (self, int i, "Variant" pack)
str | get_cmp (self)
str | get_put_wrapper (self, "Variant" packet, int index, bool deltafragment)
str | get_put (self, bool deltafragment)
str | get_put_real (self, bool deltafragment)
str | get_get_wrapper (self, "Variant" packet, int i, bool deltafragment)
str | get_get (self, bool deltafragment)
str | get_get_real (self, bool deltafragment)

## Data Fields

| cfg
| name
| type_info
| flags
| diff

## Static Public Attributes

| FIELDS_LINE_PATTERN = re.compile(, re.VERBOSE)
| FIELD_ARRAY_PATTERN = re.compile(r"^(.+)\[([^][]+)\]$")
dict | FORBIDDEN_NAMES = {"pid", "fields"}
ScriptConfig | cfg
str | name
FieldType | type_info
FieldFlags | flags

## Detailed Description

    A single field of a packet. Consists of a name, type information
    (including array sizes) and flags.

Definition at line 2090 of file generate_packets.py.

## Constructor & Destructor Documentation

## ◆ __init__()

generate_packets.Field.__init__ | ( |  | self,
|  | ScriptConfig | cfg,
|  | str | name,
|  | FieldType | type_info,
|  | FieldFlags | flags
| ) |  |

Definition at line 2172 of file generate_packets.py.

## Member Function Documentation

## ◆ all_caps()

"typing.AbstractSet[str]" generate_packets.Field.all_caps | ( |  | self | ) |

    Set of all capabilities affecting this field

Definition at line 2190 of file generate_packets.py.

## ◆ complex()

bool generate_packets.Field.complex | ( |  | self | ) |

    Whether this field's type requires special handling;
    see FieldType.complex

Definition at line 2195 of file generate_packets.py.

## ◆ diff()

bool generate_packets.Field.diff | ( |  | self | ) |

    Whether this field uses deep diff / array-diff when transmitted
    as part of a delta packet

Definition at line 2184 of file generate_packets.py.

## ◆ folded_into_head()

bool generate_packets.Field.folded_into_head | ( |  | self | ) |

    Whether this field is folded into the packet header.

    If enabled, lone booleans (which only carry one bit of information)
    get directly written into the `fields` bitvector, since they don't
    take any more space than the usual "content-differs" bit would.

    See also get_cmp_wrapper()

Definition at line 2268 of file generate_packets.py.

## ◆ get_cmp()

str generate_packets.Field.get_cmp | ( |  | self | ) |

    Generate code checking whether this field changed.

    This code is primarily used by self.get_cmp_wrapper()

Definition at line 2317 of file generate_packets.py.

## ◆ get_cmp_wrapper()

str generate_packets.Field.get_cmp_wrapper | ( |  | self,
|  | int | i,
|  | "Variant" | pack
| ) |  |

    Generate code setting this field's bit in the `fields` bitvector.

    This bit marks whether the field changed and is being transmitted,
    except for (non-array) boolean fields folded into the header;
    see self.folded_into_head for more details.

    See also self.get_cmp()

Definition at line 2281 of file generate_packets.py.

## ◆ get_copy()

str generate_packets.Field.get_copy | ( |  | self,
|  | str | dest,
|  | str | src
| ) |  |

    Generate code deep-copying this field from *src to *dest.

Definition at line 2248 of file generate_packets.py.

## ◆ get_declaration()

str generate_packets.Field.get_declaration | ( |  | self | ) |

    Generate the way this field is declared in the packet struct

Definition at line 2225 of file generate_packets.py.

## ◆ get_fill()

str generate_packets.Field.get_fill | ( |  | self | ) |

    Generate code shallow-copying this field from the dsend arguments
    into the packet struct.

Definition at line 2252 of file generate_packets.py.

## ◆ get_free()

str generate_packets.Field.get_free | ( |  | self | ) |

    Generate code deinitializing this field in the packet struct
    before destroying the packet.

Definition at line 2257 of file generate_packets.py.

## ◆ get_get()

str generate_packets.Field.get_get | ( |  | self,
|  | bool | deltafragment
| ) |  |

    Generate the code getting this field, i.e. reading it from the
    dataio stream.

    This does not include delta-related code checking if the field
    was transmitted in the first place; see self.get_get_wrapper()

Definition at line 2407 of file generate_packets.py.

## ◆ get_get_real()

str generate_packets.Field.get_get_real | ( |  | self,
|  | bool | deltafragment
| ) |  |

    Generate the bare core of this field's get code. This code is not
    yet wrapped for full delta and JSON protocol support.

    See self.get_get() for more info

Definition at line 2421 of file generate_packets.py.

## ◆ get_get_wrapper()

str generate_packets.Field.get_get_wrapper | ( |  | self,
|  | "Variant" | packet,
|  | int | i,
|  | bool | deltafragment
| ) |  |

    Generate code conditionally getting this field iff its bit in the
    `fields` bitvector is set.

    For boolean fields folded into the packet header, instead reads the
    field from the bitvector.

    See also self.get_get()

Definition at line 2381 of file generate_packets.py.

## ◆ get_handle_arg()

str generate_packets.Field.get_handle_arg | ( |  | self,
|  | str | packet
| ) |  |

    Generate the way this field is passed as an argument to a handle
    function.

    See also self.get_handle_param()

Definition at line 2236 of file generate_packets.py.

## ◆ get_hash()

str generate_packets.Field.get_hash | ( |  | self | ) |

    Generate code factoring this field into a hash computation.

Definition at line 2262 of file generate_packets.py.

## ◆ get_init()

str generate_packets.Field.get_init | ( |  | self | ) |

    Generate code initializing this field in the packet struct, after
    the struct has already been zeroed.

Definition at line 2243 of file generate_packets.py.

## ◆ get_param()

str generate_packets.Field.get_param | ( |  | self | ) |

    Generate the way this field is declared as a parameter of a
    handle or dsend function.

    See also self.get_handle_arg()

Definition at line 2229 of file generate_packets.py.

## ◆ get_put()

str generate_packets.Field.get_put | ( |  | self,
|  | bool | deltafragment
| ) |  |

    Generate the code putting this field, i.e. writing it to the
    dataio stream.

    This does not include delta-related code checking whether to
    transmit the field in the first place; see self.get_put_wrapper()

Definition at line 2355 of file generate_packets.py.

## ◆ get_put_real()

str generate_packets.Field.get_put_real | ( |  | self,
|  | bool | deltafragment
| ) |  |

    Generate the bare core of this field's put code. This code is not
    yet wrapped for full delta and JSON protocol support.

    See self.get_put() for more info

Definition at line 2374 of file generate_packets.py.

## ◆ get_put_wrapper()

str generate_packets.Field.get_put_wrapper | ( |  | self,
|  | "Variant" | packet,
|  | int | index,
|  | bool | deltafragment
| ) |  |

    Generate code conditionally putting this field iff its bit in the
    `fields` bitvector is set.

    Does nothing for boolean fields folded into the packet header.

    See also self.get_put()

Definition at line 2323 of file generate_packets.py.

## ◆ is_compatible()

bool generate_packets.Field.is_compatible | ( |  | self,
|  | "Field" | other
| ) |  |

    Whether two field objects are variants of the same field, i.e.
    type-compatible in the packet struct and mutually exclusive based
    on their required capabilities.

    Note that this function does not test field name.

Definition at line 2200 of file generate_packets.py.

## ◆ is_key()

bool generate_packets.Field.is_key | ( |  | self | ) |

    Whether this is a key field

Definition at line 2179 of file generate_packets.py.

## ◆ parse()

"typing.Iterable[Field]" generate_packets.Field.parse | ( |  | cls,
|  | ScriptConfig | cfg,
|  | str | line,
|  | typing.Callable[[str], RawFieldType] | resolve_type
| ) |  |

    Parse a single line defining one or more fields

Definition at line 2143 of file generate_packets.py.

## ◆ present_with_caps()

bool generate_packets.Field.present_with_caps | ( |  | self,
|  | typing.Container[str] | caps
| ) |  |

    Determine whether this field should be part of a variant with the
    given capabilities

Definition at line 2216 of file generate_packets.py.

## Field Documentation

## ◆ cfg [1/2]

ScriptConfig generate_packets.Field.cfg

static

Definition at line 2130 of file generate_packets.py.

## ◆ cfg [2/2]

generate_packets.Field.cfg

Definition at line 2173 of file generate_packets.py.

## ◆ diff

generate_packets.Field.diff

Definition at line 2426 of file generate_packets.py.

## ◆ FIELD_ARRAY_PATTERN

generate_packets.Field.FIELD_ARRAY_PATTERN = re.compile(r"^(.+)\[([^][]+)\]$")

static

Definition at line 2119 of file generate_packets.py.

## ◆ FIELDS_LINE_PATTERN

generate_packets.Field.FIELDS_LINE_PATTERN = re.compile(, re.VERBOSE)

static

Definition at line 2094 of file generate_packets.py.

## ◆ flags [1/2]

FieldFlags generate_packets.Field.flags

static

Definition at line 2139 of file generate_packets.py.

## ◆ flags [2/2]

generate_packets.Field.flags

Definition at line 2176 of file generate_packets.py.

## ◆ FORBIDDEN_NAMES

dict generate_packets.Field.FORBIDDEN_NAMES = {"pid", "fields"}

static

Definition at line 2126 of file generate_packets.py.

## ◆ name [1/2]

str generate_packets.Field.name

static

Definition at line 2133 of file generate_packets.py.

## ◆ name [2/2]

generate_packets.Field.name

Definition at line 2174 of file generate_packets.py.

## ◆ type_info [1/2]

FieldType generate_packets.Field.type_info

static

Definition at line 2136 of file generate_packets.py.

## ◆ type_info [2/2]

generate_packets.Field.type_info

Definition at line 2175 of file generate_packets.py.