Example #1
0
static void
dumpCineonChannelInfo(CineonChannelInformation* chan) {
	d_printf("	Metric selector: %d", chan->designator1);
	switch (chan->designator1) {
		case 0: d_printf(" (Universal)\n"); break;
		default: d_printf(" (Vendor specific)\n"); break;
	}
	d_printf("	Metric: %d,", chan->designator2);
	switch (chan->designator2) {
		case 0: d_printf(" B&W (printing density?)\n"); break;
		case 1: d_printf(" Red printing density\n"); break;
		case 2: d_printf(" Green printing density\n"); break;
		case 3: d_printf(" Blue printing density\n"); break;
		case 4: d_printf(" Red CCIR XA/11\n"); break;
		case 5: d_printf(" Green CCIR XA/11\n"); break;
		case 6: d_printf(" Blue CCIR XA/11\n"); break;
		default: d_printf(" (unknown)\n"); break;
	}
	d_printf("	Bits per pixel %d\n", chan->bits_per_pixel);
	d_printf("	Pixels per line %ld\n", (intptr_t)ntohl(chan->pixels_per_line));
	d_printf("	Lines per image %ld\n", (intptr_t)ntohl(chan->lines_per_image));
	d_printf("	Ref low data %ld\n", (intptr_t)ntohl(chan->ref_low_data));
	d_printf("	Ref low quantity %f\n", ntohf(chan->ref_low_quantity));
	d_printf("	Ref high data %ld\n", (intptr_t)ntohl(chan->ref_high_data));
	d_printf("	Ref high quantity %f\n", ntohf(chan->ref_high_quantity));
}
Example #2
0
File: dpxlib.c Project: jinjoh/NOOR
static void
dumpDpxChannelInfo(DpxChannelInformation* chan) {
	d_printf("	Signage %ld", (intptr_t)ntohl(chan->signage));
	d_printf("	Ref low data %ld\n", (intptr_t)ntohl(chan->ref_low_data));
	d_printf("	Ref low quantity %f\n", ntohf(chan->ref_low_quantity));
	d_printf("	Ref high data %ld\n", (intptr_t)ntohl(chan->ref_high_data));
	d_printf("	Ref high quantity %f\n", ntohf(chan->ref_high_quantity));
	d_printf("	Designator1: %d,", chan->designator1);
	d_printf("	Bits per pixel %d\n", chan->bits_per_pixel);
	d_printf("	Packing: %d,", ntohs(chan->packing));
	d_printf("	Data Offset: %ld,", (intptr_t)ntohl(chan->data_offset));
}
Example #3
0
File: dpxlib.c Project: jinjoh/NOOR
static void
dumpDpxOriginationInfo(DpxOriginationInformation* originInfo) {
	d_printf("\n--Origination Information--\n");
	d_printf("X offset %ld\n", (intptr_t)ntohl(originInfo->x_offset));
	d_printf("Y offset %ld\n", (intptr_t)ntohl(originInfo->y_offset));
	d_printf("X centre %f\n", ntohf(originInfo->x_centre));
	d_printf("Y centre %f\n", ntohf(originInfo->y_centre));
	d_printf("Original X %ld\n", (intptr_t)ntohl(originInfo->x_original_size));
	d_printf("Original Y %ld\n", (intptr_t)ntohl(originInfo->y_original_size));
	d_printf("File name \"%s\"\n", originInfo->file_name);
	d_printf("Creation time \"%s\"\n", originInfo->creation_time);
	d_printf("Input device \"%s\"\n", originInfo->input_device);
	d_printf("Serial number \"%s\"\n", originInfo->input_serial_number);
}
Example #4
0
static void
dumpCineonImageInfo(CineonImageInformation* imageInfo) {

	int i;
	d_printf("\n--Image Information--\n");
	d_printf("Image orientation %d,", imageInfo->orientation);
	switch (imageInfo->orientation) {
		case 0: d_printf(" LRTB\n"); break;
		case 1: d_printf(" LRBT\n"); break;
		case 2: d_printf(" RLTB\n"); break;
		case 3: d_printf(" RLBT\n"); break;
		case 4: d_printf(" TBLR\n"); break;
		case 5: d_printf(" TBRL\n"); break;
		case 6: d_printf(" BTLR\n"); break;
		case 7: d_printf(" BTRL\n"); break;
		default: d_printf(" (unknown)\n"); break;
	}
	d_printf("Channels %d\n", imageInfo->channels_per_image);
	for (i = 0; i < imageInfo->channels_per_image; ++i) {
		d_printf("	--Channel %d--\n", i);
		dumpCineonChannelInfo(&imageInfo->channel[i]);
	}

	d_printf("White point x %f\n", ntohf(imageInfo->white_point_x));
	d_printf("White point y %f\n", ntohf(imageInfo->white_point_y));
	d_printf("Red primary x %f\n", ntohf(imageInfo->red_primary_x));
	d_printf("Red primary y %f\n", ntohf(imageInfo->red_primary_y));
	d_printf("Green primary x %f\n", ntohf(imageInfo->green_primary_x));
	d_printf("Green primary y %f\n", ntohf(imageInfo->green_primary_y));
	d_printf("Blue primary x %f\n", ntohf(imageInfo->blue_primary_x));
	d_printf("Blue primary y %f\n", ntohf(imageInfo->blue_primary_y));
	d_printf("Label \"%s\"\n", imageInfo->label);
}
Example #5
0
static void
dumpCineonOriginationInfo(CineonOriginationInformation* originInfo) {
	d_printf("\n--Origination Information--\n");
	d_printf("X offset %ld\n", (intptr_t)ntohl(originInfo->x_offset));
	d_printf("Y offset %ld\n", (intptr_t)ntohl(originInfo->y_offset));
	d_printf("File name \"%s\"\n", originInfo->file_name);
	d_printf("Creation date \"%s\"\n", originInfo->create_date);
	d_printf("Creation time \"%s\"\n", originInfo->create_time);
	d_printf("Input device \"%s\"\n", originInfo->input_device);
	d_printf("Model number \"%s\"\n", originInfo->model_number);
	d_printf("Serial number \"%s\"\n", originInfo->serial_number);
	d_printf("Samples per mm in x %f\n", ntohf(originInfo->x_input_samples_per_mm));
	d_printf("Samples per mm in y %f\n", ntohf(originInfo->y_input_samples_per_mm));
	d_printf("Input device gamma %f\n", ntohf(originInfo->input_device_gamma));
}
Example #6
0
SVFloat
SV_BufferRemoveFloat (CDBuffer* self)
{
    SVFloat result = 0;

    evbuffer_remove(self->raw, &result, SVFloatSize);

    return ntohf(result);
}
Example #7
0
int main() {
    float f= 3.1415926;
    printf("the before float is:%f\n", f);
    uint32_t i = htonf(f);
    printf("the int is:%d\n", i);
    f = ntohf(i);
    printf("hte float is:%f\n", f);
    return 0;
}
Example #8
0
static u_char
show_vty_subtlv_use_bw (struct vty *vty, struct te_subtlv_use_bw *tlv)
{
  float fval;

  fval = ntohf (tlv->value);

  if (vty != NULL)
    vty_out (vty, "    Unidirectional Utilized Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
  else
    zlog_debug ("      Unidirectional Utilized Bandwidth: %g (Bytes/sec)", fval);

  return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE);
}
Example #9
0
static u_char
show_vty_subtlv_unrsv_bw (struct vty *vty, struct te_subtlv_unrsv_bw *tlv)
{
  float fval1, fval2;
  int i;

  if (vty != NULL)
    vty_out (vty, "    Unreserved Bandwidth:%s",VTY_NEWLINE);
  else
    zlog_debug ("      Unreserved Bandwidth:");

  for (i = 0; i < MAX_CLASS_TYPE; i+=2)
    {
      fval1 = ntohf (tlv->value[i]);
      fval2 = ntohf (tlv->value[i+1]);
      if (vty != NULL)
        vty_out (vty, "      [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s", i, fval1, i+1, fval2, VTY_NEWLINE);
      else
        zlog_debug ("        [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)", i, fval1, i+1, fval2);
    }

  return (SUBTLV_HDR_SIZE + TE_SUBTLV_UNRSV_SIZE);
}
Example #10
0
static u_char
show_vty_subtlv_max_rsv_bw (struct vty *vty, struct te_subtlv_max_rsv_bw *tlv)
{
  float fval;

  fval = ntohf (tlv->value);

  if (vty != NULL)
    vty_out (vty, "    Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval,
             VTY_NEWLINE);
  else
    zlog_debug ("      Maximum Reservable Bandwidth: %g (Bytes/sec)", fval);

  return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE);
}
Example #11
0
void dispatchFixedMessage(int operation, unsigned long param)
{
  if (VERBOSE) {
    fprintf(stderr,"Calling base operation %d\n",operation);
  }

  confirmCommandToClient(operation, param); /* sends a message back to all
					     * baseClients, confirming the
					     * command, sebastian 7-97 */

  switch(operation) {
    
    /**** GENERAL ****/ 
  case BASE_baseKill:		baseKill(); break;	
  case BASE_loadHeading:	loadHeading(param); break;	
  case BASE_loadPosition:	loadPosition(param); break;	
  case BASE_statusReportData:	statusReportData(param);break;
  case BASE_statusReportPeriod:	statusReportPeriod(param);break;
  case BASE_batteryVoltage:	batteryVoltage();break;
  case BASE_batteryCurrent:	batteryCurrent();break;

  case BASE_watchdogTimer:	watchdogTimer(param);break;
  case BASE_assumeWatchdog:	assumeWatchdog();break;


    /**** ROTATION ****/ 
  case BASE_rotateLimp:		rotateLimp(); break;
  case BASE_rotateHalt:		rotateHalt(); break;
  case BASE_rotateVelocityPos:	rotateVelocityPos(); break;	
  case BASE_rotateVelocityNeg:  rotateVelocityNeg(); break;	
  case BASE_rotateRelativePos:  rotateRelativePos(param); break;	
  case BASE_rotateRelativeNeg: 	rotateRelativeNeg(param); break;	
  case BASE_rotateTorquePos:	rotateTorquePos(param); break;	
  case BASE_rotateTorqueNeg: 	rotateTorqueNeg(param); break;	
  case BASE_rotatePowerPos:	rotatePowerPos(param); break;	
  case BASE_rotatePowerNeg: 	rotatePowerNeg(param); break;	
  case BASE_rotateToPosition: 	rotateToPosition(param); break;	
  case BASE_findRotIndex:
    if (bRobot.base_hasIndex) {
      findRotIndex();
    }
    else {
      sendClientFixed(BASE_indexReport, 0xFFFFFF);
    }
    break;

  case BASE_setRotateVelocity:	setRotateVelocity(param); break;	
  case BASE_setRotateAcceleration: setRotateAcceleration(param); break;	
  case BASE_setRotateFriction: 	setRotateFriction(param); break;	
  case BASE_setRotateSlope: 	setRotateSlope(param); break;	
  case BASE_setRotateTorque: 	setRotateTorque(param); break;	
  case BASE_setRotateZero: 	setRotateZero(param); break;	

  case BASE_rotateCurrent:	rotateCurrent(); break;	
  case BASE_rotateWhere:	rotateWhere(); break;	


    /**** TRANSLATION ****/ 
  case BASE_translateLimp:		translateLimp(); break;
  case BASE_translateHalt:		translateHalt(); break;
  case BASE_translateVelocityPos:  	translateVelocityPos(); break;	
  case BASE_translateVelocityNeg:  	translateVelocityNeg(); break;	
  case BASE_translateRelativePos:  	translateRelativePos(param); break;
  case BASE_translateRelativeNeg:  	translateRelativeNeg(param); break;
  case BASE_translateTorquePos:		translateTorquePos(param); break;
  case BASE_translateTorqueNeg: 	translateTorqueNeg(param); break;
  case BASE_translatePowerPos:		translatePowerPos(param); break;
  case BASE_translatePowerNeg: 		translatePowerNeg(param); break;
  case BASE_translateToPosition: 	translateToPosition(param); break;
  case BASE_setTranslateVelocity:	setTranslateVelocity(param); break;
  case BASE_setTranslateAcceleration: 	setTranslateAcceleration(param); break;
  case BASE_setTranslateSlope: 		setTranslateSlope(param); break;
  case BASE_setTranslateTorque: 	setTranslateTorque(param); break;
  case BASE_setTranslateZero: 		setTranslateZero(param); break;

  case BASE_translateCurrent:		translateCurrent(); break;	
  case BASE_translateWhere:		translateWhere(); break;	

  /**** SONARS ****/
  case BASE_sonarStart:                 SIM_sonarStart(); break;
  case BASE_sonarStop:                  SIM_sonarStop(); break;

  /**** Odometry stuff ****/
  case BASE_odometryChangeX:
    ntohf(param, bOriginX);
    sendClientFixed(BASE_odometryChangeX, param);
    break;
  case BASE_odometryChangeY:
    ntohf(param, bOriginY);
    sendClientFixed(BASE_odometryChangeY, param);
    break;
  case BASE_odometryChangeH:
    ntohf(param, bOriginHeading);
    sendClientFixed(BASE_odometryChangeH, param);
    break;

  /**** Odometry lock requests ****/
  case BASE_requestOdometryLock:
    requestOdometryLock((unsigned short)param);
    break;
  case BASE_releaseOdometryLock:
    releaseOdometryLock();
    break;

  default: 
    fprintf(stderr, "BaseServer: Operation %d not yet implemented.\n",
            operation); 	
  }
  
  if (VERBOSE) {
    fprintf(stderr,"Operation %d complete\n",operation);
  }
}
Example #12
0
// Deserialize the move server packet
void deserializeMoveServerPacket(MoveServerPacket *move_server_packet) {
  int i, j;

  // Server Config
  move_server_packet->server_config.num_image_slices = ntohl(move_server_packet->server_config.num_image_slices);
  move_server_packet->server_config.image_slice_format = ntohl(move_server_packet->server_config.image_slice_format);

  // Connection Config
  move_server_packet->client_config.ms_delay_between_standard_packets = ntohl(move_server_packet->client_config.ms_delay_between_standard_packets);
  move_server_packet->client_config.ms_delay_between_camera_frame_packets = ntohl(move_server_packet->client_config.ms_delay_between_camera_frame_packets);
  move_server_packet->client_config.camera_frame_packet_paused = ntohl(move_server_packet->client_config.camera_frame_packet_paused);

  // Camera
  move_server_packet->camera_state.exposure = ntohl(move_server_packet->camera_state.exposure);
  move_server_packet->camera_state.exposure_time = ntohf(move_server_packet->camera_state.exposure_time);
  move_server_packet->camera_state.gain = ntohf(move_server_packet->camera_state.gain);
  move_server_packet->camera_state.pitch_angle = ntohf(move_server_packet->camera_state.pitch_angle);
  move_server_packet->camera_state.pitch_angle_estimate = ntohf(move_server_packet->camera_state.pitch_angle_estimate);

  // Nav
  for (i = 0; i < MOVE_SERVER_MAX_NAVS; i++) {
    move_server_packet->pad_info.port_status[i] = ntohl(move_server_packet->pad_info.port_status[i]);

    // NavPadData
    move_server_packet->pad_data[i].len = ntohl(move_server_packet->pad_data[i].len);

    for (j = 0; j < CELL_PAD_MAX_CODES; j++) {
      move_server_packet->pad_data[i].button[j] = ntohs(move_server_packet->pad_data[i].button[j]);

    }

  }

  // Gems
  for (i = 0; i < MOVE_SERVER_MAX_GEMS; i++) {

    // Status
    move_server_packet->status[i].connected = ntohl(move_server_packet->status[i].connected);
    move_server_packet->status[i].code = ntohl(move_server_packet->status[i].code);
    move_server_packet->status[i].flags = ntohll(move_server_packet->status[i].flags);

    if (move_server_packet->status[i].connected == 1) {

      // State
      for (j = 0; j < 4; j++) {
        move_server_packet->state[i].pos[j] = ntohf(move_server_packet->state[i].pos[j]);
        move_server_packet->state[i].vel[j] = ntohf(move_server_packet->state[i].vel[j]);
        move_server_packet->state[i].accel[j] = ntohf(move_server_packet->state[i].accel[j]);
        move_server_packet->state[i].quat[j] = ntohf(move_server_packet->state[i].quat[j]);
        move_server_packet->state[i].angvel[j] = ntohf(move_server_packet->state[i].angvel[j]);
        move_server_packet->state[i].angaccel[j] = ntohf(move_server_packet->state[i].angaccel[j]);
        move_server_packet->state[i].handle_pos[j] = ntohf(move_server_packet->state[i].handle_pos[j]);
        move_server_packet->state[i].handle_vel[j] = ntohf(move_server_packet->state[i].handle_vel[j]);
        move_server_packet->state[i].handle_accel[j] = ntohf(move_server_packet->state[i].handle_accel[j]);

      }

      move_server_packet->state[i].timestamp = (system_time_t)ntohll((uint64_t)move_server_packet->state[i].timestamp);
      move_server_packet->state[i].temperature = ntohf(move_server_packet->state[i].temperature);
      move_server_packet->state[i].camera_pitch_angle = ntohf(move_server_packet->state[i].camera_pitch_angle);
      move_server_packet->state[i].tracking_flags = ntohl(move_server_packet->state[i].tracking_flags);

      // Pad
      move_server_packet->state[i].pad.digital_buttons = ntohs(move_server_packet->state[i].pad.digital_buttons);
      move_server_packet->state[i].pad.analog_trigger = ntohs(move_server_packet->state[i].pad.analog_trigger);

      // Image State
      move_server_packet->image_state[i].frame_timestamp = (system_time_t)ntohll((uint64_t)move_server_packet->image_state[i].frame_timestamp);
      move_server_packet->image_state[i].timestamp = (system_time_t)ntohll((uint64_t)move_server_packet->image_state[i].timestamp);
      move_server_packet->image_state[i].u = ntohf(move_server_packet->image_state[i].u);
      move_server_packet->image_state[i].v = ntohf(move_server_packet->image_state[i].v);
      move_server_packet->image_state[i].r = ntohf(move_server_packet->image_state[i].r);
      move_server_packet->image_state[i].projectionx = ntohf(move_server_packet->image_state[i].projectionx);
      move_server_packet->image_state[i].projectiony = ntohf(move_server_packet->image_state[i].projectiony);
      move_server_packet->image_state[i].distance = ntohf(move_server_packet->image_state[i].distance);

      // Sphere State
      move_server_packet->sphere_state[i].tracking = ntohl(move_server_packet->sphere_state[i].tracking);
      move_server_packet->sphere_state[i].tracking_hue = ntohl(move_server_packet->sphere_state[i].tracking_hue);
      move_server_packet->sphere_state[i].r = ntohf(move_server_packet->sphere_state[i].r);
      move_server_packet->sphere_state[i].g = ntohf(move_server_packet->sphere_state[i].g);
      move_server_packet->sphere_state[i].b = ntohf(move_server_packet->sphere_state[i].b);

      // Pointer State
      move_server_packet->pointer_state[i].valid = ntohl(move_server_packet->pointer_state[i].valid);
      move_server_packet->pointer_state[i].normalized_x = ntohf(move_server_packet->pointer_state[i].normalized_x);
      move_server_packet->pointer_state[i].normalized_y = ntohf(move_server_packet->pointer_state[i].normalized_y);

      // Position Pointer State
      move_server_packet->position_pointer_state[i].valid = ntohl(move_server_packet->position_pointer_state[i].valid);
      move_server_packet->position_pointer_state[i].normalized_x = ntohf(move_server_packet->position_pointer_state[i].normalized_x);
      move_server_packet->position_pointer_state[i].normalized_y = ntohf(move_server_packet->position_pointer_state[i].normalized_y);

    }

  }

}
 void LCMDeserializerVisitor::read(const uint32_t &/*id*/, const string &/*longName*/, const string &/*shortName*/, float &v) {
     float _v = 0;
     m_buffer.read(reinterpret_cast<char *>(&_v), sizeof(float));
     v = ntohf(_v);
 }
