Lines Matching +full:buffer +full:- +full:from
8 * http://www.apache.org/licenses/LICENSE-2.0
24 /// it allows users to write and read data directly from memory thus the use of its
35 /// pointer to the start of the buffer object in memory
37 /// Capacity of UInt8 the buffer can hold
63 func copy(from ptr: UnsafeRawPointer, count: Int) { in copy()
66 "copy should NOT be called on a buffer that is built by assumingMemoryBound") in copy()
67 memory.copyMemory(from: ptr, byteCount: count) in copy()
74 "initalize should NOT be called on a buffer that is built by assumingMemoryBound") in initialize()
78 /// Reallocates the buffer incase the object to be written doesnt fit in the current buffer
79 /// - Parameter size: Size of the current object
82 let currentWritingIndex = capacity &- writerSize in reallocate()
87 /// solution take from Apple-NIO in reallocate()
93 memset(newData, 0, capacity &- writerSize) in reallocate()
95 newData.advanced(by: capacity &- writerSize), in reallocate()
105 /// The size of the elements written to the buffer + their paddings
107 /// Aliginment of the current memory being written to the buffer
109 …ent Index which is being used to write to the buffer, it is written from the end to the start of t…
110 var writerIndex: Int { _storage.capacity &- _writerSize }
112 /// Reader is the position of the current Writer Index (capacity - size)
114 /// Current size of the buffer
116 /// Public Pointer to the buffer object in memory. This should NOT be modified for any reason
118 /// Current capacity for the buffer
121 /// Constructor that creates a Flatbuffer object from a UInt8
122 /// - Parameter bytes: Array of UInt8
128 self._storage.copy(from: bufferPointer.baseAddress!, count: bytes.count)
133 /// Constructor that creates a Flatbuffer from the Swift Data type object
134 /// - Parameter data: Swift data Object
140 self._storage.copy(from: bufferPointer.baseAddress!, count: data.count)
146 /// - Parameter size: Length of the buffer
154 /// Constructor that creates a Flatbuffer object from a ContiguousBytes
155 /// - Parameters:
156 /// - contiguousBytes: Binary stripe to use as the buffer
157 /// - count: amount of readable bytes
165 _storage.copy(from: buf.baseAddress!, count: buf.count)
170 /// Constructor that creates a Flatbuffer from unsafe memory region without copying
171 /// - Parameter assumingMemoryBound: The unsafe memory region
172 /// - Parameter capacity: The size of the given memory region
181 /// Creates a copy of the buffer that's being built by calling sizedBuffer
182 /// - Parameters:
183 /// - memory: Current memory of the buffer
184 /// - count: count of bytes
187 _storage.copy(from: memory, count: count)
192 /// - Parameters:
193 /// - memory: Current memory of the buffer
194 /// - count: count of bytes
195 /// - removeBytes: Removes a number of bytes from the current size
202 _storage.copy(from: memory, count: count)
206 /// Fills the buffer with padding by adding to the writersize
207 /// - Parameter padding: Amount of padding between two to be serialized objects
216 /// Adds an array of type Scalar to the buffer memory
217 /// - Parameter elements: An array of Scalars
228 /// Adds an object of type NativeStruct into the buffer
229 /// - Parameters:
230 /// - value: Object that will be written to the buffer
231 /// - size: size to subtract from the WriterIndex
237 memcpy(_storage.memory.advanced(by: writerIndex &- size), &v, size) in push<T: NativeStruct>()
241 /// Adds an object of type Scalar into the buffer
242 /// - Parameters:
243 /// - value: Object that will be written to the buffer
244 /// - len: Offset to subtract from the WriterIndex
250 memcpy(_storage.memory.advanced(by: writerIndex &- len), &v, len) in push<T: Scalar>()
254 /// Adds a string to the buffer using swift.utf8 object
255 /// - Parameter str: String that will be added to the buffer
256 /// - Parameter len: length of the string
274 /// - Parameters:
275 /// - bytes: Pointer to the view
276 /// - len: Size of string
281 len: Int) -> Bool
284 _storage.memory.advanced(by: writerIndex &- len),
291 /// Write stores an object into the buffer directly or indirectly.
293 …/// Direct: ignores the capacity of buffer which would mean we are referring to the direct point i…
294 …t: takes into respect the current capacity of the buffer (capacity - index), writing to the buffer…
295 /// - Parameters:
296 /// - value: Value that needs to be written to the buffer
297 /// - index: index to write to
298 /// - direct: Should take into consideration the capacity of the buffer
303 index = _storage.capacity &- index in write<T>()
310 /// Makes sure that buffer has enouch space for each of the objects that will be written into it
311 /// - Parameter size: size of object
315 mutating func ensureSpace(size: Int) -> Int { in ensureSpace()
319 assert(size < FlatBufferMaxSize, "Buffer can't grow beyond 2 Gigabytes") in ensureSpace()
323 /// pops the written VTable if it's already written into the buffer
324 /// - Parameter size: size of the `VTable`
329 (_writerSize &- size) > 0, in pop()
331 memset(_storage.memory.advanced(by: writerIndex), 0, _writerSize &- size) in pop()
335 /// Clears the current size of the buffer
341 /// Clears the current instance of the buffer, replacing it with new memory
349 /// Reads an object from the buffer
350 /// - Parameters:
351 /// - def: Type of the object
352 /// - position: the index of the object in the buffer
354 public func read<T>(def: T.Type, position: Int) -> T { in read<T>()
358 /// Reads a slice from the memory assuming a type of T
359 /// - Parameters:
360 /// - index: index of the object to be read from the buffer
361 /// - count: count of bytes in memory
365 count: Int) -> [T]
377 /// Reads a string from the buffer and encodes it to a swift string
378 /// - Parameters:
379 /// - index: index of the string in the buffer
380 /// - count: length of the string
381 /// - type: Encoding of the string
386 type: String.Encoding = .utf8) -> String?
397 /// Reads a string from the buffer and encodes it to a swift string
398 /// - Parameters:
399 /// - index: index of the string in the buffer
400 /// - count: length of the string
401 /// - type: Encoding of the string
405 count: Int) -> String?
417 /// Creates a new Flatbuffer object that's duplicated from the current one
418 /// - Parameter removeBytes: the amount of bytes to remove from the current Size
420 public func duplicate(removing removeBytes: Int = 0) -> ByteBuffer { in duplicate()
428 removing: _writerSize &- removeBytes) in duplicate()
433 let cp = capacity &- writerIndex
443 /// which allows us to skip the first 4 bytes instead of recreating the buffer
447 mutating func skipPrefix() -> Int32 { in skipPrefix()
448 _writerSize = _writerSize &- MemoryLayout<Int32>.size in skipPrefix()
458 buffer located at: \(_storage.memory), with capacity of \(_storage.capacity)