Class: Superstudio::JsonBroker

Inherits:
Object
  • Object
show all
Defined in:
ext/superstudio/jsonbroker.c

Instance Method Summary collapse

Instance Method Details

#consume_row(row) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'ext/superstudio/jsonbroker.c', line 279

static VALUE json_broker_consume_row(VALUE self, VALUE row)
{
  JSONDocumentBuilder *builder;
  Check_Type(row, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  struct RArray* cRow = RARRAY(row);
  VALUE* row_pointer = RARRAY_PTR(cRow);

  unsigned long length = RARRAY_LENINT(row);
  unsigned long counter = 0;
  struct RString* in_loop_rstring;
  char* in_loop_string;
  char* row_strings[length];
  unsigned long string_sizes[length];

  while(counter < length) {
    Check_Type(row_pointer[counter], T_STRING);
    in_loop_rstring = RSTRING(row_pointer[counter]);
    in_loop_string = RSTRING_PTR(in_loop_rstring);

    row_strings[counter] = in_loop_string;
    string_sizes[counter] = RSTRING_LEN(in_loop_rstring);
    counter++;
  }
  consume_row(builder, row_strings, string_sizes, 0, 0, length, NULL, NULL, 4, 0, builder->root_level->search_list);
  return Qnil;
}

#finalize_jsonObject



307
308
309
310
311
312
313
314
# File 'ext/superstudio/jsonbroker.c', line 307

static VALUE json_broker_finalize_json(VALUE self)
{
  JSONDocumentBuilder *builder;
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  char* final_json = finalize_json(builder);

  return rb_str_new2(final_json);
}

#get_column_countObject



231
232
233
234
235
236
237
238
# File 'ext/superstudio/jsonbroker.c', line 231

static VALUE json_broker_get_mapper_length(VALUE self)
{
  JSONDocumentBuilder *builder;
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  unsigned long get_count = get_column_count(builder);
  VALUE count = LONG2FIX(get_count);
  return count;
}

#get_row_countObject



270
271
272
273
274
275
276
277
# File 'ext/superstudio/jsonbroker.c', line 270

static VALUE json_broker_get_row_count(VALUE self)
{
  JSONDocumentBuilder *builder;
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  unsigned long get_count = get_row_count(builder);
  VALUE count = LONG2FIX(get_count);
  return count;
}

#set_array_node_names(keys) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/superstudio/jsonbroker.c', line 126

static VALUE json_broker_set_array_node_names(VALUE self, VALUE keys)
{
  JSONDocumentBuilder* builder;
  unsigned long length = RARRAY_LENINT(keys);

  Check_Type(keys, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);

  struct RArray* cKeys = RARRAY(keys);
  VALUE* key_pointer = RARRAY_PTR(cKeys);

  struct RString* in_loop_rstring;
  char* in_loop_string;
  unsigned long in_loop_string_size;
  char* key_array[length];
  unsigned long key_sizes[length];
  unsigned long counter = 0;

  while(counter < length) {
    Check_Type(key_pointer[counter], T_STRING);
    in_loop_rstring = RSTRING(key_pointer[counter]);
    in_loop_string = RSTRING_PTR(in_loop_rstring);
    in_loop_string_size = RSTRING_LEN(in_loop_rstring);
    key_array[counter] = in_loop_string;
    key_sizes[counter] = in_loop_string_size;

    counter++;
  }
  set_array_node_key_names(builder, key_array, key_sizes);
  return Qnil;
}

#set_column_names(names) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'ext/superstudio/jsonbroker.c', line 63

static VALUE json_broker_set_column_names(VALUE self, VALUE names)
{
  JSONDocumentBuilder *builder;
  unsigned long length = RARRAY_LENINT(names);

  Check_Type(names, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  
  struct RArray* cNames = RARRAY(names);
  VALUE* name_pointer = RARRAY_PTR(cNames);

  struct RString* in_loop_rstring;
  char* in_loop_string;
  unsigned long in_loop_string_size;
  char* names_array[length];
  unsigned long names_sizes[length];
  unsigned long counter = 0;

  while(counter < length) {
    Check_Type(name_pointer[counter], T_STRING);
    in_loop_rstring = RSTRING(name_pointer[counter]);
    in_loop_string = RSTRING_PTR(in_loop_rstring);
    in_loop_string_size = RSTRING_LEN(in_loop_rstring);
    names_array[counter] = in_loop_string;
    names_sizes[counter] = in_loop_string_size;
    counter++;
  }
  set_column_names_sizes(builder, names_array, names_sizes);
  return Qnil;
}

#set_depths(depths, real_depths) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'ext/superstudio/jsonbroker.c', line 198

static VALUE json_broker_set_depths(VALUE self, VALUE depths, VALUE real_depths)
{
  JSONDocumentBuilder *builder;
  Check_Type(depths, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);

  unsigned long length = get_column_count(builder);
  struct RArray* cDepths = RARRAY(depths);
  struct RArray* cRealDepths = RARRAY(real_depths);
  VALUE* depths_pointer = RARRAY_PTR(cDepths);
  VALUE* real_depths_pointer = RARRAY_PTR(cRealDepths);

  unsigned long depths_array[length];
  unsigned long real_depths_array[length];
  unsigned long counter = 0;
  unsigned long max_depth = 0;
  unsigned long max_real_depth = 0;

  while(counter < length) {
    depths_array[counter] = FIX2LONG(depths_pointer[counter]);
    real_depths_array[counter] = FIX2LONG(real_depths_pointer[counter]);
    if (depths_array[counter] > max_depth) {
      max_depth = depths_array[counter];
    }
    if (real_depths_array[counter] > max_real_depth) {
      max_real_depth = real_depths_array[counter];
    }
    counter++;
  }
  set_depth_array(builder, depths_array, max_depth, real_depths_array, max_real_depth);
  return Qnil;
}

#set_hashing(do_not_hash) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'ext/superstudio/jsonbroker.c', line 178

static VALUE json_broker_set_hashing(VALUE self, VALUE do_not_hash)
{
  JSONDocumentBuilder *builder;
  Check_Type(do_not_hash, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  unsigned long length = get_column_count(builder);

  struct RArray* cDoNotHash = RARRAY(do_not_hash);
  VALUE* hashing_pointer = RARRAY_PTR(cDoNotHash);
  unsigned long hashing_array[length];
  unsigned long counter = 0;

  while(counter < length) {
    hashing_array[counter] = FIX2LONG(hashing_pointer[counter]);
    counter++;
  }
  set_hashing_array(builder, hashing_array);
  return Qnil;
}

#set_mapper(tags) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/superstudio/jsonbroker.c', line 31

static VALUE json_broker_set_mapper(VALUE self, VALUE tags)
{
  JSONDocumentBuilder *builder;
  unsigned long length = RARRAY_LENINT(tags);

  Check_Type(tags, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  set_column_count(builder, length);

  struct RArray* cTags = RARRAY(tags);
  VALUE* tag_pointer = RARRAY_PTR(cTags);
  unsigned long counter = 0;

  struct RString* in_loop_rstring;
  char* in_loop_string;
  unsigned long in_loop_string_size;
  char* mapping_array[length];
  unsigned long mapping_array_lengths[length];

  while(counter < length) {
    Check_Type(tag_pointer[counter], T_STRING);
    in_loop_rstring = RSTRING(tag_pointer[counter]);
    in_loop_string = RSTRING_PTR(in_loop_rstring);
    in_loop_string_size = RSTRING_LEN(in_loop_rstring);
    mapping_array[counter] = in_loop_string;
    mapping_array_lengths[counter] = in_loop_string_size;
    counter++;
  }
  set_mapping_array(builder, mapping_array, mapping_array_lengths);
  return Qnil;
}

#set_quotes(quotes) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'ext/superstudio/jsonbroker.c', line 158

static VALUE json_broker_set_quotes(VALUE self, VALUE quotes)
{
  JSONDocumentBuilder *builder;
  Check_Type(quotes, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);

  unsigned long length = get_column_count(builder);
  struct RArray* cQuotes = RARRAY(quotes);
  VALUE* quotes_pointer = RARRAY_PTR(cQuotes);
  unsigned long quotes_array[length];
  unsigned long counter = 0;

  while(counter < length) {
    quotes_array[counter] = FIX2LONG(quotes_pointer[counter]);
    counter++;
  }
  set_quote_array(builder, quotes_array);
  return Qnil;
}

#set_repeating_arrays(repeating) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'ext/superstudio/jsonbroker.c', line 249

static VALUE json_broker_set_repeating_array_columns(VALUE self, VALUE repeating)
{
  JSONDocumentBuilder *builder;
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  
  unsigned long length = get_column_count(builder);
  struct RArray* cRepeats = RARRAY(repeating);
  VALUE* repeating_pointer = RARRAY_PTR(cRepeats);

  unsigned long repeats_array[length];
  unsigned long counter = 0;

  while(counter < length) {
    repeats_array[counter] = FIX2LONG(repeating_pointer[counter]);
    counter++;
  }

  set_repeating_array_columns(builder, repeats_array);
  return Qnil;
}

#set_row_count(row_count) ⇒ Object



240
241
242
243
244
245
246
247
# File 'ext/superstudio/jsonbroker.c', line 240

static VALUE json_broker_set_row_count(VALUE self, VALUE row_count)
{
  JSONDocumentBuilder *builder;
  Data_Get_Struct(self, JSONDocumentBuilder, builder);
  unsigned long set_count = FIX2LONG(row_count);
  set_row_count(builder, set_count);
  return Qnil;
}

#set_single_node_names(keys) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/superstudio/jsonbroker.c', line 94

static VALUE json_broker_set_single_node_names(VALUE self, VALUE keys)
{
  JSONDocumentBuilder* builder;
  unsigned long length = RARRAY_LENINT(keys);

  Check_Type(keys, T_ARRAY);
  Data_Get_Struct(self, JSONDocumentBuilder, builder);

  struct RArray* cKeys = RARRAY(keys);
  VALUE* key_pointer = RARRAY_PTR(cKeys);

  struct RString* in_loop_rstring;
  char* in_loop_string;
  unsigned long in_loop_string_size;
  char* key_array[length];
  unsigned long key_sizes[length];
  unsigned long counter = 0;

  while(counter < length) {
    Check_Type(key_pointer[counter], T_STRING);
    in_loop_rstring = RSTRING(key_pointer[counter]);
    in_loop_string = RSTRING_PTR(in_loop_rstring);
    in_loop_string_size = RSTRING_LEN(in_loop_rstring);
    key_array[counter] = in_loop_string;
    key_sizes[counter] = in_loop_string_size;

    counter++;
  }
  set_single_node_key_names(builder, key_array, key_sizes);
  return Qnil;
}