@@ -141,7 +141,7 @@ func (w *writer) decodeVarint(src []byte, fd protoreflect.FieldDescriptor) ([]by
141141 src = rest
142142
143143 if extra > 0 {
144- w .Writef ("long-form:%d" , extra )
144+ w .Writef ("long-form:%d " , extra )
145145 }
146146
147147 ftype := protoreflect .Int64Kind
@@ -153,9 +153,19 @@ func (w *writer) decodeVarint(src []byte, fd protoreflect.FieldDescriptor) ([]by
153153 // make sense (like a double), we fall back on int64. We ignore 32-bit-ness:
154154 // everything is 64 bit here.
155155 switch ftype {
156+ case protoreflect .BoolKind :
157+ switch value {
158+ case 0 :
159+ w .Write ("false" )
160+ return src , true
161+ case 1 :
162+ w .Write ("true" )
163+ return src , true
164+ }
165+ fallthrough
156166 case protoreflect .Uint32Kind , protoreflect .Uint64Kind ,
157167 protoreflect .Fixed32Kind , protoreflect .Fixed64Kind :
158- w .Writef ( "%d" , value )
168+ w .Write ( value )
159169 case protoreflect .Sint32Kind , protoreflect .Sint64Kind :
160170 // Undo ZigZag encoding, then print as signed.
161171 value = (value >> 1 ) ^ - (value & 1 )
@@ -170,7 +180,7 @@ func (w *writer) decodeVarint(src []byte, fd protoreflect.FieldDescriptor) ([]by
170180 }
171181 fallthrough
172182 default :
173- w .Writef ( "%d" , int64 (value ))
183+ w .Write ( int64 (value ))
174184 }
175185
176186 return src , true
@@ -405,46 +415,92 @@ func (w *writer) decodeField(src []byte) ([]byte, bool) {
405415 })
406416 }
407417
408- // First, assume this is a message.
409- startLine := w .Mark ()
410- src2 := delimited
411- outerGroups := w .groups
412- w .groups = nil
418+ ftype := protoreflect .MessageKind
413419 if fd != nil {
414- w . descs . Push ( fd .Message () )
420+ ftype = fd .Kind ( )
415421 }
416- for len (src2 ) > 0 {
417- w .NewLine ()
418- s , ok := w .decodeField (src2 )
419- if ! ok {
420- // Clip off an incompletely printed line.
421- w .DiscardLine ()
422- break
422+
423+ decodePacked := func (decode func ([]byte , protoreflect.FieldDescriptor ) ([]byte , bool )) {
424+ count := 0
425+ for ; ; count ++ {
426+ w .NewLine ()
427+ s , ok := decode (delimited , fd )
428+ if ! ok {
429+ w .DiscardLine ()
430+ break
431+ }
432+ delimited = s
423433 }
424- src2 = s
425- }
426- if fd != nil {
427- w .descs .Pop ()
434+
435+ w .FoldIntoColumns (8 , count )
428436 }
429437
430- // Order does not matter for fixing up unclosed groups
431- for _ = range w .groups {
432- w .resetGroup ()
438+ switch ftype {
439+ case protoreflect .BoolKind , protoreflect .EnumKind ,
440+ protoreflect .Int32Kind , protoreflect .Int64Kind ,
441+ protoreflect .Uint32Kind , protoreflect .Uint64Kind ,
442+ protoreflect .Sint32Kind , protoreflect .Sint64Kind :
443+ decodePacked (w .decodeVarint )
444+ goto decodeBytes
445+
446+ case protoreflect .Fixed32Kind , protoreflect .Sfixed32Kind ,
447+ protoreflect .FloatKind :
448+ decodePacked (w .decodeI32 )
449+ goto decodeBytes
450+
451+ case protoreflect .Fixed64Kind , protoreflect .Sfixed64Kind ,
452+ protoreflect .DoubleKind :
453+ decodePacked (w .decodeI64 )
454+ goto decodeBytes
455+
456+ case protoreflect .StringKind , protoreflect .BytesKind :
457+ goto decodeUtf8
433458 }
434- w .groups = outerGroups
435-
436- // If we consumed all the bytes, we're done and can wrap up. However, if we
437- // consumed *some* bytes, and the user requested unconditional message
438- // parsing, we'll continue regardless. We don't bother in the case where we
439- // failed at the start because the `...` case below will do a cleaner job.
440- if len (src2 ) == 0 || (w .AllFieldsAreMessages && len (src2 ) < len (delimited )) {
441- delimited = src2
442- goto justBytes
443- } else {
444- w .Reset (startLine )
459+
460+ // This is in a block so that the gotos can jump over the declarations
461+ // safely.
462+ {
463+ startLine := w .Mark ()
464+ src2 := delimited
465+ outerGroups := w .groups
466+ w .groups = nil
467+ if fd != nil {
468+ w .descs .Push (fd .Message ())
469+ }
470+ for len (src2 ) > 0 {
471+ w .NewLine ()
472+ s , ok := w .decodeField (src2 )
473+ if ! ok {
474+ // Clip off an incompletely printed line.
475+ w .DiscardLine ()
476+ break
477+ }
478+ src2 = s
479+ }
480+ if fd != nil {
481+ w .descs .Pop ()
482+ }
483+
484+ // Order does not matter for fixing up unclosed groups
485+ for range w .groups {
486+ w .resetGroup ()
487+ }
488+ w .groups = outerGroups
489+
490+ // If we consumed all the bytes, we're done and can wrap up. However, if we
491+ // consumed *some* bytes, and the user requested unconditional message
492+ // parsing, we'll continue regardless. We don't bother in the case where we
493+ // failed at the start because the `...` case below will do a cleaner job.
494+ if len (src2 ) == 0 || (w .AllFieldsAreMessages && len (src2 ) < len (delimited )) {
495+ delimited = src2
496+ goto decodeBytes
497+ } else {
498+ w .Reset (startLine )
499+ }
445500 }
446501
447502 // Otherwise, maybe it's a UTF-8 string.
503+ decodeUtf8:
448504 if ! w .NoQuotedStrings && utf8 .Valid (delimited ) {
449505 runes := utf8 .RuneCount (delimited )
450506
@@ -456,7 +512,7 @@ func (w *writer) decodeField(src []byte) ([]byte, bool) {
456512 }
457513 }
458514 if float64 (unprintable )/ float64 (runes ) > 0.3 {
459- goto justBytes
515+ goto decodeBytes
460516 }
461517
462518 w .NewLine ()
@@ -489,11 +545,11 @@ func (w *writer) decodeField(src []byte) ([]byte, bool) {
489545 }
490546 w .Write ("\" " )
491547 delimited = nil
492- goto justBytes
548+ goto decodeBytes
493549 }
494550
495551 // Who knows what it is? Bytes or something.
496- justBytes :
552+ decodeBytes :
497553 w .dumpHexString (delimited )
498554 if ! w .ExplicitLengthPrefixes {
499555 w .NewLine ()
0 commit comments