Create array for mapping message Ids to proper structs
177608
def generate_message_mappings_array(outf, msgs):
    """"""

    classes = []
    for msg in msgs:
        classes.append("%u: %s.self" % (msg.id, msg.swift_name))
    t.write(outf, """



/**
    Array for mapping message id to proper struct
*/
private let messageIdToClass: [UInt8: Message.Type] = [${ARRAY_CONTENT}]
""", {'ARRAY_CONTENT' : ", ".join(classes)})
646759
def batch_message_from_parts(cls, messages):
        '''
        '''
        # Comma-separate the messages and wrap the lot in square brackets
        middle = b', '.join(messages)
        if not middle:
            raise ProtocolError.empty_batch()
        return b''.join([b'[', middle, b']'])
681691
def to_array(self):
        
        array = super(PassportElementErrorDataField, self).to_array()
        array['source'] = u(self.source)  # py2: type unicode, py3: type str
        array['type'] = u(self.type)  # py2: type unicode, py3: type str
        array['field_name'] = u(self.field_name)  # py2: type unicode, py3: type str
        array['data_hash'] = u(self.data_hash)  # py2: type unicode, py3: type str
        array['message'] = u(self.message)  # py2: type unicode, py3: type str
        return array
1335272
function (message) {
    var objs = [], collector = '', chr, msglen, data;

    this.data += message;
    data = new Buffer(this.data, 'utf8');

    for (var i = 0; i < data.length; i += 1) {
        chr = data[i];
        if (chr > 47 && chr < 58) {
            collector += String.fromCharCode(chr);
        } else if (chr !== 10 && chr !== 13) {
            msglen = parseInt(collector, 10);

            if (msglen + i <= data.length) {
              objs.push(JSON.parse(data.toString('utf8', i, msglen + i)));
              data = data.slice(i + msglen);
              collector = '';
              i = 0;
            } else {
              break;
            }
        }
    }
    this.data = data.toString('utf8');
    return objs;
}
997282
function sortMessages(messages) {
  var fileArray = {
    error: [],
    warning: []
  };

  messages.forEach(function (message) {
    if (message.severity === 1) {
      fileArray.warning.push(message);
    } else {
      fileArray.error.push(message);
    }
  });

  return lodash.concat(fileArray.error, fileArray.warning);
}
1339043
def generate_messages_info(msgs):
    """"""

    for msg in msgs:
        msg.swift_name = camel_case_from_underscores(msg.name)

        msg.formatted_description = ""
        if msg.description:
            msg.description = " ".join(msg.description.split())
            msg.formatted_description = "\n/**\n    %s\n*/\n" % " ".join(msg.description.split())
        msg.message_description = msg.description.replace('"','\\"')

        for field in msg.ordered_fields:
            field.swift_name = lower_camel_case_from_underscores(field.name)
            field.return_type = swift_types[field.type][0]
            
            # configure fields initializers
            if field.enum:
                # handle enums
                field.return_type = camel_case_from_underscores(field.enum)
                field.initial_value = "try data.mavEnumeration(offset: %u)" % field.wire_offset
            elif field.array_length > 0:
                if field.return_type == "String":
                    # handle strings
                    field.initial_value = "data." + swift_types[field.type][2] % (field.wire_offset, field.array_length)
                else:
                    # other array types
                    field.return_type = "[%s]" % field.return_type
                    field.initial_value = "try data.mavArray(offset: %u, count: %u)" % (field.wire_offset, field.array_length)
            else:
                # simple type field
                field.initial_value = "try data." + swift_types[field.type][2] % field.wire_offset
            
            field.formatted_description = ""
            if field.description:
                field.description = " ".join(field.description.split())
                field.formatted_description = "\n\t/// " + field.description + "\n"
         
        fields_info = map(lambda field: '("%s", %u, "%s", "%s")' % (field.swift_name, field.wire_offset, field.return_type, field.description.replace('"','\\"')), msg.fields)
        msg.fields_info = ", ".join(fields_info)

    msgs.sort(key = lambda msg : msg.id)
1336842
def _create_array(self, format, args):
        """"""

        builder = None
        if args is None or not args[0]:
            # empty value: we need to call _create() to parse the subtype,
            # and specify the element type precisely
            rest_format = self._create(format[1:], None)[1]
            element_type = format[:len(format) - len(rest_format)]
            builder = GLib.VariantBuilder.new(variant_type_from_string(element_type))
        else:
            builder = GLib.VariantBuilder.new(variant_type_from_string('a*'))
            for i in range(len(args[0])):
                (v, rest_format, _) = self._create(format[1:], args[0][i:])
                builder.add_value(v)
        if args is not None:
            args = args[1:]
        return (builder.end(), rest_format, args)
