Giter Site home page Giter Site logo

mingun / serde-pod Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 22 KB

Простая сериализация данных в формате, близком к расположению элементов в памяти

License: MIT License

Rust 100.00%
serde-serialization serde pod

serde-pod's Introduction

serde-pod (plain old data)

Реализует простую сериализацию и десериализацию структур, наиболее близкую к их представлению в памяти.

Пример

Читаем заголовок GFF файла (формат Bioware, используемый для хранения данных в таких играх, как Neverwinter Nights, Neverwinter Nights 2 и Ведьмак):

extern crate byteorder;
#[macro_use]
extern crate serde_derive;
extern crate serde_pod;
use serde_pod::{from_bytes, Result};

#[derive(Debug, Deserialize, PartialEq)]
struct Signature([u8; 4]);

#[derive(Debug, Deserialize, PartialEq)]
struct Version([u8; 4]);

#[derive(Debug, Deserialize, PartialEq)]
struct Section {
  offset: u32,
  count:  u32,
}
#[derive(Debug, Deserialize, PartialEq)]
struct GffHeader {
  signature:     Signature,
  version:       Version,
  structs:       Section,
  fields:        Section,
  labels:        Section,
  field_data:    Section,
  field_indices: Section,
  list_indices:  Section,
}

fn main() {
  let header: GffHeader = from_bytes::<byteorder::LE, _>(&[
    // Signature
    0x47, 0x55, 0x49, 0x20,
    // Version
    0x56, 0x33, 0x2E, 0x32,
    // structs
    0x38, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00,
    // fields
    0xEC, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00,
    // labels
    0xD0, 0x07, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00,
    // field_data
    0x70, 0x09, 0x00, 0x00, 0x1D, 0x02, 0x00, 0x00,
    // field_indices
    0x8D, 0x0B, 0x00, 0x00, 0x4C, 0x02, 0x00, 0x00,
    // list_indices
    0xD9, 0x0D, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
  ])?;

  assert_eq!(header, GffHeader {
    signature:     Signature(*b"GUI "),
    version:       Version(*b"V3.2"),
    structs:       Section { offset:   0x38, count:  15 },
    fields:        Section { offset:   0xEC, count: 147 },
    labels:        Section { offset: 0x07D0, count:  26 },
    field_data:    Section { offset: 0x0970, count: 541 },
    field_indices: Section { offset: 0x0B8D, count: 588 },
    list_indices:  Section { offset: 0x0DD9, count:  36 },
  });
}

serde-pod's People

Contributors

dependabot-preview[bot] avatar mingun avatar

Stargazers

 avatar

Watchers

 avatar  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.