anshu-krishna/neo4j-pack-stream

An implementation of Neo4j Pack Stream

1.0 2022-09-10 09:48 UTC

This package is auto-updated.

Last update: 2024-05-10 13:30:15 UTC


README

Installation:

composer require anshu-krishna/neo4j-pack-stream

Requirements:

  • PHP >= 8.1

Example:

// For packing use
Krishna\PackStream\Packer::pack(mixed $value): iterable;
// Note: pack() is a generator. It yields binary strings.

// For unpacking use
Krishna\PackStream\Unpacker::unpack(I_ByteSource $source): mixed;
// Source must implement I_ByteSource interface.
Data Packed (Hex Representation) Unpacked
null: null
C0
null: null
int: 25
19
int: 25
float: 15.5
C1 40 2F 00  00 00 00 00  00
float: 15.5
bool: true
C3
bool: true
bool: false
C2
bool: false
string: "Hello world"
8B 48 65 6C  6C 6F 20 77  6F 72 6C 64
string: "Hello world"
array: [
    1,
    2.3,
    true,
    "abc"
]
94 01 C1 40  02 66 66 66  66 66 66 C3  83 61 62 63
array: [
    1,
    2.3,
    true,
    "abc"
]
array: {
    "a": 10,
    "b": 20
}
A2 81 61 0A  81 62 14
array: {
    "a": 10,
    "b": 20
}
Bytes: {
    "length": 5,
    "hex": "0102030405"
}
CC 05 01 02  03 04 05
Bytes: {
    "length": 5,
    "hex": "0102030405"
}
Node: {
    "id": 45,
    "labels": [
        "abc",
        "def"
    ],
    "properties": {
        "xyz": 55
    }
}
B3 4E 2D 92  83 61 62 63  83 64 65 66  A1 83 78 79  7A 37
Node: {
    "id": 45,
    "labels": [
        "abc",
        "def"
    ],
    "properties": {
        "xyz": 55
    }
}
Relationship: {
    "id": 96,
    "startNodeId": 45,
    "endNodeId": 47,
    "type": "example",
    "properties": {
        "prop": "test"
    }
}
B5 52 60 2D  2F 87 65 78  61 6D 70 6C  65 A1 84 70  72 6F 70 84
74 65 73 74
Relationship: {
    "id": 96,
    "startNodeId": 45,
    "endNodeId": 47,
    "type": "example",
    "properties": {
        "prop": "test"
    }
}
UnboundRelationship: {
    "id": 100,
    "type": "unbound-example",
    "properties": []
}
B3 72 64 8F  75 6E 62 6F  75 6E 64 2D  65 78 61 6D  70 6C 65 A0
UnboundRelationship: {
    "id": 100,
    "type": "unbound-example",
    "properties": []
}
Path: {
    "nodes": [
        {
            "id": 45,
            "labels": [
                "abc",
                "def"
            ],
            "properties": []
        }
    ],
    "rels": [
        {
            "id": 100,
            "type": "unbound",
            "properties": []
        }
    ],
    "ids": [
        15
    ]
}
B3 50 91 B3  4E 2D 92 83  61 62 63 83  64 65 66 A0  91 B3 72 64
87 75 6E 62  6F 75 6E 64  A0 91 0F
Path: {
    "nodes": [
        {
            "id": 45,
            "labels": [
                "abc",
                "def"
            ],
            "properties": []
        }
    ],
    "rels": [
        {
            "id": 100,
            "type": "unbound",
            "properties": []
        }
    ],
    "ids": [
        15
    ]
}
Date: {
    "days": 15
}
B1 44 0F
Date: {
    "days": 15
}
Time: {
    "nanoseconds": 100000,
    "tz_offset_seconds": 50
}
B2 54 CA 00  01 86 A0 32
Time: {
    "nanoseconds": 100000,
    "tz_offset_seconds": 50
}
LocalTime: {
    "nanoseconds": 100000
}
B1 74 CA 00  01 86 A0
LocalTime: {
    "nanoseconds": 100000
}
DateTime: {
    "seconds": 50,
    "nanoseconds": 100,
    "tz_offset_seconds": 100
}
B3 46 32 64  64
DateTime: {
    "seconds": 50,
    "nanoseconds": 100,
    "tz_offset_seconds": 100
}
DateTimeZoneId: {
    "seconds": 45,
    "nanoseconds": 10005,
    "tz_id": "Asia\/Kolkata"
}
B3 66 2D C9  27 15 8C 41  73 69 61 2F  4B 6F 6C 6B  61 74 61
DateTimeZoneId: {
    "seconds": 45,
    "nanoseconds": 10005,
    "tz_id": "Asia\/Kolkata"
}
LocalDateTime: {
    "seconds": 100000000,
    "nanoseconds": 155
}
B2 64 CA 05  F5 E1 00 C9  00 9B
LocalDateTime: {
    "seconds": 100000000,
    "nanoseconds": 155
}
Duration: {
    "months": 10,
    "days": 20,
    "seconds": 0,
    "nanoseconds": 5
}
B4 45 0A 14  00 05
Duration: {
    "months": 10,
    "days": 20,
    "seconds": 0,
    "nanoseconds": 5
}
Point2D: {
    "srid": 105,
    "x": 10.2,
    "y": 15.3
}
B3 58 69 C1  40 24 66 66  66 66 66 66  C1 40 2E 99  99 99 99 99
9A
Point2D: {
    "srid": 105,
    "x": 10.2,
    "y": 15.3
}
Point3D: {
    "srid": 101,
    "x": 5.2,
    "y": 10.7,
    "z": 4.9
}
B4 59 65 C1  40 14 CC CC  CC CC CC CD  C1 40 25 66  66 66 66 66
66 C1 40 13  99 99 99 99  99 9A
Point3D: {
    "srid": 101,
    "x": 5.2,
    "y": 10.7,
    "z": 4.9
}
Structure: {
    "fields": [
        {
            "a": 5,
            "b": 10
        }
    ],
    "sig": 112
}
B1 70 A2 81  61 05 81 62  0A
Structure: {
    "fields": [
        {
            "a": 5,
            "b": 10
        }
    ],
    "sig": 112
}