Beispiel #1
0
void SerializeInt(Obj obj) {
  Int n = INT_INTOBJ(obj);
  WriteTNum(T_INT);
  if (n >= -32 && n <= 31) {
    WriteByte(((n + 32) << 2) + 1);
  } else if (n >= -8192 && n <= 8191) {
    n += 8192;
    WriteByte(((n >> 8) << 2) + 2);
    WriteByte(n & 0xff);
  }
Beispiel #2
0
void SerializeObj(Obj obj)
{
    if (!obj) {
        /* Handle unbound list elements correctly */
        WriteTNum(T_BACKREF);
        WriteImmediateObj(INTOBJ_INT(0));
        return;
    }
    SerializationFuncByTNum[TNUM_OBJ(obj)](obj);
}
Beispiel #3
0
int SerializedAlready(Obj obj) {
  Obj ref = LookupObjMap(TLS(SerializationRegistry), obj);
  if (ref) {
    WriteTNum(T_BACKREF);
    WriteImmediateObj(OBJ_BACKREF(INT_INTOBJ(ref)));
    return 1;
  } else {
    TLS(SerializationIndex)++;
    AddObjMap(TLS(SerializationRegistry), obj,
        INTOBJ_INT(TLS(SerializationIndex)));
    return 0;
  }
}
Beispiel #4
0
int SerializedAlready(Obj obj)
{
    Obj ref = LookupObjMap(MODULE_STATE(Serialize).registry, obj);
    if (ref) {
        WriteTNum(T_BACKREF);
        WriteImmediateObj(OBJ_BACKREF(INT_INTOBJ(ref)));
        return 1;
    }
    else {
        MODULE_STATE(Serialize).index++;
        AddObjMap(MODULE_STATE(Serialize).registry, obj,
                  INTOBJ_INT(MODULE_STATE(Serialize).index));
        return 0;
    }
}
Beispiel #5
0
void SerializeUnbound() {
  WriteTNum(T_BACKREF);
  WriteImmediateObj(INTOBJ_INT(0));
}
Beispiel #6
0
static void SerializeBinary(Obj obj) {
  WriteTNum(TNUM_OBJ(obj));
  WriteByteBlock(obj, 0, SIZE_OBJ(obj));
}