Code Monkey home page Code Monkey logo

data-packer's Introduction

简介

data-packer是一个数据打包工具。将通过一系列操作将数据从传入数据容器导入到传出容器中. 数据打包中的一个字段打包,将由以下步骤构成:

  1. 从传入数据容器中获取数据
  2. 遍历字段校验器列表,对该字段进行校验(如过用户传入了). 以检查传入数据的:类型,长度,取值等是否合法
  3. 遍历字段转换器列表,对该字段值进行转换(如果用户传入了). 以便将传入数据值转换为我们期望的格式/类型等
  4. 设置转换后的字段值到传出数据容器

定义

  • data-packer是字段提取,校验,打包的工具包.
  • 将数据打包逻辑中设计到的实体抽象为:
    • 字段 定义不同类型的字段,相互组合形成最终的期望的数据组成结构
    • 校验器 当需要对原始数据进行校验时使用, 如校验数据类型,取值范围
    • 转换器 当原始数据需要进一步加工处理时使用. 比如长度截取,类型转换等
    • 数据容器 将原始数据和目的数据抽象为数据容器,便于再数据打包过程中处理

组成

  • field包,用来定义常见的字段类型。 如:
    • 必填字段(RequiredField)
    • 可选字段(DefaultField)
    • 缺省值字段(DefaultField)
    • 占位字段(PlaceholderField)
    • 多选字段(SelectorField)
    • 组合字段(CompositedField)
  • checker包: 定义字段校验器类, 用于校验传入容器中的字段值是否合法
  • converter包: 定义字段值转换器类, 用于按需转换传入数据容器中的字段值
  • container包: 定义一些数据容器类, 用于封装原始数据和目的数据,以便于数据打包

应用场景

  1. 微信支付业务中,封装到微信的请求数据,解析微信的返回数据。
  2. web业务中,解析并转换web端传入的请求数据。
  3. 服务提供端:预定义一系列的DataPacker对象,用于验证和转换 前段传入的数据为内部可用的数据容器。
  4. 服务请求端:按照服务提供方要求的数据格式创建好DataPacker对象后,将请求的原始数据容器快捷方便的转为服务提供方需要的格式。

示例

参见example目录

data-packer's People

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.