SFS2X Objective-C API  1.7.13
iOS / macOS / tvOS
SFSArray.h
1 //
2 // SFSArray.h
3 // SFS2X
4 //
5 // Original development by Infosfer Game Technologies Ltd. | http://www.infosfer.com.
6 //
7 // Maintained and developed by A51 Integrated.
8 // Copyright 2012 A51 Integrated | http://a51integrated.com. All rights reserved.
9 //
10 
11 #import "ISFSArray.h"
12 #import "ISFSDataSerializer.h"
13 
14 
15 /** SFSArray is used from both server and client sides to exchange data. It can be thought of a specialized Array/List object that can contain any type of data.
16 
17  The advantage of using SFSArray is that you can fine tune the way your data will be transmitted over the network.
18  For instance, a number like 100 can be transmitted as a normal <b>integer</b> (which takes 32 bits) but also a <b>short</b> (16 bit) or even a <b>byte</b> (8 bit)
19 
20  SFSArray supports many primitive data types and related arrays of primitives. It also allows to serialize class instances and rebuild them on the Java side. This is explained in greater detail in a separate document.
21 
22  <a href="http://docs2x.smartfoxserver.com/DevelopmentBasics/sfsobject-sfsarray" target="_blank">More details and examples.</a>
23 
24  @see ISFSArray
25  @see SFSObject
26  */
27 @interface SFSArray : NSObject <ISFSArray> {
28 @private
29 
30  id <ISFSDataSerializer> _serializer;
31  NSMutableArray *_dataHolder;
32 
33 }
34 
35 /** Alternative static constructor that builds an SFSArray populated with the data found in the passed Array */
36 +(SFSArray *)newFromArray:(NSArray *)arr;
37 /** Alternative static constructor that builds an SFSArray from a valid SFSArray binary representation */
38 +(SFSArray *)newFromBinaryData:(NSData *)data;
39 /** Alternative static constructor */
40 +(SFSArray *)newInstance;
41 
42 
43 /** Returns true if the passed object is contained in the Array */
44 -(BOOL)contains:(id)obj;
45 
46 /** Returns the element at the specified index */
47 -(id)getElementAt:(NSInteger)index;
48 
49 /** */
50 -(SFSDataWrapper *)getWrappedElementAt:(NSInteger)index;/** @endcond */
51 
52 /** Remove the element at the specified index */
53 -(id)removeElementAt:(NSInteger)index;
54 
55 /** Return the number of elements in the Array */
56 -(NSInteger)size;
57 
58 /** Return the binary form of the object */
59 -(NSData *)toBinary;
60 
61 /**
62  Return a formatted dump of the object that can logged or traced in the console
63  for debugging purposes.
64 
65  @param format turns the "pretty print" on/off
66  */
67 -(NSString *)getDump:(BOOL)format;
68 
69 /**
70  Returns a detailed hex-dump of the object that can logged or traced in the console
71  for debugging purposes.
72  */
73 -(NSString *)getHexDump;
74 
75 /** Add a null element */
76 -(void)addNull;
77 
78 /** Add a Boolean value */
79 -(void)addBool:(BOOL)value;
80 
81 /** Add a byte value (8 bit) */
82 -(void)addByte:(NSInteger)value;
83 
84 /** Add a short int value (16 bit) */
85 -(void)addShort:(NSInteger)value;
86 
87 /** Add an int value (32 bit) */
88 -(void)addInt:(NSInteger)value;
89 
90 /** Add a long int value (64 bit) */
91 -(void)addLong:(NSNumber *)value;
92 
93 /** Add a float value (32 bit) */
94 -(void)addFloat:(NSNumber *)value;
95 
96 /** Add a dobule value (64 bit) */
97 -(void)addDouble:(NSNumber *)value;
98 
99 /** Add a UTF-8 String (use with strings <= 32KB) */
100 -(void)addUtfString:(NSString *)value;
101 
102 /** Add an array of Booleans */
103 -(void)addBoolArray:(NSArray *)value;
104 
105 /** Add an array of bytes */
106 -(void)addByteArray:(NSData *)value;
107 
108 /** Add an array of short ints */
109 -(void)addShortArray:(NSArray *)value;
110 
111 /** Add an array of ints */
112 -(void)addIntArray:(NSArray *)value;
113 
114 /** Add an array of long ints */
115 -(void)addLongArray:(NSArray *)value;
116 
117 /** Add an array of floats */
118 -(void)addFloatArray:(NSArray *)value;
119 
120 /** Add an array of doubles */
121 -(void)addDoubleArray:(NSArray *)value;
122 
123 /** Add an array of UTF-8 String */
124 -(void)addUtfStringArray:(NSArray *)value;
125 
126 /** Add an SFSArray */
127 -(void)addSFSArray:(id<ISFSArray>)value;
128 
129 /**
130  Add an SFSObject
131  @see SFSObject
132  */
133 -(void)addSFSObject:(id<ISFSObject>)value;
134 
135 -(void)addClass:(id)value;
136 
137 /**
138  Add a UTF-8 string to the end of this array (use with strings > 32KB, up to 2GB)
139  Requires API 1.7.x or higher
140  */
141 -(void)addText:(NSString*)value;
142 
143 /** */
144 -(void)add:(SFSDataWrapper *)wrappedObject;/** @endcond */
145 
146 /** Checks if a certain element in the Array is null */
147 -(BOOL)isNull:(NSInteger)index;
148 
149 /** Get a Boolean element at the provided index */
150 -(BOOL)getBool:(NSInteger)index;
151 
152 /** Get a byte element at the provided index */
153 -(NSInteger)getByte:(NSInteger)index;
154 
155 /** Get an unsigned byte element at the provided index */
156 -(NSInteger)getUnsignedByte:(NSInteger)index;
157 
158 /** Get a short int element at the provided index */
159 -(NSInteger)getShort:(NSInteger)index;
160 
161 /** Get an int element at the provided index */
162 -(NSInteger)getInt:(NSInteger)index;
163 
164 /** Get a long int element at the provided index */
165 -(NSNumber *)getLong:(NSInteger)index;
166 
167 /** Get a float element at the provided index */
168 -(NSNumber *)getFloat:(NSInteger)index;
169 
170 /** Get a double element at the provided index */
171 -(NSNumber *)getDouble:(NSInteger)index;
172 
173 /** Get a String element at the provided index */
174 -(NSString *)getUtfString:(NSInteger)index;
175 
176 /** Get a Boolean Array element at the provided index */
177 -(NSArray *)getBoolArray:(NSInteger)index;
178 
179 /** Get a byte Array element at the provided index */
180 -(NSData *)getByteArray:(NSInteger)index;
181 
182 /** Get an Array of unsigned integers at the provided index */
183 -(NSArray *)getUnsignedByteArray:(NSInteger)index;
184 
185 /** Get a short Array element at the provided index */
186 -(NSArray *)getShortArray:(NSInteger)index;
187 
188 /** Get a int Array element at the provided index */
189 -(NSArray *)getIntArray:(NSInteger)index;
190 
191 /** Get a lomg Array element at the provided index */
192 -(NSArray *)getLongArray:(NSInteger)index;
193 
194 /** Get a float Array element at the provided index */
195 -(NSArray *)getFloatArray:(NSInteger)index;
196 
197 /** Get a double Array element at the provided index */
198 -(NSArray *)getDoubleArray:(NSInteger)index;
199 
200 /** Get a String Array element at the provided index */
201 -(NSArray *)getUtfStringArray:(NSInteger)index;
202 
203 /** Get an SFSArray element at the provided index */
204 -(id <ISFSArray>)getSFSArray:(NSInteger)index;
205 
206 /** Get an SFSObject element at the provided index */
207 -(id <ISFSObject>)getSFSObject:(NSInteger)index;
208 
209 -(id)getClass:(NSInteger)index;
210 
211 /**
212  Get a String element at the provided index (use with strings > 32KB)
213  Requires API 1.7.x or higher
214  */
215 -(NSString *) getText:(NSInteger) index;
216 
217 @end
SFSDataWrapper
Definition: SFSDataWrapper.h:13
SFSArray
Definition: SFSArray.h:27