示例#1
0
        public override void Write(IWriteContext context, object obj)
        {
            char charValue = ((char)obj);

            context.WriteBytes(new byte[] { (byte)(charValue & unchecked ((int)(0xff))), (byte
                                                                                          )(charValue >> 8) });
        }
示例#2
0
 protected virtual void WriteElements(IWriteContext context, object obj, ArrayInfo
                                      info)
 {
     if (HandleAsByteArray(obj))
     {
         context.WriteBytes((byte[])obj);
     }
     else
     {
         // byte[] performance optimisation
         if (HasNullBitmap(info))
         {
             BitMap4 nullItems = NullItemsMap(ArrayReflector(Container(context)), obj);
             WriteNullBitmap(context, nullItems);
             for (int i = 0; i < info.ElementCount(); i++)
             {
                 if (!nullItems.IsTrue(i))
                 {
                     context.WriteObject(_handler, ArrayReflector(Container(context)).Get(obj, i));
                 }
             }
         }
         else
         {
             for (int i = 0; i < info.ElementCount(); i++)
             {
                 context.WriteObject(_handler, ArrayReflector(Container(context)).Get(obj, i));
             }
         }
     }
 }
        // ITypeHandler4 override
        public override void Write(IWriteContext context, object obj)
        {
            // Write the data.
            var cfi = (CustomFieldInfo)obj;

            context.WriteInt(cfi.m_flid);
            context.WriteInt((int)cfi.m_fieldType);
            context.WriteInt(cfi.m_destinationClass);
            var cvtr  = new UnicodeEncoding();
            var bytes = cvtr.GetBytes(cfi.m_classname);

            context.WriteInt(bytes.Length);
            context.WriteBytes(bytes);
            bytes = cvtr.GetBytes(cfi.m_fieldname);
            context.WriteInt(bytes.Length);
            context.WriteBytes(bytes);
            if (cfi.m_fieldname != cfi.Label)
            {
                // marker to distinguish this from any other optional info we may one day write,
                // and from cases where no label is written.
                context.WriteByte(1);
                bytes = cvtr.GetBytes(cfi.Label);
                context.WriteInt(bytes.Length);
                context.WriteBytes(bytes);
            }
            if (!String.IsNullOrEmpty(cfi.m_fieldHelp))
            {
                context.WriteByte(2);
                bytes = cvtr.GetBytes(cfi.m_fieldHelp);
                context.WriteInt(bytes.Length);
                context.WriteBytes(bytes);
            }
            if (cfi.m_fieldListRoot != Guid.Empty)
            {
                context.WriteByte(3);
                bytes = cfi.m_fieldListRoot.ToByteArray();
                context.WriteInt(bytes.Length);
                context.WriteBytes(bytes);
            }
            if (cfi.m_fieldWs != 0)
            {
                context.WriteByte(4);
                context.WriteInt(cfi.m_fieldWs);
            }
            // End marker
            context.WriteByte(0);
        }
示例#4
0
        // #end example

        // #example: Write the StringBuilder
        public void Write(IWriteContext writeContext, object o)
        {
            StringBuilder builder = (StringBuilder) o;
            string str = builder.ToString();
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            writeContext.WriteInt(bytes.Length);
            writeContext.WriteBytes(bytes);
        }
示例#5
0
 public override void Write(IWriteContext context, object obj)
 {
     ushort us = (ushort)obj;
     context.WriteBytes(
         new byte[] { 
             (byte)(us>>8),
             (byte)us,
         });
 }
示例#6
0
 public override void Write(IWriteContext context, object obj)
 {
     var charValue = ((char) obj);
     context.WriteBytes(new[]
     {
         (byte) (charValue & unchecked(0xff)), (byte
             ) (charValue >> 8)
     });
 }
示例#7
0
        // #end example

        // #example: Write the StringBuilder
        public void Write(IWriteContext writeContext, object o)
        {
            StringBuilder builder = (StringBuilder)o;
            string        str     = builder.ToString();

            byte[] bytes = Encoding.UTF8.GetBytes(str);
            writeContext.WriteInt(bytes.Length);
            writeContext.WriteBytes(bytes);
        }
示例#8
0
        public override void Write(IWriteContext context, object obj)
        {
            ushort us = (ushort)obj;

            context.WriteBytes(
                new byte[] {
                (byte)(us >> 8),
                (byte)us,
            });
        }
示例#9
0
 public override void Write(IWriteContext context, object obj)
 {
     uint ui = (uint)obj;
     context.WriteBytes(
         new byte[] { 
             (byte)(ui>>24),
             (byte)(ui>>16),
             (byte)(ui>>8),
             (byte)ui,
         });
 }
