#include <stdio.h>
unsigned short x = 1; /* 0x0001 */
int main(void)
{
printf("%s\n", *((unsigned char *) &x + 1) == 0 ? "little-endian" : "big-endian");
return 0;
}
static int
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
{
Py_ssize_t i, numfields = 0;
int res = -1;
PyObject *key, *value, *fields;
fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields);
if (!fields)
PyErr_Clear();
if (fields) {
numfields = PySequence_Size(fields);
if (numfields == -1)
goto cleanup;
}
res = 0; /* if no error occurs, this stays 0 to the end */
if (numfields < PyTuple_GET_SIZE(args)) {
PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
"%zd positional argument%s",
Py_TYPE(self)->tp_name,
numfields, numfields == 1 ? "" : "s");
res = -1;
goto cleanup;
}
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
/* cannot be reached when fields is NULL */
PyObject *name = PySequence_GetItem(fields, i);
if (!name) {
res = -1;
goto cleanup;
}
res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
Py_DECREF(name);
if (res < 0)
goto cleanup;
}
if (kw) {
i = 0; /* needed by PyDict_Next */
while (PyDict_Next(kw, &i, &key, &value)) {
res = PyObject_SetAttr(self, key, value);
if (res < 0)
goto cleanup;
}
}
cleanup:
Py_XDECREF(fields);
return res;
}
{ ... }
) конкретно как на объекты в ООП, а не как на ассоциативный массив. Создай конкретные модели со всеми связями между собой, которые ты собираешься сериализировать в JSON. Если нужен список серверов/групп/клиентов, то используй именно список ([ ... ]
) сериализированных моделей. package com.company;
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
MapData<String,Integer> mapData = MapData.map(new Zoidberg(), 10);
System.out.print("");
}
}
class Pair <K, V> {
public K key;
public V value;
public Pair (K key, V value){
this.key = key; this.value = value;
}
}
interface Generator <T> {
public T next ();
}
class MapData <K, V> extends LinkedHashMap<K, V> {
public MapData (Generator <Pair<K, V>> gen, int size){
for (int i=0; i!=size; i++){
Pair <K, V> p = gen.next();
put (p.key, p.value);
}
}
public static <K, V> MapData <K, V> map (Generator <Pair<K, V>> gen, int size){
return new MapData (gen, size);
}
}
class Zoidberg implements Generator<Pair<String,Integer>> {
@Override
public Pair<String, Integer> next() {
return new Pair<String, Integer>("i_will_read_books", 10);
}
}
public static void vargs(final String... strings) {
System.out.println(strings);
}
public static void arrs(final String[] strings) {
System.out.println(strings);
}
public static void main(final String... args) {
vargs(); // ok
vargs("1", "2"); // ok
arrs(); // compilation error
arrs(new String[] {"1", "2"}); // ok
}
public static void manyParams(final String... strings, final Integer number) {
// compilation error
}
public static void manyParams(final Integer number, final String... strings) {
// ok
}
public static class Integer implements MyRandom <java.lang.Integer> {
private Random rand = new Random();
public java.lang.Integer GetRandom() {
return rand.nextInt(10);
}
}
Python позволяет быстрее вести разработку