//
//  NSData-BytePacking.h
//
//  Created by Philippe Hausler on 9/10/08.
//  Copyright 2008 Philippe Hausler. All rights reserved.
//

#import <Foundation/Foundation.h>

enum {
	NSLittleEndian = -1,
	NSSameEndian = 0,
	NSBigEndian = 1
};
typedef NSInteger NSByteEndian;

NSByteEndian NSHostEndian(void);

@interface NSString (BytePacking)
+ (id)stringWithData:(NSData *)data encoding:(NSStringEncoding)encoding;
@end

@interface NSData (BytePacking)
- (NSString *)stringUsingEncoding:(NSStringEncoding)encoding;
- (BOOL)hasPrefix:(NSData *)data;
- (BOOL)hasSuffix:(NSData *)data;
- (BOOL)hasUTF8Prefix:(NSString *)prefix;
- (BOOL)hasUTF8Suffix:(NSString *)suffix;
+ (NSData *)dataWithUTF8String:(NSString *)aString;
- (unsigned char)byteAtIndex:(NSUInteger)index;
- (unsigned int)uintAtIndex:(NSUInteger)index;
- (NSData *)dataUntilTermination:(NSData *)terminator;
+ (id)dataWithByte:(unsigned char)byte;
@end

@interface NSMutableData (BytePacking)
- (void)pad:(NSData *)pad count:(NSUInteger)count;

- (void)appendString:(NSString *)aString encoding:(NSStringEncoding)encoding;

- (void)appendByte:(unsigned char)byte;
- (void)appendShort:(short)number;
- (void)appendUShort:(unsigned short)number;
- (void)appendInt:(int)number;
- (void)appendUInt:(unsigned int)number;
- (void)appendLong:(long)number;
- (void)appendULong:(unsigned long)number;
- (void)appendDouble:(double)number;
- (void)appendLongLong:(long long)number;
- (void)appendULongLong:(unsigned long long)number;

- (void)appendShort:(short)number ordered:(NSByteEndian)endian;
- (void)appendUShort:(unsigned short)number ordered:(NSByteEndian)endian;
- (void)appendInt:(int)number ordered:(NSByteEndian)endian;
- (void)appendUInt:(unsigned int)number ordered:(NSByteEndian)endian;
- (void)appendLong:(long)number ordered:(NSByteEndian)endian;
- (void)appendULong:(unsigned long)number ordered:(NSByteEndian)endian;
- (void)appendDouble:(double)number ordered:(NSByteEndian)endian;
- (void)appendLongLong:(long long)number ordered:(NSByteEndian)endian;
- (void)appendULongLong:(unsigned long long)number ordered:(NSByteEndian)endian;
@end
