Skip to content

Commit

Permalink
Added cbor decoder that uses data instead of inputstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Nov 12, 2024
1 parent 610eff2 commit 82f32c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ NS_ASSUME_NONNULL_BEGIN
*/
@protocol YKFCBORDecoderProtocol<NSObject>

/*!
@abstract
Decodes a CBOR type from NSData.
@returns
The object or nil if the object could not be parsed.
*/
+ (nullable id)decodeObjectFromData:(NSData *)data;

/*!
@abstract
Decodes a CBOR type from an input stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ - (NSData *)dequeueBytes:(NSUInteger)numberOfBytes;

@implementation YKFCBORDecoder

+ (nullable id)decodeObjectFromData:(NSData *)data {
NSInputStream *decoderInputStream = [[NSInputStream alloc] initWithData:data];
[decoderInputStream open];
id result = [YKFCBORDecoder decodeObjectFrom:decoderInputStream];
[decoderInputStream close];
return result;
}

+ (nullable id)decodeObjectFrom:(NSInputStream *)inputStream {
YKFAssertReturnValue(inputStream, @"CBOR - Decoding input stream is nil.", nil);
YKFAssertReturnValue(inputStream.streamStatus == NSStreamStatusOpen, @"CBOR - Decoding input stream not opened.", nil);
Expand Down

0 comments on commit 82f32c3

Please sign in to comment.