86193
function __serializeArray(data, options=DEFAULT_OPTIONS) {
	let dataBuffers = [];
	// ignore undefined value
	for (let key in data) {
		let subData = data[key];
		let subType = __getType(subData, options);
		let subTypeBuffer = __serializeType(subType);
		let subDataBuffers = __serializeData(subType, subData, options);
		dataBuffers.push(subTypeBuffer, ...subDataBuffers);
	}
	let length = __getLengthByArrayBuffers(dataBuffers);
	let lengthData = new Uint32Array([length]);
	return [lengthData.buffer, ...dataBuffers];
}
200362
def array_from_text(self, msg):
        """"""
        rows, columns = self.t.height, self.t.width
        return self.array_from_text_rc(msg, rows, columns)
444502
def do_struct(self, subcmd, opts, message):
        
        client = MdClient(self.maildir, filesystem=self.filesystem)
        as_json = getattr(opts, "json", False)
        client.getstruct(message, as_json=as_json, stream=self.stdout)
1043560
function toArray($user_message = true, $ignore = [])
    {
        $result = array(
            'code' => $this->code,
            'message' => $user_message ? $this->getUserMessage() : (empty($this->args)?$this->message:array($this->message, $this->args)),
            'children' => []
        );
        foreach ($this->children as $name => $e){
            if (!in_array($name, $ignore, true)){
                if ($e instanceof Error){
                    $result['children'][$name] = $e->toArray($user_message);
                }else{
                    /** @var $e Exception */
                    $result['children'][$name] = array(
                        'code' => $this->getCode(),
                        'message' => $this->getMessage(),
                    );
                }
            }
        }
        return $result;
    }
1367189
def from_array(array):
        
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")

        data = {}
        data['action'] = u(array.get('action'))
        if array.get('chat_id') is None:
            data['receiver'] = None
        elif isinstance(array.get('chat_id'), None):
            data['receiver'] = None(array.get('chat_id'))
        elif isinstance(array.get('chat_id'), str):
            data['receiver'] = u(array.get('chat_id'))
        elif isinstance(array.get('chat_id'), int):
            data['receiver'] = int(array.get('chat_id'))
        else:
            raise TypeError('Unknown type, must be one of None, str, int or None.')
        # end if
        return ChatActionMessage(**data)
950561
private function prepareMessages()
    {
        $prepared = [];

        foreach ($this->messages as $key => $msg) {
            $prepared[(string)$key] = $msg;
        }

        $this->messages = $prepared;
    }
1135873
def to_array(self):
        
        array = super(Chat, self).to_array()
        array['id'] = int(self.id)  # type int
        array['type'] = u(self.type)  # py2: type unicode, py3: type str

        if self.title is not None:
            array['title'] = u(self.title)  # py2: type unicode, py3: type str

        if self.username is not None:
            array['username'] = u(self.username)  # py2: type unicode, py3: type str

        if self.first_name is not None:
            array['first_name'] = u(self.first_name)  # py2: type unicode, py3: type str

        if self.last_name is not None:
            array['last_name'] = u(self.last_name)  # py2: type unicode, py3: type str

        if self.all_members_are_administrators is not None:
            array['all_members_are_administrators'] = bool(self.all_members_are_administrators)  # type bool
        if self.photo is not None:
            array['photo'] = self.photo.to_array()  # type ChatPhoto

        if self.description is not None:
            array['description'] = u(self.description)  # py2: type unicode, py3: type str

        if self.invite_link is not None:
            array['invite_link'] = u(self.invite_link)  # py2: type unicode, py3: type str

        if self.pinned_message is not None:
            array['pinned_message'] = self.pinned_message.to_array()  # type Message

        if self.sticker_set_name is not None:
            array['sticker_set_name'] = u(self.sticker_set_name)  # py2: type unicode, py3: type str

        if self.can_set_sticker_set is not None:
            array['can_set_sticker_set'] = bool(self.can_set_sticker_set)  # type bool
        return array
872023
function map(ary, each, done) {
  var result = new Array(ary.length);
  var next = after(ary.length, done);

  for (var i = 0; i < ary.length; i++) {
    each(ary[i], function(error, msg) {
      result[i] = msg;
      next(error, result);
    });
  }
}
914567
def _unpack_object_array(inp, source, prescatter):
    
    raise NotImplementedError("Currently not used with record/struct/object improvements")
    base_rec, attr = source.rsplit(".", 1)
    new_name = "%s_%s_unpack" % (inp["name"], base_rec.replace(".", "_"))
    prescatter[base_rec].append((new_name, attr, _to_variable_type(inp["type"]["items"])))
    return new_name, prescatter
882502
def _create_struct_table(self):
        """"""
        len_alph = len(self.alphabet)
        len_vocb = len(self.voc_structure)
        identificator_size = ceil(log(len_vocb, len_alph))
        # create list of lexems 
        num2alph = lambda x, n: self.alphabet[(x // len_alph**n) % len_alph]
        identificators = [[str(num2alph(x, n)) 
                           for n in range(identificator_size)
                          ] 
                          for x in range(len_vocb)
                         ]
        # initialize table and iterable
        identificators_table = {}
        zip_id_voc = zip_longest(
            identificators, self.voc_structure, 
            fillvalue=None
        )
        # create dict identificator:word
        for idt, word in zip_id_voc:
            identificators_table[''.join(idt)] = word
        return identificators_table, identificator_size