def _StructPackEncoder(wire_type, format):
value_size = struct.calcsize(format)<EOL>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>write(local_struct_pack(format, element))<EOL><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>write(local_struct_pack(format, element))<EOL><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>return write(local_struct_pack(format, value))<EOL><DEDENT>return EncodeField<EOL><DEDENT><DEDENT>return SpecificEncoder<EOL>
Return a constructor for an encoder for a fixed-width field.

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