MCPcopy Create free account
hub / github.com/apache/fory / Write

Method Write

csharp/src/Fory/TypeMeta.cs:273–336  ·  view source on GitHub ↗
(ByteWriter writer)

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 6

WriteUInt8Method · 0.80
WriteVarUInt32Method · 0.80
WriteMethod · 0.65
EncodeMethod · 0.45
WriteBytesMethod · 0.45

Tested by

no test coverage detected