示例#10
0
        public override void Write(IWriteContext context, object obj)
        {
            uint ui = (uint)obj;

            context.WriteBytes(
                new byte[] {
                (byte)(ui >> 24),
                (byte)(ui >> 16),
                (byte)(ui >> 8),
                (byte)ui,
            });
        }
        // ITypeHandler4 override
        public override void Write(IWriteContext context, object obj)
        {
            if (m_serverOnlyMode)
            {
                throw new ApplicationException("Programming error. Should not be writing db4o objects in server mode.");
            }

            var asSurrogate = (ICmObjectSurrogate)obj;

            // Write Guid.
            context.WriteBytes(asSurrogate.Guid.ToByteArray());
            // Write class name.
            var classBytes = m_unicodeEnc.GetBytes(asSurrogate.Classname);

            context.WriteInt(classBytes.Length);
            context.WriteBytes(classBytes);
            // Write the XML data.
            var dataBytes = asSurrogate.XMLBytes;

            context.WriteInt(dataBytes.Length);
            context.WriteBytes(dataBytes);
        }
示例#12
0
 public override void Write(IWriteContext context, object obj)
 {
     ulong ui = (ulong)obj;
     context.WriteBytes(
         new byte[] { 
             (byte)(ui>>56),
             (byte)(ui>>48),
             (byte)(ui>>40),
             (byte)(ui>>32),
             (byte)(ui>>24),
             (byte)(ui>>16),
             (byte)(ui>>8),
             (byte)ui,
         });
 }
示例#13
0
        public override void Write(IWriteContext context, object obj)
        {
            ulong ui = (ulong)obj;

            context.WriteBytes(
                new byte[] {
                (byte)(ui >> 56),
                (byte)(ui >> 48),
                (byte)(ui >> 40),
                (byte)(ui >> 32),
                (byte)(ui >> 24),
                (byte)(ui >> 16),
                (byte)(ui >> 8),
                (byte)ui,
            });
        }
示例#14
0
 public override void Write(IWriteContext context, object obj)
 {
     decimal dec = (decimal)obj;
     byte[] bytes = new byte[16];
     int offset = 4;
     int[] ints = Decimal.GetBits(dec);
     for (int i = 0; i < 4; i++)
     {
         bytes[--offset] = (byte)ints[i];
         bytes[--offset] = (byte)(ints[i] >>= 8);
         bytes[--offset] = (byte)(ints[i] >>= 8);
         bytes[--offset] = (byte)(ints[i] >>= 8);
         offset += 8;
     }
     context.WriteBytes(bytes);
 }
示例#15
0
        public override void Write(IWriteContext context, object obj)
        {
            var dec    = (decimal)obj;
            var bytes  = new byte[16];
            var offset = 4;
            var ints   = decimal.GetBits(dec);

            for (var i = 0; i < 4; i++)
            {
                bytes[--offset] = (byte)ints[i];
                bytes[--offset] = (byte)(ints[i] >>= 8);
                bytes[--offset] = (byte)(ints[i] >>= 8);
                bytes[--offset] = (byte)(ints[i] >>= 8);
                offset         += 8;
            }
            context.WriteBytes(bytes);
        }
示例#16
0
        public override void Write(IWriteContext context, object obj)
        {
            decimal dec = (decimal)obj;

            byte[] bytes  = new byte[16];
            int    offset = 4;

            int[] ints = Decimal.GetBits(dec);
            for (int i = 0; i < 4; i++)
            {
                bytes[--offset] = (byte)ints[i];
                bytes[--offset] = (byte)(ints[i] >>= 8);
                bytes[--offset] = (byte)(ints[i] >>= 8);
                bytes[--offset] = (byte)(ints[i] >>= 8);
                offset         += 8;
            }
            context.WriteBytes(bytes);
        }
示例#17
0
 public override void Write(IWriteContext context, object obj)
 {
     int shortValue = ((short) obj);
     context.WriteBytes(new[] {(byte) (shortValue >> 8), (byte) shortValue});
 }
		protected virtual void WriteElements(IWriteContext context, object obj, ArrayInfo
			 info)
		{
			if (HandleAsByteArray(obj))
			{
				context.WriteBytes((byte[])obj);
			}
			else
			{
				// byte[] performance optimisation
				if (HasNullBitmap(info))
				{
					BitMap4 nullItems = NullItemsMap(ArrayReflector(Container(context)), obj);
					WriteNullBitmap(context, nullItems);
					for (int i = 0; i < info.ElementCount(); i++)
					{
						if (!nullItems.IsTrue(i))
						{
							context.WriteObject(_handler, ArrayReflector(Container(context)).Get(obj, i));
						}
					}
				}
				else
				{
					for (int i = 0; i < info.ElementCount(); i++)
					{
						context.WriteObject(_handler, ArrayReflector(Container(context)).Get(obj, i));
					}
				}
			}
		}
示例#19
0
        public override void Write(IWriteContext context, object obj)
        {
            int shortValue = ((short)obj);

            context.WriteBytes(new[] { (byte)(shortValue >> 8), (byte)shortValue });
        }
示例#20
0
 public override void Write(IWriteContext context, object obj)
 {
     var dec = (decimal) obj;
     var bytes = new byte[16];
     var offset = 4;
     var ints = decimal.GetBits(dec);
     for (var i = 0; i < 4; i++)
     {
         bytes[--offset] = (byte) ints[i];
         bytes[--offset] = (byte) (ints[i] >>= 8);
         bytes[--offset] = (byte) (ints[i] >>= 8);
         bytes[--offset] = (byte) (ints[i] >>= 8);
         offset += 8;
     }
     context.WriteBytes(bytes);
 }