EndContainer closes the most recently opened container. It panics if the receiver has no open container.
()
| 47 | // EndContainer closes the most recently opened container. It panics if the |
| 48 | // receiver has no open container. |
| 49 | func (b *Builder) EndContainer() { |
| 50 | // Pop the container body offset off the stack. |
| 51 | bodyOff := b.containers[len(b.containers)-1] |
| 52 | b.containers = b.containers[:len(b.containers)-1] |
| 53 | tag := toTag(len(b.bytes) - bodyOff) |
| 54 | tagSize := SizeOfUvarint(tag) |
| 55 | // BeginContainer allocated one byte for the container tag. |
| 56 | tagOff := bodyOff - 1 |
| 57 | if tagSize > 1 { |
| 58 | // Need additional space for the tag, so move body over. |
| 59 | b.bytes = append(b.bytes[:tagOff+tagSize], b.bytes[bodyOff:]...) |
| 60 | } |
| 61 | if binary.PutUvarint(b.bytes[tagOff:], tag) != tagSize { |
| 62 | panic("bad container tag size") |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func (b *Builder) EndContainerWithNones(nopts int, nones []int) { |
| 67 | if nopts == 0 { |