Skip to content
Utility classes for handling binary data
Objective-C Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CCHBinaryData Example
CCHBinaryData Tests
CCHBinaryData
.gitignore
.travis.yml
CCHBinaryData.podspec
LICENSE
README.md

README.md

CCHBinaryData

Utility classes for handling binary data, such as reading various data types from byte buffers.

Build Status Version Platform

See Releases for a high-level overview of recent updates.

Need to talk to a human? I'm @claushoefele on Twitter.

Installation

Use CocoaPods to integrate CCHBinaryData into your project. Minimum deployment targets are 7.0 for iOS and 10.9 for OS X.

platform :ios, '7.0'
pod "CCHBinaryData"
platform :osx, '10.9'
pod "CCHBinaryData"

Reading binary data

CCHBinaryDataReader can read various data types from byte buffers provided as NSData. The following sample code reads chunk information from a PNG image file:

    // Read PNG file. Data is big endian, see http://www.w3.org/TR/PNG/#7Integers-and-byte-order
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"pngbar" ofType:@"png"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    CCHBinaryDataReader *binaryDataReader = [[CCHBinaryDataReader alloc] initWithData:data options:CCHBinaryDataReaderBigEndian];
    
    // Skip file signature
    [binaryDataReader setNumberOfBytesRead:8];
    
    // Read chunks, see http://www.w3.org/TR/PNG/#5Chunk-layout
    while ([binaryDataReader canReadNumberOfBytes:4]) {
        unsigned int length = [binaryDataReader readUnsignedInt];
        NSString *chunkType = [binaryDataReader readStringWithNumberOfBytes:4 encoding:NSASCIIStringEncoding];
        [binaryDataReader skipNumberOfBytes:length];
        unsigned int crc = [binaryDataReader readUnsignedInt];
        
        [NSLog(@"%@ length: %tu, crc: 0x%08x\n", chunkType, length, crc];
    }
You can’t perform that action at this time.