Skip to main content

data serialize

Project description

data_serialize

This library allows reading and writing binary to string

Installation

pip3 install data_serialize

serialize and deserialize

#
import data_serialize
import numpy as np


def test_feature():
    val1 = data_serialize.Int64List(value=[1, 2, 3] * 20)
    val2 = data_serialize.FloatList(value=[1, 2, 3] * 20)
    val3 = data_serialize.BytesList(value=[b'The china', b'boy'])

    featrue = data_serialize.Features(feature=
    {
        "item_0": data_serialize.Feature(int64_list=val1),
        "item_1": data_serialize.Feature(float_list=val2),
        "item_2": data_serialize.Feature(bytes_list=val3)
    }
    )

    example = data_serialize.Example(features=featrue)

    # 序列化
    serialize = example.SerializeToString()
    print(serialize)

    # 反序列化
    example = data_serialize.Example()
    example.ParseFromString(serialize)
    print(example)


def test_numpyobject():
    a = np.random.randint(0, 21128, size=(10,), dtype=np.int64)
    b = np.random.rand(3, 4)
    c = np.asarray(b'The china')

    val1 = data_serialize.NumpyObject(
        header='',
        dtype=str(a.dtype),
        shape=list(a.shape),
        int64=a.reshape((-1,)).tolist(),
    )
    val2 = data_serialize.NumpyObject(
        header='',
        dtype=str(b.dtype),
        shape=list(b.shape),
        float64=b.reshape((-1,)).tolist(),
    )
    val3 = data_serialize.NumpyObject(
        header='',
        dtype=str(c.dtype),
        shape=list(c.shape),
        bytes=c.tobytes(),
    )

    example = data_serialize.NumpyObjectMap(numpyobjects={
        "item_0": val1,
        "item_1": val2,
        "item_2": val3}
    )
    # 序列化
    serialize = example.SerializeToString()
    print(serialize)

    # 反序列化
    example = data_serialize.NumpyObjectMap()
    example.ParseFromString(serialize)
    print(example)


test_feature()

test_numpyobject()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

data_serialize-0.4.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file data_serialize-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: data_serialize-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.2

File hashes

Hashes for data_serialize-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c7a5a784ea8fa505e761269860e76b2327e58da16ff9e07add266f6091a12a3
MD5 fcd35cf637890f00e5d9e6c84f02670e
BLAKE2b-256 06df4aab68bd269c8c56daaad0137de39cab964cf0b4cfec7a2bb0a9194285d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page