def _FloatingPointEncoder(wire_type, format):
value_size = struct.calcsize(format)<EOL>if value_size == <NUM_LIT:4>:<EOL><INDENT>def EncodeNonFiniteOrRaise(write, value):<EOL><INDENT>if value == _POS_INF:<EOL><INDENT>write(b'<STR_LIT>')<EOL><DEDENT>elif value == _NEG_INF:<EOL><INDENT>write(b'<STR_LIT>')<EOL><DEDENT>elif value != value:           <EOL><INDENT>write(b'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>elif value_size == <NUM_LIT:8>:<EOL><INDENT>def EncodeNonFiniteOrRaise(write, value):<EOL><INDENT>if value == _POS_INF:<EOL><INDENT>write(b'<STR_LIT>')<EOL><DEDENT>elif value == _NEG_INF:<EOL><INDENT>write(b'<STR_LIT>')<EOL><DEDENT>elif value != value:                         <EOL><INDENT>write(b'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % value_size)<EOL><DEDENT>def SpecificEncoder(field_number, is_repeated, is_packed):<EOL><INDENT>local_struct_pack = struct.pack<EOL>if is_packed:<EOL><INDENT>tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)<EOL>local_EncodeVarint = _EncodeVarint<EOL>def EncodePackedField(write, value):<EOL><INDENT>write(tag_bytes)<EOL>local_EncodeVarint(write, len(value) * value_size)<EOL>for element in value:<EOL><INDENT>try:<EOL><INDENT>write(local_struct_pack(format, element))<EOL><DEDENT>except SystemError:<EOL><INDENT>EncodeNonFiniteOrRaise(write, element)<EOL><DEDENT><DEDENT><DEDENT>return EncodePackedField<EOL><DEDENT>elif is_repeated:<EOL><INDENT>tag_bytes = TagBytes(field_number, wire_type)<EOL>def EncodeRepeatedField(write, value):<EOL><INDENT>for element in value:<EOL><INDENT>write(tag_bytes)<EOL>try:<EOL><INDENT>write(local_struct_pack(format, element))<EOL><DEDENT>except SystemError:<EOL><INDENT>EncodeNonFiniteOrRaise(write, element)<EOL><DEDENT><DEDENT><DEDENT>return EncodeRepeatedField<EOL><DEDENT>else:<EOL><INDENT>tag_bytes = TagBytes(field_number, wire_type)<EOL>def EncodeField(write, value):<EOL><INDENT>write(tag_bytes)<EOL>try:<EOL><INDENT>write(local_struct_pack(format, value))<EOL><DEDENT>except SystemError:<EOL><INDENT>EncodeNonFiniteOrRaise(write, value)<EOL><DEDENT><DEDENT>return EncodeField<EOL><DEDENT><DEDENT>return SpecificEncoder<EOL>
Return a constructor for an encoder for float fields.

    This is like StructPackEncoder, but catches errors that may be due to
    passing non-finite floating-point values to struct.pack, and makes a
    second attempt to encode those values.

    Args:
        wire_type:  The field's wire type, for encoding tags.
        format:  The format string to pass to struct.pack().