WriteAt() public méthode

Overwrites the byte at the specified index
public WriteAt ( int index, byte @byte ) : void
index int
@byte byte
Résultat void
Exemple #1
0
        /// <summary>
        /// Writes a binary object to the Mongo database
        /// </summary>
        public static byte[] AsBinary(byte[] value)
        {
            var stream = new DynamicStream(4);

            //write the kinds of stream this is
            //for now default to User-Defined
            stream.Append((byte)MongoBinaryTypes.UserDefined);

            //write the bytes and update the length
            stream.Append(value);
            stream.WriteAt(0, BitConverter.GetBytes(value.Length));

            //and return the final bytes to use
            return stream.ToArray();
        }
Exemple #2
0
        /// <summary>
        /// Renders the bytes required to create a document
        /// </summary>
        public override byte[] ToBsonByteArray()
        {
            //create the default size
            DynamicStream stream = new DynamicStream(5);

            //generate the bytes
            stream.InsertAt(4, base.ToBsonByteArray());

            //update the length
            stream.WriteAt(0, BsonTranslator.AsInt32(stream.Length));

            //and return the bytes to use
            return stream.ToArray();
        }
Exemple #3
0
        //generates the entire request
        private void GenerateStream()
        {
            //if the stream has already been created then don't bother
            if (_output != null) { return; }

            //called just before the generation starts
            OnBeforeGenerateStream();

            //start building the header
            var stream = new DynamicStream(DefaultHeaderLength);
            stream.WriteAt(PositionOpCode, BitConverter.GetBytes((int)OpCode));

            //generate the bytes to use for the body
            GenerateBody(stream);

            //update the request/response IDs incase they change when building
            stream.WriteAt(PositionRequestId, BitConverter.GetBytes(RequestId));
            stream.WriteAt(PositionResponseId, BitConverter.GetBytes(ResponseId));

            //finally, remember to update the length
            stream.WriteAt(PositionRequestLength, BitConverter.GetBytes(stream.Length));

            //cache this value to use it later
            _output = stream;
        }
Exemple #4
0
        //generates the entire request
        private void _GenerateStream()
        {
            //if the stream has already been created then don't bother
            if (this._Output is DynamicStream) { return; }

            //called just before the generation starts
            this.OnBeforeGenerateStream();

            //start building the header
            DynamicStream stream = new DynamicStream(DEFAULT_HEADER_LENGTH);
            stream.WriteAt(POSITION_OP_CODE, BitConverter.GetBytes((int)this.OpCode));

            //generate the bytes to use for the body
            this.GenerateBody(stream);

            //update the request/response IDs incase they change when building
            stream.WriteAt(POSITION_REQUEST_ID, BitConverter.GetBytes(this.RequestId));
            stream.WriteAt(POSITION_RESPONSE_ID, BitConverter.GetBytes(this.ResponseId));

            //finally, remember to update the length
            stream.WriteAt(POSITION_REQUEST_LENGTH, BitConverter.GetBytes(stream.Length));

            //cache this value to use it later
            this._Output = stream;
        }