CCHBinaryData 1.0.2

CCHBinaryData 1.0.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布时间最新发布2015年9月

Claus Höfele维护。



处理二进制数据的实用类,例如从字节数据缓冲区中读取各种数据类型。

  

查看发布以获取最新更新的高级概述。

需要与人交谈? 我在 Twitter 上是 @claushoefele

安装

使用 CocoaPodsCCHBinaryData 集成到您的项目中。最低部署目标是 iOS 7.0 和 OS X 10.9。

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

读取二进制数据

CCHBinaryDataReader 可以从作为 NSData 提供的字节数据缓冲区中读取各种数据类型。以下示例代码从 PNG 图像文件中读取块信息

    // 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];
    }