Exemple #1
0
GhbValue*
ghb_int_value(gint64 ival)
{
    static GhbValue *gval = NULL;
    if (gval == NULL)
        gval = json_integer(ival);
    else
        json_integer_set(gval, ival);
    return gval;
}
Exemple #2
0
//native json_integer_set(Handle:hInteger, value);
static cell_t Native_json_integer_set(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
	json_t *object;
	Handle_t hndlObject = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlObject, htJanssonObject, &sec, (void **)&object)) != HandleError_None)
    {
        return pContext->ThrowNativeError("Invalid <Integer> handle %x (error %d)", hndlObject, err);
    }

	return (json_integer_set(object, params[2]) == 0);
}
Exemple #3
0
json_t * createLostArray(struct lost * lost)
{
    json_t * json_lost = json_object();
    
    json_t * title = json_string(lost->title);
    
    json_t * desc = json_string(lost->description);
    
    json_t * value = json_real(lost->value);
    
    json_t * date = json_integer(JSON_INTEGER_IS_LONG_LONG);
    
    json_integer_set(date, lost->date);
    
    json_object_set(json_lost, "title", title);
    json_object_set(json_lost, "description", desc);
    json_object_set(json_lost, "value", value);
    json_object_set(json_lost, "date", date);
    
    return json_lost;
}
Exemple #4
0
json_t * createRevenueArray(struct revenue * revenue){
    
    json_t * json_revenue = json_object();
        
    json_t * title = json_string(revenue->title);
        
    json_t * desc = json_string(revenue->description);
        
    json_t * value = json_real(revenue->value);
        
    json_t * date = json_integer(JSON_INTEGER_IS_LONG_LONG);
        
    json_integer_set(date, revenue->date);
        
    json_object_set(json_revenue, "title", title);
    json_object_set(json_revenue, "description", desc);
    json_object_set(json_revenue, "value", value);
    json_object_set(json_revenue, "date", date);
        
    return json_revenue;
    
}
Exemple #5
0
/* Call the simple functions not covered by other tests of the public API */
int main()
{
    json_t *value;

    value = json_integer(1);
    if(json_typeof(value) != JSON_INTEGER)
        fail("json_typeof failed");

    if(json_is_object(value))
        fail("json_is_object failed");

    if(json_is_array(value))
        fail("json_is_array failed");

    if(json_is_string(value))
        fail("json_is_string failed");

    if(!json_is_integer(value))
        fail("json_is_integer failed");

    if(json_is_real(value))
        fail("json_is_real failed");

    if(!json_is_number(value))
        fail("json_is_number failed");

    if(json_is_true(value))
        fail("json_is_true failed");

    if(json_is_false(value))
        fail("json_is_false failed");

    if(json_is_boolean(value))
        fail("json_is_boolean failed");

    if(json_is_null(value))
        fail("json_is_null failed");

    json_decref(value);


    value = json_string("foo");
    if(!value)
        fail("json_string failed");
    if(strcmp(json_string_value(value), "foo"))
        fail("invalid string value");

    if(json_string_set(value, "bar"))
        fail("json_string_set failed");
    if(strcmp(json_string_value(value), "bar"))
        fail("invalid string value");

    json_decref(value);

    value = json_string(NULL);
    if(value)
        fail("json_string(NULL) failed");

    /* invalid UTF-8  */
    value = json_string("a\xefz");
    if(value)
        fail("json_string(<invalid utf-8>) failed");

    value = json_string_nocheck("foo");
    if(!value)
        fail("json_string_nocheck failed");
    if(strcmp(json_string_value(value), "foo"))
        fail("invalid string value");

    if(json_string_set_nocheck(value, "bar"))
        fail("json_string_set_nocheck failed");
    if(strcmp(json_string_value(value), "bar"))
        fail("invalid string value");

    json_decref(value);

    /* invalid UTF-8 */
    value = json_string_nocheck("qu\xff");
    if(!value)
        fail("json_string_nocheck failed");
    if(strcmp(json_string_value(value), "qu\xff"))
        fail("invalid string value");

    if(json_string_set_nocheck(value, "\xfd\xfe\xff"))
        fail("json_string_set_nocheck failed");
    if(strcmp(json_string_value(value), "\xfd\xfe\xff"))
        fail("invalid string value");

    json_decref(value);


    value = json_integer(123);
    if(!value)
        fail("json_integer failed");
    if(json_integer_value(value) != 123)
        fail("invalid integer value");
    if(json_number_value(value) != 123.0)
        fail("invalid number value");

    if(json_integer_set(value, 321))
        fail("json_integer_set failed");
    if(json_integer_value(value) != 321)
        fail("invalid integer value");
    if(json_number_value(value) != 321.0)
        fail("invalid number value");

    json_decref(value);

    value = json_real(123.123);
    if(!value)
        fail("json_real failed");
    if(json_real_value(value) != 123.123)
        fail("invalid integer value");
    if(json_number_value(value) != 123.123)
        fail("invalid number value");

    if(json_real_set(value, 321.321))
        fail("json_real_set failed");
    if(json_real_value(value) != 321.321)
        fail("invalid real value");
    if(json_number_value(value) != 321.321)
        fail("invalid number value");

    json_decref(value);

    value = json_true();
    if(!value)
        fail("json_true failed");
    json_decref(value);

    value = json_false();
    if(!value)
        fail("json_false failed");
    json_decref(value);

    value = json_null();
    if(!value)
        fail("json_null failed");
    json_decref(value);

    /* Test reference counting on singletons (true, false, null) */
    value = json_true();
    if(value->refcount != (size_t)-1)
      fail("refcounting true works incorrectly");
    json_decref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting true works incorrectly");
    json_incref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting true works incorrectly");

    value = json_false();
    if(value->refcount != (size_t)-1)
      fail("refcounting false works incorrectly");
    json_decref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting false works incorrectly");
    json_incref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting false works incorrectly");

    value = json_null();
    if(value->refcount != (size_t)-1)
      fail("refcounting null works incorrectly");
    json_decref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting null works incorrectly");
    json_incref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting null works incorrectly");

    return 0;
}
Exemple #6
0
void net_json_convert_min3(json_t* r) {
 
  // ADC has changed i/o count from [2,2] to [3,2],
  // and likewise size of byte-arry of state data.

  // there is only one ADC operator, so this isn't too bad.
  
  /// magic number based on what 0.3.x scenes looked like.
  int lastAdcIn = 29;

  json_t* ins = json_object_get(r, "ins");
  json_t* insData = json_object_get(ins, "data");
  int insCount = json_integer_value(json_object_get(ins, "count"));
  json_integer_set(json_object_get(ins, "count"), insCount + 1);

  // need to f*x 

  // all we should have to do for input nodes is: 
  // - insert a new node
  // - fix everyone's index
  json_t* o = json_object();
  json_object_set(o, "idx", json_integer(lastAdcIn));
  json_object_set(o, "name", json_string("MODE    "));
  json_object_set(o, "opIdx", json_integer(10));
  json_object_set(o, "opInIdx", json_integer(2));
  json_object_set(o, "value", json_integer(0));
  json_object_set(o, "play", json_integer(0));
  int err  = json_array_insert(insData, lastAdcIn + 1, o );

  if(err != 0) { printf(" error inserting input node in ADC op conversion."); }
  
  // loop over input nodes and fix idx fields
  for(int i=0; i<NET_INS_MAX; i++) {
    json_integer_set(json_object_get(json_array_get(insData, i), "idx"), i);
  }

  // we also have to add some dummy values to the byte array of the ADC op's state.
  json_t* ops = json_object_get(r, "ops");
  // 10 is the magic number of the ADC op in 0.3.x
  json_t* adc = json_array_get(json_object_get(ops, "data"), 10);
  // mode pickle: 2 bytes input value, zero is fine
  json_array_append(json_object_get(adc, "state"),  json_integer(0));
  json_array_append(json_object_get(adc, "state"),  json_integer(0));

  /* // copy all input nodes above this operator's... */
  /* // count down from top. src has fewer input nodes; otherwise we would lose last value. */
  /* for(int i = NET_INS_MAX - 1; i > lastAdcIn; i--) { */
  /*   // get json object at this index in node array */
  /*   json_t* dst = json_array_get(insData, i); */
  /*   json_t* src = json_array_get(insData, i - 1);     */
  /*   if(src != NULL) { */
  /*     if(dst == NULL) { */
  /* 	int err; */
  /* 	dst = json_object(); */
  /* 	json_object_set(dst, "idx", json_integer(i)); */
  /* 	err = json_array_insert(insData, i, dst); */
  /* 	if(err != 0) { printf(" error inserting input node in ADC op conversion."); } */
  /*     } */
  /*     // shallow copy ok? */
  /*     json_array_set(insData, src); */
  /*     // custom-copy, leaving idx */
  /*     /\* json_object_(dst, "name", json_object_get(src, "name")); *\/ */
  /*     /\* json_object_set(dst, "opIdx", json_object_get(src, "opIdx")); *\/ */
  /*     /\* json_object_set(dst, "opInIdx", json_object_get(src, "opInIdx")); *\/ */
  /*     /\* json_object_set(dst, "value", json_object_get(src, "value")); *\/ */
  /*     /\* json_object_set(dst, "play", json_object_get(src, "play")); *\/ */
  /*   } */
  /* } */
  /* // finally, we need to fix up the values for the new input ("mode");   */
  /* ///... FIXME */

  
  //---- -outs
  json_t* outs = json_object_get(r, "outs");
  json_t* outsData = json_object_get(outs, "data");
  // loop over all outputs and check targets
  for(int i = 0; i< NET_OUTS_MAX; i++) {
    json_t* o = json_array_get(outsData, i);
    int t = json_integer_value(json_object_get(o, "target"));
      if(t > lastAdcIn) {
	json_integer_set(json_object_get(o, "target"), t + 1);
      }
  }

  // i don't think anyone really used presets in this rev, so skipping those for now.

  // write the output of the converted json for a visual check.
  json_dump_file(r, "converted.json", JSON_INDENT(4) | JSON_PRESERVE_ORDER | JSON_ESCAPE_SLASH);
}
Exemple #7
0
int ast_json_integer_set(struct ast_json *integer, intmax_t value)
{
	return json_integer_set((json_t *)integer, value);
}
Exemple #8
0
int la_codec_integer_set(la_codec_value_t *integer, la_codec_int_t value)
{
    return json_integer_set((json_t *) integer, value);
}