def MessageEncoder(field_number, is_repeated, is_packed):
tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)<EOL>local_EncodeVarint = _EncodeVarint<EOL>assert not is_packed<EOL>if is_repeated:<EOL><INDENT>def EncodeRepeatedField(write, value):<EOL><INDENT>for element in value:<EOL><INDENT>write(tag)<EOL>local_EncodeVarint(write, element.ByteSize())<EOL>element._InternalSerialize(write)<EOL><DEDENT><DEDENT>return EncodeRepeatedField<EOL><DEDENT>else:<EOL><INDENT>def EncodeField(write, value):<EOL><INDENT>write(tag)<EOL>local_EncodeVarint(write, value.ByteSize())<EOL>return value._InternalSerialize(write)<EOL><DEDENT>return EncodeField<EOL><DEDENT>
Returns an encoder for a message field.