ServerJS/Binary/C: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 22: Line 22:
:A type of list which manages a list of items. These items are not related to one another in any way other than their inclusion in the list and do not need to be of the same type.
:A type of list which manages a list of items. These items are not related to one another in any way other than their inclusion in the list and do not need to be of the same type.
:A key importance is an Array is a loose collection of items, these items do not have any sort of fixed unit to them.
:A key importance is an Array is a loose collection of items, these items do not have any sort of fixed unit to them.
;memcopy
:Where used memcopy is used it refers to the technique of copying memory as directly as possible from one source to another. At the very least this refers to copying from A to B without creating an intermediate Blob.


Where "as if by" is used in the spec the result is meant, the algorithm should not be affected by changes to the class' prototype.
Where "as if by" is used in the spec the result is meant, the algorithm should not be affected by changes to the class' prototype.
Line 59: Line 61:
Java's [http://java.sun.com/javase/6/docs/api/java/lang/StringBuffer.html java.lang.StringBuffer] is a very good reference for prior art. It is made for Strings rather than bytes, but nonetheless it's a api designed solely for the purpose of mutation of a string, not one designed for one purpose and hacked to suit another.
Java's [http://java.sun.com/javase/6/docs/api/java/lang/StringBuffer.html java.lang.StringBuffer] is a very good reference for prior art. It is made for Strings rather than bytes, but nonetheless it's a api designed solely for the purpose of mutation of a string, not one designed for one purpose and hacked to suit another.


The StringBuffer works using by append[ing](), insert[ing](), strings to grow the buffer. .delete() removes portions of the buffer, .indexOf() and .lastIndexOf() can search, .replace() and .reverse() are available, .length() shows the length of the data itself, .capacity() shows the current amount of memory allocated, and .substring can grab a substring from the StringBuffer.
Java's StringBuffer works using by append[ing](), insert[ing](), strings to grow the buffer. .delete() removes portions of the buffer, .indexOf() and .lastIndexOf() can search, .replace() and .reverse() are available, .length() shows the length of the data itself, .capacity() shows the current amount of memory allocated, and .substring can grab a substring from the StringBuffer.


== The API ==
== The API ==
Line 70: Line 72:


Most of the blob methods work on blobish data, rather than flat blobs. This means that the argument is treated as if it were passed through Blob(), thus .indexOf(255); is the same as if you had done .indexOf(Blob(255)), so you do not need to explicitly convert everything into a blob.
Most of the blob methods work on blobish data, rather than flat blobs. This means that the argument is treated as if it were passed through Blob(), thus .indexOf(255); is the same as if you had done .indexOf(Blob(255)), so you do not need to explicitly convert everything into a blob.
Note that unlike String, Blob is not defined as a primitive datatype by ECMA, this means that typeof will never return 'blob' and all blobs will be objects unlike strings which are normally primitives. Blob works with and without the new constructor and acts the same. It is recommended to use the `Blob()` form


;[new] Blob();
;[new] Blob();
Line 180: Line 184:
:When length is set the buffer is dynamically resized. If shrunk it is truncated to size discarding items from the end. If grown the buffer is padded with 0 bytes for binary, and '\0' (null characters) for text.
:When length is set the buffer is dynamically resized. If shrunk it is truncated to size discarding items from the end. If grown the buffer is padded with 0 bytes for binary, and '\0' (null characters) for text.


;buf.text;
;buf.contentConstructor;
:(May be removed in favor of a better idiom)
:Returns Blob from a BlobBuffer to indicate it has binary content, and String from StringBuffer to indicate it has text content. Implementations should make an effort to make this readonly.
:Get the type of the buffer. Binary buffers return false, text buffers return true.


;buf[index];
;buf[index];
Line 189: Line 192:


;buf.append(data);
;buf.append(data);
:Append a chunk of data to the end of the buffer growing it by <code>data.length</code>.
:Append a chunk of data to the end of the buffer growing it by <code>data.length</code>. If data is another Buffer memcopy should be used.


;buf.insert(data, index);
;buf.insert(data, index);
:Insert a chunk of data into a buffer growing it by <code>data.length</code> and shifting the data to the right of the specified index towards the end of the buffer.
:Insert a chunk of data into a buffer growing it by <code>data.length</code> and shifting the data to the right of the specified index towards the end of the buffer. If data is another Buffer memcopy should be used.


;buf.clear(start, length);
;buf.clear(start, length);
Line 204: Line 207:


;buf.splice(offset, length, data, ...);
;buf.splice(offset, length, data, ...);
:Remove a section of the buffer and insert chunks of data starting from the place it was removed from.
:Remove a section of the buffer and insert chunks of data starting from the place it was removed from. If data is another Buffer memcopy should be used.


;buf.slice();
;buf.slice();
Line 210: Line 213:
;buf.slice(start, end);
;buf.slice(start, end);
:Extract a subsection of the buffer and return it as a new sequence. (Behaves the same as the string and blob counterparts)
:Extract a subsection of the buffer and return it as a new sequence. (Behaves the same as the string and blob counterparts)
;buf.copy(data, offset, length, [dataOffset]);
:Uses memcopy to copy a section of data directly into buf. data may either be another buffer of the same type, or a sequence (String/Blob) of same type as indicated by contentConstructor.


;buf.split();
;buf.split();
Line 220: Line 226:
:Returns the index within the calling buffer object of the first or last (depending on which method is used) occurrence of the specified value, or -1 if not found.
:Returns the index within the calling buffer object of the first or last (depending on which method is used) occurrence of the specified value, or -1 if not found.


;buf.reverse();
;<s>buf.reverse();</s>
:Causes the sequence to be replaced by the reverse of the sequence.
:<s>Causes the sequence to be replaced by the reverse of the sequence.</s>


;buf.valueOf();
;buf.valueOf();
40

edits

Navigation menu