(nopts int, nones []int)
| 64 | } |
| 65 | |
| 66 | func (b *Builder) EndContainerWithNones(nopts int, nones []int) { |
| 67 | if nopts == 0 { |
| 68 | b.EndContainer() |
| 69 | return |
| 70 | } |
| 71 | // Pop the container body offset off the stack. |
| 72 | bodyOff := b.containers[len(b.containers)-1] |
| 73 | b.containers = b.containers[:len(b.containers)-1] |
| 74 | bitLen := (nopts + 7) >> 3 |
| 75 | bitSize := SizeOfUvarint(uint64(bitLen)) |
| 76 | bitTag := toTag(bitLen) |
| 77 | bodyLen := len(b.bytes) - bodyOff |
| 78 | tag := toTag(bodyLen + bitSize + bitLen) |
| 79 | tagSize := SizeOfUvarint(tag) |
| 80 | // BeginContainer allocated one byte for the container tag. |
| 81 | tagOff := bodyOff - 1 |
| 82 | if tagSize+bitSize+bitLen <= 1 { |
| 83 | panic("bad tag/bit") |
| 84 | } |
| 85 | for range bitSize + bitLen { |
| 86 | // Always add bytes at the end to pad for the none bits so when we |
| 87 | // do the overlapping copy it works if the container body is smaller |
| 88 | // than the nones elem. |
| 89 | b.bytes = append(b.bytes, 0) |
| 90 | } |
| 91 | // Always need additional space for the tag and bits, so move body over. |
| 92 | b.bytes = append(b.bytes[:tagOff+tagSize+bitSize+bitLen], b.bytes[bodyOff:len(b.bytes)-(bitSize+bitLen)]...) |
| 93 | if binary.PutUvarint(b.bytes[tagOff:], tag) != tagSize { |
| 94 | panic("bad container tag size") |
| 95 | } |
| 96 | if binary.PutUvarint(b.bytes[tagOff+tagSize:], bitTag) != bitSize { |
| 97 | panic("bad container bits tag size") |
| 98 | } |
| 99 | bitsOff := tagOff + tagSize + bitSize |
| 100 | bits := b.bytes[bitsOff : bitsOff+bitLen] |
| 101 | for k := range bits { |
| 102 | bits[k] = 0 |
| 103 | } |
| 104 | for _, k := range nones { |
| 105 | if k>>3 >= bitLen { |
| 106 | panic(k) |
| 107 | } |
| 108 | bits[k>>3] |= 1 << (k & 7) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // TransformContainer calls transform, passing it the body of the most recently |
| 113 | // opened container and replacing the original body with the return value. It |
no test coverage detected