PrepareSize() 공개 메소드

public PrepareSize ( int aValueSize ) : int
aValueSize int
리턴 int
예제 #1
0
 // read size and data and store WITH size and data
 public bool Read(TByteBuffer aValue)
 {
     Int32 Len;
     if (Read(out Len))
     {
         if (Len <= ReadAvailable)
         {
             aValue.PrepareSize(Len + sizeof(Int32));
             aValue.PrepareApply();
             aValue.QWrite(Len);
             Array.Copy(FBuffer, FReadCursor, aValue.FBuffer, aValue.FWriteCursor, Len);
             FReadCursor += Len;
             return true;
         }
         else
             return false;
     }
     else
         return false;
 }
예제 #2
0
파일: IMBclients.cs 프로젝트: TNOCS/csTouch
 public int SignalStream(string aStreamName, Stream aStream) {
     var payload = new TByteBuffer();
     if (!IsPublished && connection.AutoPublish)
         Publish();
     if (IsPublished) {
         // ekStreamHeader, includes stream name, no stream data
         var streamNameUtf8 = Encoding.UTF8.GetBytes(aStreamName);
         var streamID = connection.getConnectionHashCode(streamNameUtf8);
         payload.Prepare(ID);
         payload.Prepare((Int32) 0); // tick
         payload.Prepare((Int32) TEventKind.ekStreamHeader); // event kind
         payload.Prepare(streamID);
         payload.Prepare(aStreamName);
         payload.PrepareApply();
         payload.QWrite(ID);
         payload.QWrite((Int32) 0); // tick
         var eventKindIndex = payload.WriteCursor;
         payload.QWrite((Int32) TEventKind.ekStreamHeader); // event kind
         payload.QWrite(streamID);
         var bodyIndex = payload.WriteCursor;
         payload.QWrite(aStreamName);
         var res = connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer);
         if (res > 0) {
             // ekStreamBody, only buffer size chunks of data
             // prepare Payload to same value but aStreamName stripped
             // fixup event kind
             payload.WriteStart(eventKindIndex);
             payload.QWrite((Int32) TEventKind.ekStreamBody);
             payload.WriteStart(bodyIndex);
             // prepare room for body data
             payload.PrepareStart();
             payload.PrepareSize(TConnection.MaxStreamBodyBuffer);
             payload.PrepareApply();
             // write pointer in ByteBuffer is still at beginning of stream read buffer!
             // but buffer is already created on correct length
             Int32 readSize;
             do {
                 readSize = ReadBytesFromStream(payload, aStream);
                 //ReadSize = aStream.Read(Payload.Buffer, BodyIndex, Connection.MaxStreamBodyBuffer);
                 if (readSize == TConnection.MaxStreamBodyBuffer)
                     res = connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer);
                 // reset write position
                 payload.WriteStart(bodyIndex);
             } while ((readSize == TConnection.MaxStreamBodyBuffer) && (res > 0));
             if (res > 0) {
                 // clip ByteBuffer to bytes read from stream
                 // write pointer in ByteBuffer is still at beginning of stream read buffer!
                 payload.PrepareStart();
                 payload.PrepareSize(readSize);
                 payload.PrepareApplyAndTrim();
                 // fixup event kind
                 payload.WriteStart(eventKindIndex);
                 payload.QWrite((Int32) TEventKind.ekStreamTail);
                 res = connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer);
             }
         }
         return res;
     }
     else
         return TConnection.iceNotEventPublished;
 }