Пример #1
0
void MsgItem::MergeFrom(const MsgItem& from) {
  GOOGLE_CHECK_NE(&from, this);
  item_.MergeFrom(from.item_);
  if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    if (from._has_bit(0)) {
      set_sku(from.sku());
    }
    if (from._has_bit(1)) {
      set_position(from.position());
    }
    if (from._has_bit(3)) {
      set_sequence(from.sequence());
    }
    if (from._has_bit(4)) {
      set_counter(from.counter());
    }
    if (from._has_bit(5)) {
      set_quantity(from.quantity());
    }
    if (from._has_bit(6)) {
      set_timeleft(from.timeleft());
    }
  }
  mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
Пример #2
0
int main()
{
    ARY_TP arr[ARY_SZ]; /* = { 0 }; */
    /* print before initialization */
    print_array(arr);

    /* set all to 1 and print */
    set_ones(arr);
    print_array(arr);

    multiply_all(arr, 2);
    print_array(arr);

    /* set all to a sequence and print */
    set_sequence(arr);
    print_array(arr);

    multiply_all(arr, 10);
    print_array(arr);

    return 0;
}
Пример #3
0
/**
 * Send an edcl packet and fragment it if max_packet_size < data_size
 */
static int		send_fragmented(void)
{
	unsigned int		nb_ack_packet = 0;
	unsigned int		address_offset = 0;
	unsigned int		nb_sent_packet = 0;
	unsigned int		local_data_size = config.data_size;
	edcl_packet_t*		packet = NULL;

	/* Allocating the packet of the packet */
	packet = calloc(1, min(local_data_size, MAX_DATA_SIZE) + sizeof (edcl_header_t));
	if (packet == NULL)
		goto error_malloc;

	do {
		/* Filling up the edcl header */
		clear_header(packet->header);
		set_operation(packet->header, WRITE_OP);
		set_sequence(packet->header, config.sequence_number);
		set_address(packet->header, config.memory_address + address_offset);
		set_length(packet->header, min(local_data_size, MAX_DATA_SIZE));

		if (config.verbose)
			fprintf(stderr,
				" [%d] Trying to write at 0x%08x.",
				config.sequence_number,
				config.memory_address + address_offset);

		/* Copying the data in the packet */
		memcpy(packet->data,
		       config.data_c + address_offset,
		       min(local_data_size, MAX_DATA_SIZE));

		/* Sending the packet to the ethernet IP */
		if (sendto(config.socket,
			   packet,
			   min(local_data_size, MAX_DATA_SIZE) + sizeof (edcl_header_t),
			   0, config.serv_info->ai_addr, config.serv_info->ai_addrlen)
		    == -1)
			goto error_send;

		/* Waiting for the aknowledgment */
		if (recvfrom(config.socket,  packet,
			     sizeof (edcl_header_t) + min(local_data_size, MAX_DATA_SIZE),
			     0, NULL, 0) == -1)
			goto error_recvfrom;

		/* We've been aknowledge, keep sending */
		if (get_ack(packet->header)) {
			if (config.verbose)
				fprintf(stderr,
					"\t[OK]\n");
			address_offset += min(local_data_size, MAX_DATA_SIZE);
			local_data_size -= min(local_data_size, MAX_DATA_SIZE);
			++config.sequence_number;
			++nb_ack_packet;
		}
		/* The sequence number was wrong, fix it */
		else {
			if (config.verbose)
				fprintf(stderr,
					"\t[Failed]\n  Wrong sequence number (%d) should be: %d. Fixed.\n",
					config.sequence_number, get_sequence(packet->header));
			config.sequence_number = get_sequence(packet->header);
		}

		++nb_sent_packet;
	} while (local_data_size > 0);

	if (config.verbose) {
		fprintf(stderr,
			"The datas have been fragmented in %d packets.\n", nb_ack_packet);
		fprintf(stderr,
			"\t %d packets have been sent (%d have been lost).\n",
			nb_sent_packet,
			nb_sent_packet - nb_ack_packet);
	}

	/* Releasing ressources */
	free(packet);

	return (0);

 error_recvfrom:
 error_send:
	if (config.verbose)
		fprintf(stderr,
			"Error while sending the packet.\n");
	free(packet);
	return (errno);
 error_malloc:
	if (config.verbose)
		fprintf(stderr,
			"Unable to allocate the packet.\n");
	return (errno);
}
Пример #4
0
int 
call_moveto (int argc, char **argv)
{
	char pwd_flag = FALSE;
	char check_move = TRUE;
	int x;

	if (argc == 1) {
		Usage (argv[0]);
		return;
	}

	move_flag = FALSE;

	for (x = 1; x < argc; x++) {
		if (test_arg (argv[x],"-pwd",1))
			pwd_flag = TRUE;
		else if (test_arg (argv[x],"-nopwd",3))
			pwd_flag = FALSE;
		else if (test_arg (argv[x],"-check",1))
			check_move = TRUE;
		else if (test_arg (argv[x],"-nocheck",3))
			check_move = FALSE;
		else if (test_arg (argv[x], "-sequence",3)) {
			if (x + 1 == argc) {
				ps_printf (OPT, "We need a sequence name.\n");
				return;
			} else {
				shuffle_up (argc--, argv, x);
				set_sequence (argv[x]);
			}
		} else if (move (argv[x]) == OK) {
			if (move_flag == TRUE) {
				ps_print (RPS,"Too many parameters !\n");
				Usage (argv[0]);
				return;
			}
			move_flag = TRUE;
		} else {
			move_flag = FALSE;
			if (*argv[x] != '-')
				ps_printf (OPT,"Unknown entity '%s'\n",argv[x]);
			else
				Usage (argv[0]);
			return;
		}
	}

	if (check_move)
		if (test_move_dn() != TRUE) {
			move_flag = FALSE;
			return;
		}

	if (move_flag == TRUE)
		consolidate_move ();

	if (pwd_flag) {
		dn_print (RPS, fixed_pos, EDBOUT);
		ps_print (RPS, "\n");
	}

}