gitoriaLog in with ident

mpackdb

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmaster87888725release 1.0.7caramboleyomaster/src/mpack.js

1.1 KB

  1. import { pack, unpack } from 'msgpackr';
  2. /**
  3. * Serialize object to MessagePack with 4-byte length prefix
  4. * Format: [4-byte LE size][MessagePack data]
  5. */
  6. export function serialize(obj) {
  7. const msgpackData = pack(obj);
  8. const totalSize = 4 + msgpackData.length;
  9. const buffer = Buffer.allocUnsafe(totalSize);
  10. // Write 4-byte length prefix (little-endian)
  11. buffer.writeInt32LE(totalSize, 0);
  12. // Copy MessagePack data after the length prefix
  13. msgpackData.copy(buffer, 4);
  14. return buffer;
  15. }
  16. /**
  17. * Deserialize MessagePack data (expects data WITHOUT length prefix)
  18. */
  19. export function deserialize(buffer) {
  20. return unpack(buffer);
  21. }
  22. /**
  23. * Read size from buffer (first 4 bytes)
  24. */
  25. export function readSize(buffer) {
  26. return buffer.readInt32LE(0);
  27. }
  28. /**
  29. * Sortable unique ID generator: 9-char base36 timestamp + 3-char base36 random
  30. */
  31. export function uuid() {
  32. const t = Date.now().toString(36).padStart(9, '0');
  33. const r = Math.random().toString(36).slice(2, 5).padStart(3, '0');
  34. return t + r;
  35. }
  36. export const PrimaryKeyType = {
  37. NUMBER: 0,
  38. UUID: 1,
  39. STRING: 2,
  40. };
  41. export const IndexType = {
  42. LEXICAL: 0,
  43. NUMERIC: 1,
  44. };

Branches

  • mastermain branch

Latest commits

  • 87888725release 1.0.7caramboleyo
  • c4cdb9b6node: import prefixes (Deno compat) + pre-existing index-state WIPcaramboleyo
  • 0afb8f4bupdate now must be a callbackcaramboleyo
  • cde73eb4release 1.0.6caramboleyo
  • d01dda02add index hints, intersection, boundingBox; remove findByIndexcaramboleyo
  • b8ffc1a0release 1.0.5caramboleyo
  • d47876a1reimplemented lost features like indexed find and more testscaramboleyo
  • 7f08da9afixed insert ignoring model definitioncaramboleyo
  • 705774a9added flush before findcaramboleyo
  • b4db6391initial commitcaramboleyo