Ejemplo n.º 1
0
/* new GCC compiler v4.5.0 complains function is defined but not used*/
void grib_recompute_sections_lengths(grib_section* s)
{
    if(s)
    {
        long   plen = 0;
        size_t  len = 1;

        grib_accessor* a = s->block->first;

        while(a)
        {
            /* grib_recompute_sections_lengths(grib_get_sub_section(a)); */
            grib_recompute_sections_lengths(a->sub_section);
            a = a->next;
        }

        if(s->aclength)
        {
            int ret;
            if(s->owner)
                plen = grib_get_next_position_offset(s->block->last) - s->owner->offset;
            else
                plen = grib_get_next_position_offset(s->block->last);

            if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS)
                ;

#if 0
            if(s->h->context->debug)
                printf("SECTION updating length %ld .. %s\n",plen,s->owner->name);
#endif

        }
    }
}
Ejemplo n.º 2
0
static void set_begin_end(grib_dumper* d,grib_accessor* a) {
    grib_dumper_debug *self = (grib_dumper_debug*)d;
    if ((d->option_flags & GRIB_DUMP_FLAG_OCTECT) != 0) {

        self->begin=a->offset-self->section_offset+1;
        self->theEnd=grib_get_next_position_offset(a)-self->section_offset;
    } else {
        self->begin=a->offset;
        self->theEnd=grib_get_next_position_offset(a);
    }
}
Ejemplo n.º 3
0
/* new GCC compiler v4.5.0 complains function is defined but not used*/
static void update_sections_lengths(grib_section* s)
{
    long   plen = 0;
    size_t  len = 1;

    if(!s) return;


    if(s->aclength)
    {
        int ret;
        if(s->owner)
            plen = grib_get_next_position_offset(s->block->last) - s->owner->offset;
        else
            plen = grib_get_next_position_offset(s->block->last);

        /* if(s->owner) */
        /* s->owner->length = plen; */

        /* if(s->aclength)  */
        if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS)
            ;

        if(s->h->context->debug)
        {
            printf("SECTION updating length %ld .. %s\n",plen,s->owner->name);
            printf("NEXT_POS = %ld, owner offset= %ld %s %s\n",
                    grib_get_next_position_offset(s->block->last),
                    s->owner ? s->owner->offset : 0L, s->owner->name,
                            s->block->last->name);
        }
    }

    if(s->owner)
        update_sections_lengths(s->owner->parent);

}
Ejemplo n.º 4
0
void grib_buffer_replace( grib_accessor *a, const unsigned char* data,
        size_t newsize,int update_lengths,int update_paddings)
{
    size_t offset   = a->offset;
    long   oldsize  = grib_get_next_position_offset(a)-offset;
    long   increase = (long)newsize - (long)oldsize;

    grib_buffer *buffer     = grib_handle_of_accessor(a)->buffer;
    size_t message_length   = buffer->ulength;

    grib_context_log(a->context,GRIB_LOG_DEBUG,
            "grib_buffer_replace %s offset=%ld oldsize=%ld newsize=%ld message_length=%ld update_paddings=%d",
            a->name,(long)offset,oldsize,(long)newsize,(long)message_length,update_paddings);

    grib_buffer_set_ulength(a->context,
            buffer,
            buffer->ulength+increase);

    /* move the end */
    if(increase)
        memmove(
                buffer->data + offset + newsize,
                buffer->data + offset + oldsize,
                message_length - offset - oldsize);

    /* copy new data */
    DebugAssert( buffer->data + offset );
    DebugAssert( data || (newsize==0) );/* if data==NULL then newsize must be 0 */
    if (data) {
        /* Note: memcpy behaviour is undefined if either dest or src is NULL */
        memcpy(buffer->data + offset, data, newsize);
    }

    if(increase)
    {
        update_offsets_after(a,increase);
        if(update_lengths)
        {
            grib_update_size(a,newsize);
            grib_section_adjust_sizes(grib_handle_of_accessor(a)->root,1,0);
            if(update_paddings)
                grib_update_paddings(grib_handle_of_accessor(a)->root);
        }
    }
}
static void print_offset(FILE* out,grib_dumper* d,grib_accessor* a) {
  int i,k;
  long offset;
  long theBegin=0,theEnd=0;
  size_t size=0,more=0;
  grib_dumper_default *self = (grib_dumper_default*)d;

  theBegin=a->offset-self->section_offset+1;;
  theEnd =grib_get_next_position_offset(a)-self->section_offset;

  if ((d->option_flags & GRIB_DUMP_FLAG_HEXADECIMAL) != 0 && a->length != 0) {
    if (theBegin == theEnd) {
      fprintf(self->dumper.out,"  ");
      fprintf(out,"# Octet: ");
      fprintf(out,"%ld" ,theBegin);
    }
    else {
      fprintf(self->dumper.out,"  ");
      fprintf(out,"# Octets: ");
      fprintf(out,"%ld-%ld" ,theBegin,theEnd);
    }
    fprintf(out,"  = ");
    size=a->length;

    if(!(d->option_flags & GRIB_DUMP_FLAG_ALL_DATA) && size > 112) {
      more = size - 112;
      size = 112;
    }

    k = 0;
    while(k < size)  {
      offset=a->offset;
      for (i=0;i<14 && k<size;i++,k++) {
        fprintf(out," 0x%.2X",a->parent->h->buffer->data[offset]);
        offset++;
      }
      if (k<size) fprintf(self->dumper.out,"\n  #");
    }  if(more)  {
      fprintf(self->dumper.out,"\n  #... %d more values\n",(int)more);
    }
    fprintf(self->dumper.out,"\n");

  }
}