コード例 #1
0
        private void buildFileDescriptor(FileDescriptorSet desc)
        {
            if (desc == null)
            {
                throw new ArgumentNullException("FileDescriptorSet can not be null");
            }

            foreach (var fd in desc.file)
            {
                if (descriptors.FileDescriptors.ContainsKey(fd.name))
                {
                    continue;
                }

                descriptors.FileDescriptors.Add(fd.name, fd);
                foreach (var enum_desc in fd.enum_type)
                {
                    string enum_key = string.Format("{0}.{1}", fd.package, enum_desc.name);
                    if (descriptors.EnumDescriptors.ContainsKey(enum_key))
                    {
                        lastError.AddLast(string.Format("enum discriptor {0} already existed"));
                    }
                    else
                    {
                        descriptors.EnumDescriptors.Add(enum_key, enum_desc);

                        foreach (var enum_val in enum_desc.value)
                        {
                            string enum_val_key = string.Format("{0}.{1}", enum_key, enum_val.name);
                            descriptors.EnumValueDescriptors[enum_val_key] = enum_val;
                        }
                    }
                }

                foreach (var msg_desc in fd.message_type)
                {
                    string key = string.Format("{0}.{1}", fd.package, msg_desc.name);
                    if (descriptors.MsgDescriptors.ContainsKey(key))
                    {
                        lastError.AddLast(string.Format("message discriptor {0} already existed"));
                    }
                    else
                    {
                        DynamicMessage.MsgDiscriptor res = new DynamicMessage.MsgDiscriptor();
                        res.Package        = fd.package;
                        res.Protocol       = msg_desc;
                        res.FieldIdIndex   = new Dictionary <int, FieldDescriptorProto>();
                        res.FieldNameIndex = new Dictionary <string, FieldDescriptorProto>();
                        descriptors.MsgDescriptors.Add(key, res);
                    }
                }
            }
        }
コード例 #2
0
        public DynamicMessage Create(string path)
        {
            lastError.Clear();

            DynamicMessage.MsgDiscriptor out_desc = GetMsgDiscriptor(path);
            if (null != out_desc)
            {
                return(Create(out_desc));
            }

            lastError.AddLast(string.Format("invalid protocol path {0}", path));
            return(null);
        }
コード例 #3
0
        public DynamicMessage Decode(DynamicMessage.MsgDiscriptor out_desc, Stream stream)
        {
            lastError.Clear();

            DynamicMessage ret = Create(out_desc);

            if (null == ret)
            {
                lastError.AddLast(string.Format("invalid protocol path {0}.{1}", out_desc.Package, out_desc.Protocol));
                return(null);
            }

            if (false == ret.Parse(stream))
            {
                lastError.AddLast(ret.LastError);
                return(null);
            }

            return(ret);
        }
コード例 #4
0
 public DynamicMessage Create(DynamicMessage.MsgDiscriptor out_desc)
 {
     return(new DynamicMessage(out_desc, descriptors));
 }