当前位置: 首页>>代码示例>>C#>>正文


C# ByteBuffer.PackString方法代码示例

本文整理汇总了C#中System.ByteBuffer.PackString方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.PackString方法的具体用法?C# ByteBuffer.PackString怎么用?C# ByteBuffer.PackString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.PackString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCompoundKey

        internal Key CreateCompoundKey(int[] types, string[] values)
        {
            ByteBuffer buf = new ByteBuffer();
            int dst = 0;

            try
            {
                for (int i = 0; i < types.Length; i++)
                {
                    string val = values[i];
                    switch (types[i])
                    {
                        case ClassDescriptor.tpBoolean:
                            buf.Extend(dst + 1);
                            buf.arr[dst++] = (byte) (Int32.Parse(val) != 0 ? 1 : 0);
                            break;

                        case ClassDescriptor.tpByte:
                            buf.Extend(dst + 1);
                            buf.arr[dst++] = (byte) System.SByte.Parse(val);
                            break;

                        case ClassDescriptor.tpChar:
                            buf.Extend(dst + 2);
                            Bytes.Pack2(buf.arr, dst, (short) Int32.Parse(val));
                            dst += 2;
                            break;

                        case ClassDescriptor.tpShort:
                            buf.Extend(dst + 2);
                            Bytes.Pack2(buf.arr, dst, System.Int16.Parse(val));
                            dst += 2;
                            break;

                        case ClassDescriptor.tpInt:
                            buf.Extend(dst + 4);
                            Bytes.Pack4(buf.arr, dst, Int32.Parse(val));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpObject:
                            buf.Extend(dst + 4);
                            Bytes.Pack4(buf.arr, dst, MapId(Int32.Parse(val)));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpLong:
                        case ClassDescriptor.tpDate:
                            buf.Extend(dst + 8);
                            Bytes.Pack8(buf.arr, dst, Int64.Parse(val));
                            dst += 8;
                            break;

                        case ClassDescriptor.tpFloat:
                            buf.Extend(dst + 4);
                            Bytes.PackF4(buf.arr, dst, Single.Parse(val));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpDouble:
                            buf.Extend(dst + 8);
                            Bytes.PackF8(buf.arr, dst, Double.Parse(val));
                            dst += 8;
                            break;

                        case ClassDescriptor.tpString:
                            dst = buf.PackString(dst, val, storage.encoding);
                            break;

                        case ClassDescriptor.tpArrayOfByte:
                            buf.Extend(dst + 4 + (SupportClass.URShift(val.Length, 1)));
                            Bytes.Pack4(buf.arr, dst, SupportClass.URShift(val.Length, 1));
                            dst += 4;
                            for (int j = 0, n = val.Length; j < n; j += 2)
                            {
                                buf.arr[dst++] = (byte) ((GetHexValue(val[j]) << 4) | GetHexValue(val[j + 1]));
                            }
                            break;

                        default:
                            ThrowException("Bad key type");
                            break;
                    }
                }
            }
            catch (FormatException)
            {
                ThrowException("Failed to convert key value");
            }
            return new Key(buf.ToArray());
        }
开发者ID:kjk,项目名称:tenderbase,代码行数:91,代码来源:XMLImporter.cs

