()
| 1023 | } |
| 1024 | |
| 1025 | private byte[] EncodeBody() |
| 1026 | { |
| 1027 | ByteWriter writer = new(128); |
| 1028 | if (!TypeId.HasValue) |
| 1029 | { |
| 1030 | throw new EncodingException("type id is required"); |
| 1031 | } |
| 1032 | |
| 1033 | bool isStruct = IsStructKind(TypeId.Value); |
| 1034 | if (!isStruct && Fields.Count != 0) |
| 1035 | { |
| 1036 | throw new EncodingException("non-struct TypeMeta cannot carry field metadata"); |
| 1037 | } |
| 1038 | |
| 1039 | byte metaHeader; |
| 1040 | if (isStruct) |
| 1041 | { |
| 1042 | metaHeader = (byte)(TypeMetaConstants.StructFlag | |
| 1043 | Math.Min(Fields.Count, TypeMetaConstants.SmallNumFieldsThreshold)); |
| 1044 | if (TypeId.Value is (uint)global::Apache.Fory.TypeId.CompatibleStruct or |
| 1045 | (uint)global::Apache.Fory.TypeId.NamedCompatibleStruct) |
| 1046 | { |
| 1047 | metaHeader |= TypeMetaConstants.CompatibleFlag; |
| 1048 | } |
| 1049 | |
| 1050 | if (RegisterByName) |
| 1051 | { |
| 1052 | metaHeader |= TypeMetaConstants.RegisterByNameFlag; |
| 1053 | } |
| 1054 | } |
| 1055 | else |
| 1056 | { |
| 1057 | metaHeader = (byte)NonStructKindCode(TypeId.Value); |
| 1058 | } |
| 1059 | |
| 1060 | writer.WriteUInt8(metaHeader); |
| 1061 | if (isStruct && Fields.Count >= TypeMetaConstants.SmallNumFieldsThreshold) |
| 1062 | { |
| 1063 | writer.WriteVarUInt32((uint)(Fields.Count - TypeMetaConstants.SmallNumFieldsThreshold)); |
| 1064 | } |
| 1065 | |
| 1066 | if (RegisterByName) |
| 1067 | { |
| 1068 | WriteName(writer, NamespaceName, TypeMetaEncodings.NamespaceMetaStringEncodings); |
| 1069 | WriteName(writer, TypeName, TypeMetaEncodings.TypeNameMetaStringEncodings); |
| 1070 | } |
| 1071 | else |
| 1072 | { |
| 1073 | if (!UserTypeId.HasValue || UserTypeId == TypeMetaConstants.NoUserTypeId) |
| 1074 | { |
| 1075 | throw new EncodingException("user type id is required in register-by-id mode"); |
| 1076 | } |
| 1077 | |
| 1078 | writer.WriteVarUInt32(UserTypeId.Value); |
| 1079 | } |
| 1080 | |
| 1081 | foreach (TypeMetaFieldInfo field in Fields) |
| 1082 | { |
nothing calls this directly
no test coverage detected