• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSData problems and viewing buffer data in hex
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSData problems and viewing buffer data in hex


  • Subject: NSData problems and viewing buffer data in hex
  • From: William Squires <email@hidden>
  • Date: Wed, 07 May 2014 11:21:05 -0500

Quickie question: Does [NSData getBytes:range:] return <range>.length bytes into the buffer specified, even if some of the bytes may be '\0' (terminating null), so long as range is valid? I'm trying to read in a specified record from a random-access file (record length is 1000 bytes = kRecSize), and I have a self.fileContents that's an  @property (nonatomic, strong) NSData *fileContents, which I set up as follows:

"FSSBorr.m"
-----------
#import "FSSBorr.h"

char buffer[kRecSize + 1]; // <-file scope

#pragma mark "Private Suff"

@interface FSSBorr ()

@property (nonatomic, assign) BORR_REC theRec;
@property (nonatomic, copy) NSString *fileName;     // These two are set up in my initWithFile:
@property (nonatomic, strong) NSData *fileContents; // ditto

@end

@implementation FSSBorr

...

-(void)loadRec:(NSUInteger)index
{
NSUInteger byteOffset = index * kRecSize;
NSRange recordRange = NSMakeRange(byteOffset, kRecSize);
char *c = &buffer[0];
char *p = (char *)(&_theRec);

@try
  {
  [self.fileContents getBytes:buffer range:recordRange]; // Problem is here - not reading in all 1000 bytes.
  memccpy(p, c, kRecSize, sizeof(char));
  }
@catch (NSException *ex)
  {
  NSLog(@"%ul beyond end of file.\n", (unsigned int)index);
  NSLog(@"NSException thrown: %@\n", [ex description]);
  }
}

@end

The file in question is several hundred kB long, and "index" = 1 for this debug session. Is there some way to view the buffer (contents) as a hex dump? I know what the bytes should be (I used "hexdump -Cv <filename>.dat > <filename>.txt to get the hex dump of <filename>.dat, which is what self.fileContents is loaded with in my initWithFile: method of this class.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSData problems and viewing buffer data in hex
      • From: Uli Kusterer <email@hidden>
    • Re: NSData problems and viewing buffer data in hex
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: Help with Help
  • Next by Date: Re: NSData problems and viewing buffer data in hex
  • Previous by thread: Re: Resizing last column of NSTableView when it touches window border
  • Next by thread: Re: NSData problems and viewing buffer data in hex
  • Index(es):
    • Date
    • Thread