Example #14
0
void group_moves_synch_with_host(network_reply_group_synch *synch)
{
	int				group_idx,flags;
	d3pnt			cuml_mov_add;
	d3ang			cuml_rot_add;
	group_type		*group;

		// get the group

	group_idx=(int)ntohs(synch->group_idx);
	group=&map.group.groups[group_idx];

		// fix the movement

	flags=ntohl(synch->flags);

	group->run.on=((flags&net_group_synch_flag_on)!=0);
	group->run.freeze=((flags&net_group_synch_flag_freeze)!=0);
	group->run.main_move=((flags&net_group_synch_flag_main_move)!=0);

	group->run.count=(int)ntohs(synch->count);
	group->run.user_id=(int)ntohs(synch->user_id);
	group->run.movement_idx=(int)ntohs(synch->movement_idx);
	group->run.movement_move_idx=(int)ntohs(synch->movement_move_idx);

	group->run.f_mov_add.x=ntohf(synch->fp_mov_add_x);
	group->run.f_mov_add.y=ntohf(synch->fp_mov_add_y);
	group->run.f_mov_add.z=ntohf(synch->fp_mov_add_z);
	
	group->run.f_mov_accum_add.x=ntohf(synch->fp_mov_accum_add_x);
	group->run.f_mov_accum_add.y=ntohf(synch->fp_mov_accum_add_y);
	group->run.f_mov_accum_add.z=ntohf(synch->fp_mov_accum_add_z);

	group->run.rot_add.x=ntohf(synch->fp_rot_add_x);
	group->run.rot_add.y=ntohf(synch->fp_rot_add_y);
	group->run.rot_add.z=ntohf(synch->fp_rot_add_z);

		// synch the commulative moves

		// if there's already been movement, get rid
		// of that before synching all commulative
		// movement

	cuml_mov_add.x=ntohl(synch->cuml_mov_add_x)-group->run.cuml_mov_add.x;
	cuml_mov_add.y=ntohl(synch->cuml_mov_add_y)-group->run.cuml_mov_add.y;
	cuml_mov_add.z=ntohl(synch->cuml_mov_add_z)-group->run.cuml_mov_add.z;

	cuml_rot_add.x=ntohf(synch->fp_cuml_rot_add_x)-group->run.cuml_rot_add.x;
	cuml_rot_add.y=ntohf(synch->fp_cuml_rot_add_y)-group->run.cuml_rot_add.y;
	cuml_rot_add.z=ntohf(synch->fp_cuml_rot_add_z)-group->run.cuml_rot_add.z;

	group_move_and_rotate(group,&cuml_mov_add,&cuml_rot_add,FALSE);
}
Example #15
0
size_t Variant::deserialize(const unsigned char *buffer, size_t size)
{
    if (buffer != NULL && size > 0)
    {
        Variant::Type type = static_cast<Variant::Type>(*buffer);
        ++buffer;

        switch (type)
        {
            case UINT8:
            {
                typedef uint8_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setUint8(static_cast<Type>(*buffer));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case INT8:
            {
                typedef uint8_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setInt8(static_cast<Type>(*buffer));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case UINT16:
            {
                typedef uint16_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setUint16(ntohs(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case INT16:
            {
                typedef int16_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setInt16(ntohs(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case UINT32:
            {
                typedef uint32_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setUint32(ntohl(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case INT32:
            {
                typedef int32_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setInt32(ntohl(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case UINT64:
            {
                typedef uint64_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setUint64(ntohll(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case INT64:
            {
                typedef int64_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setInt64(ntohll(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case FLOAT:
            {
                typedef uint32_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setFloat(ntohf(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case DOUBLE:
            {
                typedef uint64_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setDouble(ntohd(*reinterpret_cast<const Type *>(buffer)));
                    size = sizeof(Type) + 1;
                }
                break;
            }

            case BOOL:
            {
                typedef bool Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setBool(*reinterpret_cast<const Type *>(buffer));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case CHAR:
            {
                typedef char Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    setChar(*reinterpret_cast<const Type *>(buffer));
                    size = sizeof(Type) + 1;
                }

                break;
            }

            case STRING:
            {
                typedef uint32_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    Type len = ntohl(*reinterpret_cast<const Type *>(buffer));

                    if (len > 0 && len <= ((size - 1) - sizeof(Type)))
                        setString(reinterpret_cast<const char *>(buffer + sizeof(Type)), len);

                    size = sizeof(Type) + 1 + len;
                }

                break;
            }

            case BINARY:
            {
                typedef uint32_t Type;

                if ((size - 1) < sizeof(Type))
                    return 0;
                else
                {
                    Type len = ntohl(*reinterpret_cast<const Type *>(buffer));

                    if (len > 0 && len <= ((size - 1) - sizeof(Type)))
                        setBinary(reinterpret_cast<const unsigned char *>(buffer + sizeof(Type)), len);

                    size = sizeof(Type) + 1 + len;
                }

                break;
            }
        }

        return size;
    }

    return 0;
}
Example #16
0
/**
 * R T _ B I N U N I F _ I M P O R T 5
 *
 * Import a uniform-array binary object from the database format to
 * the internal structure.
 */
int
rt_binunif_import5( struct rt_db_internal	*ip,
		    const struct bu_external	*ep,
		    const mat_t			mat,
		    const struct db_i		*dbip,
		    struct resource		*resp,
		    const int			minor_type)
{
    struct rt_binunif_internal	*bip;
    int				i;
    unsigned char			*srcp;
    unsigned long			*ldestp;
    int				in_cookie, out_cookie;
    int				gotten;

    BU_CK_EXTERNAL( ep );

    /*
     * There's no particular size to expect
     *
     * BU_ASSERT_LONG( ep->ext_nbytes, ==, SIZEOF_NETWORK_DOUBLE * 3*4 );
     */

    RT_CK_DB_INTERNAL( ip );
    ip->idb_major_type = DB5_MAJORTYPE_BINARY_UNIF;
    ip->idb_minor_type = minor_type;
    ip->idb_meth = &rt_functab[ID_BINUNIF];
    ip->idb_ptr = bu_malloc( sizeof(struct rt_binunif_internal),
			     "rt_binunif_internal");

    bip = (struct rt_binunif_internal *)ip->idb_ptr;
    bip->magic = RT_BINUNIF_INTERNAL_MAGIC;
    bip->type = minor_type;

    /*
     * Convert from database (network) to internal (host) format
     */
    switch (bip->type) {
	case DB5_MINORTYPE_BINU_FLOAT:
	    bip->count = ep->ext_nbytes/SIZEOF_NETWORK_FLOAT;
	    bip->u.uint8 = (unsigned char *) bu_malloc( bip->count * sizeof(float),
							"rt_binunif_internal" );
	    ntohf( (unsigned char *) bip->u.uint8,
		   ep->ext_buf, bip->count );
	    break;
	case DB5_MINORTYPE_BINU_DOUBLE:
	    bip->count = ep->ext_nbytes/SIZEOF_NETWORK_DOUBLE;
	    bip->u.uint8 = (unsigned char *) bu_malloc( bip->count * sizeof(double),
							"rt_binunif_internal" );
	    ntohd( (unsigned char *) bip->u.uint8,
		   ep->ext_buf, bip->count );
	    break;
	case DB5_MINORTYPE_BINU_8BITINT:
	case DB5_MINORTYPE_BINU_8BITINT_U:
	    bip->count = ep->ext_nbytes;
	    bip->u.uint8 = (unsigned char *) bu_malloc( ep->ext_nbytes,
							"rt_binunif_internal" );
	    memcpy((char *) bip->u.uint8, (char *) ep->ext_buf, ep->ext_nbytes);
	    break;
	case DB5_MINORTYPE_BINU_16BITINT:
	case DB5_MINORTYPE_BINU_16BITINT_U:
	    bip->count = ep->ext_nbytes/2;
	    bip->u.uint8 = (unsigned char *) bu_malloc( ep->ext_nbytes,
							"rt_binunif_internal" );
#if 0
	    srcp = (unsigned char *) ep->ext_buf;
	    sdestp = (unsigned short *) bip->u.uint8;
	    for (i = 0; i < bip->count; ++i, ++sdestp, srcp += 2) {
		*sdestp = bu_gshort( srcp );
		bu_log("Just got %d", *sdestp);
	    }
#endif
	    in_cookie = bu_cv_cookie("nus");
	    out_cookie = bu_cv_cookie("hus");
	    if (bu_cv_optimize(in_cookie) != bu_cv_optimize(out_cookie)) {
		gotten =
		    bu_cv_w_cookie((genptr_t)bip->u.uint8, out_cookie,
				   ep->ext_nbytes,
				   ep->ext_buf, in_cookie, bip->count);
		if (gotten != bip->count) {
		    bu_log("%s:%d: Tried to convert %d, did %d",
			   __FILE__, __LINE__, bip->count, gotten);
		    bu_bomb("\n");
		}
	    } else
		memcpy((char *) bip->u.uint8,
		       (char *) ep->ext_buf,
		       ep->ext_nbytes );
	    break;
	case DB5_MINORTYPE_BINU_32BITINT:
	case DB5_MINORTYPE_BINU_32BITINT_U:
	    bip->count = ep->ext_nbytes/4;
	    bip->u.uint8 = (unsigned char *) bu_malloc( ep->ext_nbytes,
							"rt_binunif_internal" );
	    srcp = (unsigned char *) ep->ext_buf;
	    ldestp = (unsigned long *) bip->u.uint8;
	    for (i = 0; i < bip->count; ++i, ++ldestp, srcp += 4) {
		*ldestp = bu_glong( srcp );
	    }
	    break;
	case DB5_MINORTYPE_BINU_64BITINT:
	case DB5_MINORTYPE_BINU_64BITINT_U:
	    bu_log("rt_binunif_import5() Can't handle 64-bit integers yet\n");
	    return -1;
    }

    return 0;		/* OK */
}