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

Method formatValue

sup/formatter.go:137–191  ·  view source on GitHub ↗
(indent int, typ super.Type, bytes scode.Bytes, parentKnown, decorate bool)

Source from the content-addressed store, hash-verified

135}
136
137func (f *Formatter) formatValue(indent int, typ super.Type, bytes scode.Bytes, parentKnown, decorate bool) {
138 known := parentKnown || f.hasName(typ)
139 var empty bool
140 switch t := typ.(type) {
141 default:
142 f.startColorPrimitive(typ)
143 formatPrimitive(&f.builder, typ, bytes)
144 f.endColor()
145 case *super.TypeNamed:
146 f.formatValue(indent, t.Type, bytes, known, false)
147 case *super.TypeRecord:
148 f.formatRecord(indent, t, bytes, known)
149 case *super.TypeArray:
150 empty = f.formatVector(indent, "[", "]", t.Type, super.NewValue(t, bytes), known)
151 case *super.TypeSet:
152 empty = f.formatVector(indent, "|[", "]|", t.Type, super.NewValue(t, bytes), known)
153 case *super.TypeUnion:
154 f.formatUnion(indent, t, bytes)
155 case *super.TypeMap:
156 empty = f.formatMap(indent, t, bytes, known)
157 case *super.TypeEnum:
158 f.build("\"")
159 f.build(t.Symbols[super.DecodeUint(bytes)])
160 f.build("\"")
161 case *super.TypeError:
162 f.startColor(color.Red)
163 f.build("error")
164 f.endColor()
165 f.build("(")
166 f.formatValue(indent, t.Type, bytes, known, true)
167 f.build(")")
168 case *super.TypeFusion:
169 f.startColor(color.Green)
170 f.build("fusion")
171 f.endColor()
172 f.build("(")
173 it := bytes.Iter()
174 f.formatValue(indent, t.Type, it.Next(), known, true)
175 f.build(",<")
176 f.formatTypeValue(indent, it.Next(), false)
177 f.build(">)")
178 // We don't need to decorate a fusion value because
179 // its type is always implied by its value.
180 return
181 case *super.TypeOfType:
182 f.startColor(color.Gray(200))
183 f.build("<")
184 f.formatTypeValue(indent, bytes, false)
185 f.build(">")
186 f.endColor()
187 }
188 if decorate && !parentKnown {
189 f.decorate(typ, empty)
190 }
191}
192
193func (f *Formatter) formatTypeValue(indent int, tv scode.Bytes, isComponentType bool) scode.Bytes {
194 n, tv := super.DecodeLength(tv)

Callers 5

formatRecordMethod · 0.95
formatVectorMethod · 0.95
formatUnionMethod · 0.95
formatMapMethod · 0.95

Calls 15

hasNameMethod · 0.95
startColorPrimitiveMethod · 0.95
endColorMethod · 0.95
formatRecordMethod · 0.95
formatVectorMethod · 0.95
formatUnionMethod · 0.95
formatMapMethod · 0.95
buildMethod · 0.95
startColorMethod · 0.95
formatTypeValueMethod · 0.95
decorateMethod · 0.95
NewValueFunction · 0.92

Tested by

no test coverage detected