// Map容器中,每一个元素的编/解码 private static ulong EntryByteSizeWithoutLength <K, V, KP, VP>(K key, V value, KP keyType, VP valueType) where KP : ProtoType where VP : ProtoType { if (Cache <K, KP> .ByteSize == null) { throw new NotImplementedException(); } if (Cache <V, VP> .ByteSize == null) { if (value is Enum && valueType is ProtoEnum) { Cache <V, VP> .ByteSize = (V parm) => ProtoTool.EnumByteSize(parm); } else { throw new NotImplementedException(); } } ulong bytes = 0; bytes += KeyByteSize(1, (uint)keyType.GetWireType()); bytes += Cache <K, KP> .ByteSize(key); bytes += KeyByteSize(2, (uint)valueType.GetWireType()); bytes += Cache <V, VP> .ByteSize(value); return(bytes); }
// Array,Set容器中,每一个元素的编/解码 private static ulong EntryByteSize <T, P>(T value, P type) { if (Cache <T, P> .ByteSize == null) { if (value is Enum && type is ProtoEnum) { Cache <T, P> .ByteSize = (T parm) => ProtoTool.EnumByteSize(parm); } else { throw new NotImplementedException(); } } return(Cache <T, P> .ByteSize(value)); }