GithubHelp home page GithubHelp logo

huangyq23 / lilliput Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkolb/lilliput

0.0 3.0 0.0 363 KB

A native Swift framework for working with binary data of varying endianness

License: MIT License

Swift 95.90% Objective-C 4.10%

lilliput's Introduction

Lilliput 1.1.3

####ChangeLog

######1.1.3 Provide accessor for direct access to the buffer's memory.

######1.1.2 Forgot to update README.

######1.1.1 Minor improvements and fixes.

######1.1.0 Updated to support Swift 2.

######1.0.5 Have to check for "arm" also to prevent compile errors on 32-bit devices.

######1.0.4 Missed two more tests that will not compile on 32-bit devices.

######1.0.3 Add compile configuration protection around tests that won't compile on 32-bit devices.

######1.0.2 Attempting to allow building for both iOS and OSX using one project file.

============ Carthage compatible

Lilliput is a native Swift framework for working with binary data of varying endianness. For example you can use it to do custom loading of PNG files which are written in big endian byte order, or tinker with reverse engineering game data files which is what I use it for.

There are only two types in the framework:

ByteOrder - Handles converting values between little and big endianness

ByteBuffer - A collection of bytes with a specific byte order

ByteOrder and ByteBuffer are loosely based on similar classes found in Java of the same name, so knowledge of them should help you here.

Examples

Putting and getting a big endian 32 bit integer

let buffer = ByteBuffer(order: BigEndian(), capacity: 100)
buffer.putUInt32(1024) // Put this value at the current position of the buffer
buffer.flip() // Reset the position to 0 and set the limit to 4 (the amout of bytes written)
let value = buffer.getUInt32() // Get the value at the current position of the buffer

Rough parsing of a PNG file

let pngBuffer = ByteBuffer(order: BigEndian(), capacity: 4096) // Filled from a file
buffer.flip() // Must flip before reading after you write to a buffer
let signature = buffer.getUInt8(8)

if signature != [UInt8][137, 80, 78, 71, 13, 10, 26, 10] {
    println("Not a PNG file")
    return
}

let chunkLength = buffer.getUInt32()
let chunkType = buffer.getUInt8(4)
let chunkData = buffer.getUInt8(chunkLength)
let chunkCRC = buffer.getUInt32()

Installation

Can install via Carthage, or by dragging and dropping the project file into your project.

Contact

Justin Kolb
@nabobnick

License

Lilliput is available under the MIT license. See the LICENSE file for more info.

lilliput's People

Contributors

jkolb avatar

Watchers

Yiqiu Huang avatar James Cloos 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.