MCPcopy Create free account
hub / github.com/brimdata/super / appendTypeValue

Function appendTypeValue

type.go:502–577  ·  view source on GitHub ↗
(b scode.Bytes, t Type, typedefs *map[string]Type)

Source from the content-addressed store, hash-verified

500}
501
502func appendTypeValue(b scode.Bytes, t Type, typedefs *map[string]Type) scode.Bytes {
503 switch t := t.(type) {
504 case *TypeNamed:
505 if *typedefs == nil {
506 *typedefs = make(map[string]Type)
507 }
508 id := byte(TypeValueNameDef)
509 if previous := (*typedefs)[t.Name]; previous == t.Type {
510 id = TypeValueNameRef
511 }
512 b = append(b, id)
513 b = binary.AppendUvarint(b, uint64(len(t.Name)))
514 b = append(b, scode.Bytes(t.Name)...)
515 if id == TypeValueNameRef {
516 return b
517 }
518 b = appendTypeValue(b, t.Type, typedefs)
519 // Set the typedef *after* the child has been recursively traversed
520 // in case the child sets the name to a different type. This insures
521 // that the DFS binding order is maintained.
522 (*typedefs)[t.Name] = t.Type
523 return b
524
525 case *TypeRecord:
526 b = append(b, TypeValueRecord)
527 n := len(t.Fields)
528 b = binary.AppendUvarint(b, uint64(n))
529 opts := make([]byte, (n+7)>>3)
530 for k := range n {
531 if t.Fields[k].Opt {
532 opts[k>>3] = opts[k>>3] | (1 << (k & 7))
533 }
534 }
535 b = append(b, opts...)
536 for _, f := range t.Fields {
537 b = binary.AppendUvarint(b, uint64(len(f.Name)))
538 b = append(b, f.Name...)
539 b = appendTypeValue(b, f.Type, typedefs)
540 }
541 return b
542 case *TypeUnion:
543 b = append(b, TypeValueUnion)
544 b = binary.AppendUvarint(b, uint64(len(t.Types)))
545 for _, t := range t.Types {
546 b = appendTypeValue(b, t, typedefs)
547 }
548 return b
549 case *TypeSet:
550 b = append(b, TypeValueSet)
551 return appendTypeValue(b, t.Type, typedefs)
552 case *TypeArray:
553 b = append(b, TypeValueArray)
554 return appendTypeValue(b, t.Type, typedefs)
555 case *TypeEnum:
556 b = append(b, TypeValueEnum)
557 b = binary.AppendUvarint(b, uint64(len(t.Symbols)))
558 for _, s := range t.Symbols {
559 b = binary.AppendUvarint(b, uint64(len(s)))

Callers 1

AppendTypeValueFunction · 0.85

Calls 2

BytesTypeAlias · 0.92
IDMethod · 0.65

Tested by

no test coverage detected