SFS2X Objective-C API  1.7.13
iOS / macOS / tvOS
SFSObject.h
1 //
2 // SFSObject.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 "ISFSObject.h"
12 #import "ISFSDataSerializer.h"
13 
14 /** SFSObject is used from both server and client sides to exchange data. It can be thought of a specialized Dictionary/Map object that can contain any type of data.
15 
16  The advantage of using SFSObject is that you can fine tune the way your data will be transmitted over the network.
17  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)
18 
19  SFSObject supports many primitive data types and related arrays of primitives. It also allows to serialize class instances and rebuild them on the Java side.
20  This is explained in greater detail in a separate document.
21 
22  <b>NOTE: </b>UTF-8/multi-byte strings are not supported in key names. In other words you should restrict key names to standard ASCII characters. It is also recommended to keep key names very short to save bandwidth.
23 
24 <a href="http://docs2x.smartfoxserver.com/DevelopmentBasics/sfsobject-sfsarray" target="_blank">More details and examples.</a>
25 
26  @see ISFSObject
27  @see SFSArray
28  */
29 @interface SFSObject : NSObject <ISFSObject>{
30  NSMutableDictionary *_dataHolder;
31  id <ISFSDataSerializer> _serializer;
32 }
33 
34 /** Alternative static constructor */
35 +(id)newInstance;
36 /** Alternative static constructor that builds an SFSObject from a valid SFSObject binary representation */
37 +(id)newFromBinaryData:(NSData *)packet;
38 
39 
40 /** Checks if a specific element in the SFSObject is null */
41 -(BOOL)isNull:(NSString *)key;
42 
43 /** Returns true if an element exists with the provided key */
44 -(BOOL)containsKey:(NSString *)key;
45 
46 /** Removes an element */
47 -(void)removeElement:(NSString *)key;
48 
49 /** Return an array with all the keys in the SFSObject */
50 -(NSArray *)getKeys;
51 
52 /** Return the number of elements in the SFSObject */
53 -(NSInteger)size;
54 
55 /** Return the binary form of the object */
56 -(NSData *)toBinary;
57 
58 /**
59  Return a formatted dump of the object that can logged or traced in the console
60  for debugging purposes.
61 
62  @param format turns the "pretty print" on/off
63  */
64 -(NSString *)getDump:(BOOL)format;
65 
66 /**
67  Returns a detailed hex-dump of the object that can logged or traced in the console
68  for debugging purposes.
69  */
70 -(NSString *)getHexDump;
71 
72 -(SFSDataWrapper *)getData:(NSString *)key;
73 
74 /** Get the element for the provided key as a Boolean */
75 -(BOOL)getBool:(NSString *)key;
76 
77 /** Get the element for the provided key as a signed byte (8 bit) (int in AS3) */
78 -(NSInteger)getByte:(NSString *)key;
79 
80 /** Get the element for the provided key as a unsigned byte (8 bit) (int in AS3) */
81 -(NSInteger)getUnsignedByte:(NSString *)key;
82 
83 /** Get the element for the provided key as a short int (16 bit) (int in AS3) */
84 -(NSInteger)getShort:(NSString *)key;
85 
86 /** Get the element for the provided key as an int (32 bit) */
87 -(NSInteger)getInt:(NSString *)key;
88 
89 /** Get the element for the provided key as a long int (64 bit) (Number in AS3) */
90 -(NSNumber *)getLong:(NSString *)key;
91 
92 /** Get the element for the provided key as a float (Number in AS3) */
93 -(NSNumber *)getFloat:(NSString *)key;
94 
95 /** Get the element for the provided key as a double (Number in AS3) */
96 -(NSNumber *)getDouble:(NSString *)key;
97 
98 /** Get the element for the provided key as a UTF-8 String (use with strings <= 32KB) */
99 -(NSString *)getUtfString:(NSString *)key;
100 
101 /** Get the element for the provided key as an array of Booleans */
102 -(NSArray *)getBoolArray:(NSString *)key;
103 
104 /** Get the element for the provided key as a an array of byte */
105 -(NSData *)getByteArray:(NSString *)key;
106 
107 /** Get the element for the provided key as a an array of integers representing each byte as unsigned values */
108 -(NSArray *)getUnsignedByteArray:(NSString *)key;
109 
110 /** Get the element for the provided key as an array of short int */
111 -(NSArray *)getShortArray:(NSString *)key;
112 
113 /** Get the element for the provided key as an array of int */
114 -(NSArray *)getIntArray:(NSString *)key;
115 
116 /** Get the element for the provided key as an array of long int */
117 -(NSArray *)getLongArray:(NSString *)key;
118 
119 /** Get the element for the provided key as an array of floats */
120 -(NSArray *)getFloatArray:(NSString *)key;
121 
122 /** Get the element for the provided key as an array of doubles */
123 -(NSArray *)getDoubleArray:(NSString *)key;
124 
125 /** Get the element for the provided key as an array of UTF-8 Strings (use with strings <= 32KBytes)*/
126 -(NSArray *)getUtfStringArray:(NSString *)key;
127 
128 /**
129  Get the element for the provided key as a UTF-8 String (use with strings > 32KB, up 2GB)
130  Requires API 1.7.x or higher
131  */
132 -(NSString *) getText:(NSString* )key;
133 
134 /**
135  Get the element for the provided key as an SFSArray
136  */
137 -(id <ISFSArray>)getSFSArray:(NSString *)key;
138 
139 /** Get the element for the provided key as an SFSObject */
140 -(id <ISFSObject>)getSFSObject:(NSString *)key;
141 
142 
143 
144 
145 -(id)getClass:(NSString *)key;
146 
147 -(void)putNull:(NSString *)key;
148 
149 /** Put a Boolean value with the provided key */
150 -(void)putBool:(NSString *)key value:(BOOL)value;
151 
152 /** Put a byte value (8 bit) with the provided key */
153 -(void)putByte:(NSString *)key value:(NSInteger)value;
154 
155 /** Put a short int (16 bit) with the provided key */
156 -(void)putShort:(NSString *)key value:(NSInteger)value;
157 
158 /** Put an int (32 bit) with the provided key */
159 -(void)putInt:(NSString *)key value:(NSInteger)value;
160 
161 /** Put a long int (64 bit) with the provided key */
162 -(void)putLong:(NSString *)key value:(NSNumber *)value;
163 
164 /** Put a float (32 bit) with the provided key */
165 -(void)putFloat:(NSString *)key value:(NSNumber *)value;
166 
167 /** Put a double (64 bit) with the provided key */
168 -(void)putDouble:(NSString *)key value:(NSNumber *)value;
169 
170 /** Put a UTF-8 String with the provided key */
171 -(void)putUtfString:(NSString *)key value:(NSString *)value;
172 
173 /** Put an array of Booleans with the provided key */
174 -(void)putBoolArray:(NSString *)key value:(NSArray *)value;
175 
176 /** Put an array of bytes with the provided key */
177 -(void)putByteArray:(NSString *)key value:(NSData *)value;
178 
179 /** Put an array of short ints with the provided key */
180 -(void)putShortArray:(NSString *)key value:(NSArray *)value;
181 
182 /** Put an array of ints with the provided key */
183 -(void)putIntArray:(NSString *)key value:(NSArray *)value;
184 
185 /** Put an array of long ints with the provided key */
186 -(void)putLongArray:(NSString *)key value:(NSArray *)value;
187 
188 /** Put an array of floats with the provided key */
189 -(void)putFloatArray:(NSString *)key value:(NSArray *)value;
190 
191 /** Put an array of doubles with the provided key */
192 -(void)putDoubleArray:(NSString *)key value:(NSArray *)value;
193 
194 /** Put an array of Strings with the provided key (use with strings <= 32KB) */
195 -(void)putUtfStringArray:(NSString *)key value:(NSArray *)value;
196 
197 /**
198  Put an array of Strings with the provided key (use with strings > 32KB, up to 2GB)
199  Requires API 1.7.x or higher
200  */
201 -(void)putText:(NSString *)key value:(NSString*)value;
202 
203 /**
204  Put an SFSArray with the provided key
205 
206  @see SFSArray
207  */
208 -(void)putSFSArray:(NSString *)key value:(id<ISFSArray>)value;
209 
210 /** Put an SFSObject with the provided key */
211 -(void)putSFSObject:(NSString *)key value:(id<ISFSObject>)value;
212 
213 -(void)putClass:(NSString *)key value:(id)value;
214 
215 -(void)put:(NSString *)key value:(SFSDataWrapper *)value;
216 
217 @end
SFSObject
Definition: SFSObject.h:29
SFSDataWrapper
Definition: SFSDataWrapper.h:13