This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
WSBuffer.h
116 lines (91 loc) · 3.6 KB
/
WSBuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// WSBuffer.h
// BitcoinSPV
//
// Created by Davide De Rosa on 16/06/14.
// Copyright (c) 2014 Davide De Rosa. All rights reserved.
//
// https://github.com/keeshux
//
// This file is part of BitcoinSPV.
//
// BitcoinSPV is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// BitcoinSPV is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with BitcoinSPV. If not, see <http://www.gnu.org/licenses/>.
//
#import <Foundation/Foundation.h>
@class WSParameters;
@class WSHash256;
@class WSHash160;
@class WSNetworkAddress;
@class WSInventory;
#pragma mark -
@interface WSBuffer : NSObject <NSCopying, NSMutableCopying>
- (instancetype)init;
- (instancetype)initWithData:(NSData *)data;
- (NSData *)data;
- (uint8_t)uint8AtOffset:(NSUInteger)offset;
- (uint16_t)uint16AtOffset:(NSUInteger)offset;
- (uint32_t)uint32AtOffset:(NSUInteger)offset;
- (uint64_t)uint64AtOffset:(NSUInteger)offset;
- (uint64_t)varIntAtOffset:(NSUInteger)offset length:(NSUInteger *)length;
- (NSString *)stringAtOffset:(NSUInteger)offset length:(NSUInteger *)length;
- (WSNetworkAddress *)networkAddressAtOffset:(NSUInteger)offset;
- (WSNetworkAddress *)legacyNetworkAddressAtOffset:(NSUInteger)offset;
- (WSInventory *)inventoryAtOffset:(NSUInteger)offset;
- (WSHash256 *)hash256AtOffset:(NSUInteger)offset;
- (NSData *)varDataAtOffset:(NSUInteger)offset length:(NSUInteger *)length;
- (NSData *)dataAtOffset:(NSUInteger)offset length:(NSUInteger)length;
- (WSBuffer *)subBufferWithRange:(NSRange)range;
- (WSHash256 *)computeHash256;
- (WSHash160 *)computeHash160;
- (NSString *)hexString;
- (const void *)bytes;
- (NSUInteger)length;
@end
#pragma mark -
@interface WSMutableBuffer : WSBuffer
- (instancetype)initWithCapacity:(NSUInteger)capacity;
- (NSMutableData *)mutableData;
- (void)appendUint8:(uint8_t)n;
- (void)appendUint16:(uint16_t)n;
- (void)appendUint32:(uint32_t)n;
- (void)appendUint64:(uint64_t)n;
- (void)appendVarInt:(uint64_t)n;
- (void)appendString:(NSString *)string;
- (void)appendNullPaddedString:(NSString *)string length:(NSUInteger)length;
- (void)appendNetworkAddress:(WSNetworkAddress *)networkAddress;
- (void)appendInventory:(WSInventory *)inventory;
- (void)appendHash256:(WSHash256 *)hash256;
- (void)appendData:(NSData *)data;
- (void)appendVarData:(NSData *)data;
- (void)appendBuffer:(WSBuffer *)buffer;
- (void)appendVarBuffer:(WSBuffer *)buffer;
- (void)appendBytes:(const void *)bytes length:(NSUInteger)length;
- (void *)mutableBytes;
- (void)setLength:(NSUInteger)length;
- (void)replaceBytesInRange:(NSRange)range withBytes:(const void *)bytes length:(NSUInteger)length;
@end
#pragma mark -
@protocol WSBufferDecoder <NSObject>
- (instancetype)initWithParameters:(WSParameters *)parameters buffer:(WSBuffer *)buffer from:(NSUInteger)from available:(NSUInteger)available error:(NSError **)error;
@end
#pragma mark -
@protocol WSBufferEncoder <NSObject>
- (void)appendToMutableBuffer:(WSMutableBuffer *)buffer;
- (WSBuffer *)toBuffer;
@end
#pragma mark -
extern const uint8_t WSBufferVarInt16Byte;
extern const uint8_t WSBufferVarInt32Byte;
extern const uint8_t WSBufferVarInt64Byte;
extern NSUInteger WSBufferVarIntSize(uint64_t i);