(ByteWriter writer)
| 271 | internal CompatibleScalarRead? CompatibleScalarRead { get; set; } |
| 272 | |
| 273 | internal void Write(ByteWriter writer) |
| 274 | { |
| 275 | byte header = 0; |
| 276 | if (FieldType.TrackRef) |
| 277 | { |
| 278 | header |= 0b1; |
| 279 | } |
| 280 | |
| 281 | if (FieldType.Nullable) |
| 282 | { |
| 283 | header |= 0b10; |
| 284 | } |
| 285 | |
| 286 | if (FieldId.HasValue) |
| 287 | { |
| 288 | short fieldId = FieldId.Value; |
| 289 | if (fieldId < 0) |
| 290 | { |
| 291 | throw new EncodingException("negative field id is invalid"); |
| 292 | } |
| 293 | |
| 294 | int size = fieldId; |
| 295 | header |= 0b11 << 6; |
| 296 | if (size >= TypeMetaConstants.FieldNameSizeThreshold) |
| 297 | { |
| 298 | header |= 0b0011_1100; |
| 299 | writer.WriteUInt8(header); |
| 300 | writer.WriteVarUInt32((uint)(size - TypeMetaConstants.FieldNameSizeThreshold)); |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | header |= (byte)(size << 2); |
| 305 | writer.WriteUInt8(header); |
| 306 | } |
| 307 | |
| 308 | FieldType.Write(writer, false); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | string snakeName = TypeMetaUtils.LowerCamelToLowerUnderscore(FieldName); |
| 313 | MetaString encoded = MetaStringEncoder.FieldName.Encode(snakeName, TypeMetaEncodings.FieldNameMetaStringEncodings); |
| 314 | int encodingIndex = Array.IndexOf(TypeMetaEncodings.FieldNameMetaStringEncodings, encoded.Encoding); |
| 315 | if (encodingIndex < 0) |
| 316 | { |
| 317 | throw new EncodingException("unsupported field name encoding"); |
| 318 | } |
| 319 | |
| 320 | int encodedSize = encoded.Bytes.Length - 1; |
| 321 | header |= (byte)(encodingIndex << 6); |
| 322 | if (encodedSize >= TypeMetaConstants.FieldNameSizeThreshold) |
| 323 | { |
| 324 | header |= 0b0011_1100; |
| 325 | writer.WriteUInt8(header); |
| 326 | writer.WriteVarUInt32((uint)(encodedSize - TypeMetaConstants.FieldNameSizeThreshold)); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | header |= (byte)(encodedSize << 2); |
nothing calls this directly
no test coverage detected