]> git.mxchange.org Git - hub.git/commitdiff
Added start ([[S]]) and end ([[E]]) marker for BASE64 stream
authorRoland Häder <roland@mxchange.org>
Sat, 4 Aug 2012 23:08:16 +0000 (23:08 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 4 Aug 2012 23:08:16 +0000 (23:08 +0000)
application/hub/main/helper/connection/class_BaseConnectionHelper.php
application/hub/main/streams/raw_data/input/class_RawDataInputStream.php
application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php

index c9f1596ae9c56e1ccf6b80da805731054026aeb5..d2573681cabbc69fa7b590c2cc4286cd772ec9f8 100644 (file)
@@ -423,12 +423,15 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
                // Deliver all data
                while ($sentBytes !== false) {
                        // And deliver it
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,MD5=' . md5($encodedData) . ',bufferSize=' . $bufferSize . ',diff=' . $this->diff);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
+
                        if ($this->diff >= 0) {
                                // Send all out (encodedData is smaller than or equal buffer size)
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: MD5=' . md5(substr($encodedData, 0, ($bufferSize - $this->diff))));
                                $sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
                        } else {
                                // Send buffer size out
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: MD5=' . md5(substr($encodedData, 0, $bufferSize)));
                                $sentBytes = socket_write($socketResource, $encodedData, $bufferSize);
                        }
 
index 17fd7541028210f9a814460b7ce29aea596ba3ab..6fc9e077cd0a9d9a1910298f96207da688fc2090 100644 (file)
@@ -57,6 +57,9 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
         * @todo        Do we need to do something more here?
         */
        public function streamData ($data) {
+               // Do we have start and end marker again?
+               assert((substr($data, 0, 5) == '[[S]]') && (substr($data, -5, 5) == '[[E]]'));
+
                // Can it be validated?
                if ((strlen($data) % 4) != 0) {
                        // Length modulo 4 must be zero, else it is an invalid Base64 message
index f9c61f455d84f4919467202b90dbe097695197b5..32fb286ba3a39a8c47ad095742015983a9981700 100644 (file)
@@ -53,8 +53,13 @@ class RawDataOutputStream extends BaseStream implements OutputStreamable {
         * @todo        Do we need to do something more here?
         */
        public function streamData ($data) {
-               // Encode the data with BASE64 encoding
-               $data = base64_encode($data);
+               /*
+                * Encode the data with BASE64 encoding and put it in a "frame":
+                *
+                * [[S]] - Start marker
+                * [[E]] - End marker
+                */
+               $data = '[[S]]' . base64_encode($data) . '[[E]]';
 
                // Return it
                return $data;