패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.0.3

objectid

Dart 언어용 빠르고 크로스 플랫폼의 ObjectId 구현.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3만
좋아요
38
Pub 점수
160

패키지 설치

flutter pub add objectid

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

고성능의 크로스플랫폼 Dart ObjectId 구현체로, 다양한 플랫폼에서 고유 식별자 생성 및 처리를 효율적으로 설계되었습니다. 속도와 호환성을 위해 제작되었으며, Android, iOS, Web, macOS, Windows, Linux를 지원합니다. 데이터베이스나 분산 시스템과 같은 보안성과 글로벌 고유 ID가 필요한 애플리케이션에 적합하며, 성능을 희생하지 않고 일관성과 신뢰성을 보장합니다. 백엔드 서비스 또는 실시간 앱과 같이 ID의 유일성과 생성 속도가 중요한 경우 특히 유용합니다.

사용 사례

  • 데이터베이스 문서 ID 생성
  • 분산 시스템 식별자 생성
  • 실시간 애플리케이션 데이터 동기화
  • 보안 세션 토큰 생성
  • 크로스 플랫폼 앱 데이터 추적

주요 기능

  • 초고속 ID 생성
  • 크로스 플랫폼 호환성
  • 스레드 안전한 구현
  • 작은 12바이트 ID 형식
  • 타임스탬프, 머신, 프로세스 및 카운터 구성 요소를 지원
  • Flutter 앱과의 간편한 통합

적합한 대상

  • 확장 가능한 백엔드 서비스를 구축하는 개발자
  • 다중 플랫폼에서 고유 식별자가 필요한 앱
  • MongoDB 또는 유사한 데이터베이스를 사용하는 프로젝트
  • 고처리량 실시간 애플리케이션
  • 성능과 이식성을 우선시하는 팀

고려 사항

  • 암호화 비밀에 적합하지 않습니다
  • 다중 스레드 환경에서는 주의 깊은 조작이 필요합니다
  • UUID 호환성 제공 안 함
  • ObjectId 고유 사용 사례에 한정
  • 내장된 검증 유틸리티 없음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

ObjectId

Blazing fast, cross-platform ObjectId implementation for the dart language!

Dart tests codecov pub package License: MIT style: lints/recommended

Why this package?

Getting started

  1. Depend on it.
dependencies:
  objectid: 4.0.3
  1. Play with it!
final id = ObjectId(); // That's all 🔥😮!
print(id);   // it's working! => 5f52c805df41c9df948e6135

Documentation

Constructors
ObjectId()

Creates an ObjectId instance based on current timestamp, process unique and counter.

final id = ObjectId();
print(id.hexString); // => 5f52c805df41c9df948e6135
ObjectId.fromHexString(String hexString)

Creates ObjectId from a 24-character hex string.

// Useful for mapping hex strings from APIs or MongoDB
final id = ObjectId.fromHexString('5f52c805df41c9df948e6135');
print(id == ObjectId.fromHexString(id.hexString)); // => true
ObjectId.fromBytes(List<int> bytes)

Creates ObjectId from a 12-byte array.

// Perfect for storing ObjectId in binary format
final id = ObjectId.fromBytes([95, 82, 205, 121, 180, 195, 28, 88, 32, 47, 183, 78]);
print(id.hexString); // => 5f52cd79b4c31c58202fb74e

// Retrieve bytes with the bytes property
final id2 = ObjectId.fromBytes(id.bytes);
print(id == id2); // => true
ObjectId.fromValues(int millisecondsSinceEpoch, int processUnique, int counter)

Creates an ObjectId from provided integer values.

// Examples of different ObjectId patterns
final zeroed = ObjectId.fromValues(0, 0, 0);                    // 000000000000000000000000
final withTimestamp = ObjectId.fromValues(0x3e7fffffc18, 0, 0); // ffffffff0000000000000000
final withProcessUnique = ObjectId.fromValues(0, 0xffffffffff, 0); // 00000000ffffffffff000000
final withCounter = ObjectId.fromValues(0, 0, 0xffffff);        // 000000000000000000ffffff
final filled = ObjectId.fromValues(0x3e7fffffc18, 0xffffffffff, 0xffffff); // ffffffffffffffffffffffff
ObjectId.fromTimestamp(DateTime timestamp)

Creates ObjectId from provided timestamp with other segments zeroed out.

// Useful for ObjectId comparisons or sorting
final id = ObjectId.fromTimestamp(DateTime.now());
print(id.hexString); // => 5f52d05e0000000000000000
Properties and Methods
String hexString

Returns a 24-character hex string representation of the ObjectId (cached for performance).

DateTime timestamp

Returns the generation time accurate to the second (cached for performance).

Uint8List bytes

Returns the ObjectId's raw byte representation.

int hashCode

Uses MurmurHash2 algorithm for fast hashing (cached for performance).

operator ==

Compares ObjectIds based on type and byte equality.

static bool isValid(String hexString)

Checks if a string is a valid ObjectId hex string.

print(ObjectId.isValid('5f52c805df41c9df948e6135')); // => true
print(ObjectId.isValid('invalid')); // => false

All implementation details conform to the BSON ObjectId specification.

Benchmark

Benchmark hardware/software: UNIT: MacBook Pro (M4 Pro, 2024) CPU: Apple M4 Pro RAM: 48 GB OS: macOS 26.3.1 Dart SDK version: 3.11.4

Constructors:
ObjectId() → (RunTime): 0.28017946395452636 us.
ObjectId.fromHexString() → (RunTime): 0.1964833532549569 us.
ObjectId.fromBytes() → (RunTime): 0.11237176106442358 us.
ObjectId.fromValues() → (RunTime): 0.02774876977800984 us.
ObjectId.fromTimestamp() → (RunTime): 0.04264624207353758 us.
Properties:
ObjectId.hexString → (RunTime): 0.03615293445770598 us.
ObjectId.timestamp → (RunTime): 0.03690251970477984 us.
ObjectId.hashCode → (RunTime): 0.02660910959699762 us.
Operators:
ObjectId == ObjectId → (RunTime): 0.08761381094863427 us.

Benchmark is available in the example app.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트