getObjectBoxModel function

ModelDefinition getObjectBoxModel()

ObjectBox model definition, pass it to Store - Store(getObjectBoxModel())

Implementation

ModelDefinition getObjectBoxModel() {
  final model = ModelInfo(
      entities: _entities,
      lastEntityId: const IdUid(2, 3591291115973887432),
      lastIndexId: const IdUid(1, 8984911200634127343),
      lastRelationId: const IdUid(0, 0),
      lastSequenceId: const IdUid(0, 0),
      retiredEntityUids: const [],
      retiredIndexUids: const [],
      retiredPropertyUids: const [],
      retiredRelationUids: const [],
      modelVersion: 5,
      modelVersionParserMinimum: 5,
      version: 1);

  final bindings = <Type, EntityDefinition>{
    CacheControlBox: EntityDefinition<CacheControlBox>(
        model: _entities[0],
        toOneRelations: (CacheControlBox object) => [],
        toManyRelations: (CacheControlBox object) => {},
        getId: (CacheControlBox object) => object.id,
        setId: (CacheControlBox object, int id) {
          object.id = id;
        },
        objectToFB: (CacheControlBox object, fb.Builder fbb) {
          final privacyOffset =
              object.privacy == null ? null : fbb.writeString(object.privacy!);
          final otherOffset = object.other == null
              ? null
              : fbb.writeList(
                  object.other!.map(fbb.writeString).toList(growable: false));
          fbb.startTable(10);
          fbb.addInt64(0, object.id ?? 0);
          fbb.addInt64(1, object.maxAge);
          fbb.addOffset(2, privacyOffset);
          fbb.addBool(3, object.noCache);
          fbb.addBool(4, object.noStore);
          fbb.addOffset(5, otherOffset);
          fbb.addInt64(6, object.maxStale);
          fbb.addInt64(7, object.minFresh);
          fbb.addBool(8, object.mustRevalidate);
          fbb.finish(fbb.endTable());
          return object.id ?? 0;
        },
        objectFromFB: (Store store, ByteData fbData) {
          final buffer = fb.BufferContext(fbData);
          final rootOffset = buffer.derefObject(0);

          final object = CacheControlBox(
              id: const fb.Int64Reader()
                  .vTableGetNullable(buffer, rootOffset, 4),
              maxAge: const fb.Int64Reader()
                  .vTableGetNullable(buffer, rootOffset, 6),
              privacy: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 8),
              noCache: const fb.BoolReader()
                  .vTableGetNullable(buffer, rootOffset, 10),
              noStore: const fb.BoolReader()
                  .vTableGetNullable(buffer, rootOffset, 12),
              other: const fb.ListReader<String>(
                      fb.StringReader(asciiOptimization: true),
                      lazy: false)
                  .vTableGetNullable(buffer, rootOffset, 14))
            ..maxStale =
                const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 16)
            ..minFresh =
                const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 18)
            ..mustRevalidate =
                const fb.BoolReader().vTableGetNullable(buffer, rootOffset, 20);

          return object;
        }),
    CacheResponseBox: EntityDefinition<CacheResponseBox>(
        model: _entities[1],
        toOneRelations: (CacheResponseBox object) => [object.cacheControl],
        toManyRelations: (CacheResponseBox object) => {},
        getId: (CacheResponseBox object) => object.id,
        setId: (CacheResponseBox object, int id) {
          object.id = id;
        },
        objectToFB: (CacheResponseBox object, fb.Builder fbb) {
          final keyOffset = fbb.writeString(object.key);
          final contentOffset = object.content == null
              ? null
              : fbb.writeListInt8(object.content!);
          final eTagOffset =
              object.eTag == null ? null : fbb.writeString(object.eTag!);
          final headersOffset = object.headers == null
              ? null
              : fbb.writeListInt8(object.headers!);
          final lastModifiedOffset = object.lastModified == null
              ? null
              : fbb.writeString(object.lastModified!);
          final urlOffset = fbb.writeString(object.url);
          fbb.startTable(15);
          fbb.addInt64(0, object.id ?? 0);
          fbb.addOffset(1, keyOffset);
          fbb.addOffset(2, contentOffset);
          fbb.addInt64(3, object.date?.millisecondsSinceEpoch);
          fbb.addOffset(4, eTagOffset);
          fbb.addInt64(5, object.expires?.millisecondsSinceEpoch);
          fbb.addOffset(6, headersOffset);
          fbb.addOffset(7, lastModifiedOffset);
          fbb.addInt64(8, object.maxStale?.millisecondsSinceEpoch);
          fbb.addInt64(9, object.responseDate.millisecondsSinceEpoch);
          fbb.addOffset(10, urlOffset);
          fbb.addInt64(11, object.priority);
          fbb.addInt64(12, object.cacheControl.targetId);
          fbb.addInt64(13, object.requestDate?.millisecondsSinceEpoch);
          fbb.finish(fbb.endTable());
          return object.id ?? 0;
        },
        objectFromFB: (Store store, ByteData fbData) {
          final buffer = fb.BufferContext(fbData);
          final rootOffset = buffer.derefObject(0);
          final dateValue =
              const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 10);
          final expiresValue =
              const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 14);
          final maxStaleValue =
              const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 20);
          final requestDateValue =
              const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 30);
          final object = CacheResponseBox(
              key: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 6, ''),
              content: const fb.ListReader<int>(fb.Int8Reader(), lazy: false)
                  .vTableGetNullable(buffer, rootOffset, 8),
              date: dateValue == null
                  ? null
                  : DateTime.fromMillisecondsSinceEpoch(dateValue),
              eTag: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 12),
              expires: expiresValue == null
                  ? null
                  : DateTime.fromMillisecondsSinceEpoch(expiresValue),
              headers: const fb.ListReader<int>(fb.Int8Reader(), lazy: false)
                  .vTableGetNullable(buffer, rootOffset, 16),
              lastModified: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 18),
              maxStale: maxStaleValue == null
                  ? null
                  : DateTime.fromMillisecondsSinceEpoch(maxStaleValue),
              requestDate: requestDateValue == null ? null : DateTime.fromMillisecondsSinceEpoch(requestDateValue),
              priority: const fb.Int64Reader().vTableGet(buffer, rootOffset, 26, 0),
              responseDate: DateTime.fromMillisecondsSinceEpoch(const fb.Int64Reader().vTableGet(buffer, rootOffset, 22, 0)),
              url: const fb.StringReader(asciiOptimization: true).vTableGet(buffer, rootOffset, 24, ''))
            ..id = const fb.Int64Reader().vTableGetNullable(buffer, rootOffset, 4);
          object.cacheControl.targetId =
              const fb.Int64Reader().vTableGet(buffer, rootOffset, 28, 0);
          object.cacheControl.attach(store);
          return object;
        })
  };

  return ModelDefinition(model, bindings);
}