Skip to content

Commit

Permalink
Roll cpp forward -- no more BinaryReader
Browse files Browse the repository at this point in the history
  • Loading branch information
mikerreed authored and duncandoit committed Apr 25, 2022
1 parent b58157d commit 63514bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions Source/Renderer/RiveFile.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ @implementation RiveFile {
rive::File* riveFile;
}

- (rive::BinaryReader) getReader:(UInt8 *)bytes byteLength:(UInt64)length {
return rive::BinaryReader(bytes, length);
}


+ (uint)majorVersion { return UInt8(rive::File::majorVersion); }
+ (uint)minorVersion { return UInt8(rive::File::minorVersion); }

Expand All @@ -39,8 +34,7 @@ - (nullable instancetype)initWithByteArray:(NSArray *)array error:(NSError**)err
[array enumerateObjectsUsingBlock:^(NSNumber* number, NSUInteger index, BOOL* stop){
bytes[index] = number.unsignedIntValue;
}];
rive::BinaryReader reader = [self getReader:bytes byteLength:array.count];
BOOL ok = [self import:reader error:error];
BOOL ok = [self import:bytes byteLength:array.count error:error];
if (!ok) {
return nil;
}
Expand All @@ -57,8 +51,7 @@ - (nullable instancetype)initWithByteArray:(NSArray *)array error:(NSError**)err

- (nullable instancetype)initWithBytes:(UInt8 *)bytes byteLength:(UInt64)length error:(NSError**)error {
if (self = [super init]) {
rive::BinaryReader reader = [self getReader:bytes byteLength:length];
BOOL ok = [self import:reader error:error];
BOOL ok = [self import:bytes byteLength:length error:error];
if (!ok) {
return nil;
}
Expand Down Expand Up @@ -104,10 +97,9 @@ - (nullable instancetype)initWithHttpUrl:(NSString *)url withDelegate:(id<RiveFi
// Load the data into the reader
NSData *data = [NSData dataWithContentsOfURL: location];
UInt8 *bytes = (UInt8 *)[data bytes];
rive::BinaryReader reader = [self getReader:bytes byteLength:[data length]];
// TODO: Do something with this error the proper way with delegates.
NSError* error = nil;
[self import:reader error:&error];
[self import:bytes byteLength:[data length] error:&error];
self.isLoaded = true;
dispatch_async(dispatch_get_main_queue(), ^{
if ([[NSThread currentThread] isMainThread]) {
Expand All @@ -130,9 +122,9 @@ - (nullable instancetype)initWithHttpUrl:(NSString *)url withDelegate:(id<RiveFi
return nil;
}

- (BOOL) import:(rive::BinaryReader)reader error:(NSError**)error {
- (BOOL) import:(UInt8 *)bytes byteLength:(UInt64)length error:(NSError**)error {
rive::ImportResult result;
riveFile = rive::File::import(reader, &result).release();
riveFile = rive::File::import(rive::Span(bytes, length), &result).release();
if (result == rive::ImportResult::success) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion submodules/rive-cpp

0 comments on commit 63514bb

Please sign in to comment.