示例2: PackObject

        internal int PackObject(object obj, ClassDescriptor desc, int offs, ByteBuffer buf, IPersistent po)
        {
            ClassDescriptor.FieldDescriptor[] flds = desc.allFields;
            for (int i = 0, n = flds.Length; i < n; i++)
            {
                ClassDescriptor.FieldDescriptor fd = flds[i];
                FieldInfo f = fd.field;
                switch (fd.type)
                {
                    case ClassDescriptor.tpByte:
                        buf.Extend(offs + 1);
                        buf.arr[offs++] = (byte) f.GetValue(obj);
                        continue;

                    case ClassDescriptor.tpBoolean:
                        buf.Extend(offs + 1);
                        buf.arr[offs++] = (byte) ((bool) f.GetValue(obj) ? 1 : 0);
                        continue;

                    case ClassDescriptor.tpShort:
                        buf.Extend(offs + 2);
                        Bytes.Pack2(buf.arr, offs, (short) f.GetValue(obj));
                        offs += 2;
                        continue;

                    case ClassDescriptor.tpChar:
                        buf.Extend(offs + 2);
                        Bytes.Pack2(buf.arr, offs, (short) f.GetValue(obj));
                        offs += 2;
                        continue;

                    case ClassDescriptor.tpInt:
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, (int) f.GetValue(obj));
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpLong:
                        buf.Extend(offs + 8);
                        Bytes.Pack8(buf.arr, offs, (long) f.GetValue(obj));
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpFloat:
                        buf.Extend(offs + 4);
                        Bytes.PackF4(buf.arr, offs, (float) f.GetValue(obj));
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpDouble:
                        buf.Extend(offs + 8);
                        Bytes.PackF8(buf.arr, offs, (double) f.GetValue(obj));
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpDate:
                    {
                        buf.Extend(offs + 8);
                        DateTime d = (DateTime) f.GetValue(obj);
                        //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                        //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                        long msec = (d == null) ? -1 : d.Ticks;
                        Bytes.Pack8(buf.arr, offs, msec);
                        offs += 8;
                        continue;
                    }

                    case ClassDescriptor.tpString:
                        offs = buf.PackString(offs, (string) f.GetValue(obj), encoding);
                        continue;

                    case ClassDescriptor.tpObject:
                    {
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, Swizzle((IPersistent) f.GetValue(obj)));
                        offs += 4;
                        continue;
                    }

                    case ClassDescriptor.tpValue:
                    {
                        object val = f.GetValue(obj);
                        if (val == null)
                        {
                            throw new StorageError(StorageError.NULL_VALUE, fd.fieldName);
                        }
                        else if (val is IPersistent)
                        {
                            throw new StorageError(StorageError.SERIALIZE_PERSISTENT);
                        }
                        offs = PackObject(val, fd.valueDesc, offs, buf, po);
                        continue;
                    }

                    case ClassDescriptor.tpRaw:
                        offs = PackValue(f.GetValue(obj), offs, buf);
                        continue;

                    case ClassDescriptor.tpArrayOfByte:
                    {
//.........这里部分代码省略.........
开发者ID:kjk,项目名称:tenderbase,代码行数:101,代码来源:StorageImpl.cs

示例3: PackObject


//.........这里部分代码省略.........
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpString:
                        if (elem != null)
                        {
                            string val = null;
                            if (elem.IsIntValue())
                            {
                                val = Convert.ToString(elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                val = elem.GetRealValue().ToString();
                            }
                            else if (elem.IsStringValue())
                            {
                                val = elem.GetStringValue();
                            }
                            else if (elem.IsNullValue())
                            {
                                val = null;
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                            offs = buf.PackString(offs, val, storage.encoding);
                            continue;
                        }

                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, -1);
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpObject:
                    {
                        int oid = 0;
                        if (elem != null)
                        {
                            XMLElement ref_Renamed = elem.GetSibling("ref");
                            if (ref_Renamed == null)
                            {
                                ThrowException("<ref> element expected");
                            }
                            oid = MapId(GetIntAttribute(ref_Renamed, "id"));
                        }
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, oid);
                        offs += 4;
                        continue;
                    }

                    case ClassDescriptor.tpValue:
                        offs = PackObject(elem, fd.valueDesc, offs, buf);
                        continue;

                    case ClassDescriptor.tpRaw:
                    case ClassDescriptor.tpArrayOfByte:
开发者ID:kjk,项目名称:tenderbase,代码行数:67,代码来源:XMLImporter.cs


注:本文中的System.ByteBuffer.PackString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。