MCPcopy Create free account
hub / github.com/CrowdStrike/csproto / TestDecoderSkip

Function TestDecoderSkip

decoder_test.go:1153–1189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1151}
1152
1153func TestDecoderSkip(t *testing.T) {
1154 var (
1155 data = []byte{
1156 // 1 (varint) - true
1157 0x8, 0x1,
1158 // 2 (varint): 42
1159 0x10, 0x2A,
1160 // 3 (fixed64): 1138
1161 0x19, 0x72, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1162 // 4 (length-delimited): "this is a test"
1163 0x22, 0xE, 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74,
1164 // 5 (fixed32): 1138
1165 0x2d, 0x72, 0x04, 0x00, 0x00,
1166 // 6 (varint): false
1167 0x30, 0x0,
1168 }
1169 // byte offsets for the start of each encoded field
1170 fieldOffsets = []int{0, 2, 4, 13, 29, 34}
1171 )
1172
1173 dec := csproto.NewDecoder(data)
1174 for i := 0; i < 6; i++ {
1175 tag, wt, _ := dec.DecodeTag()
1176 switch tag {
1177 case 1:
1178 _, _ = dec.DecodeBool()
1179 case 2, 3, 4, 5:
1180 fs, fe := fieldOffsets[i], fieldOffsets[i+1]
1181 skipped, err := dec.Skip(tag, wt)
1182 assert.NoError(t, err, "Unexpected error skipping field (%d, %s): %v", tag, wt)
1183 assert.Len(t, skipped, (fe - fs), "Unexpected length of skipped data for field (%d, %s)", tag, wt)
1184 assert.Equal(t, data[fs:fe], skipped, "Unexpected skipped content for field (%d, %s)", tag, wt)
1185 case 6:
1186 _, _ = dec.DecodeBool()
1187 }
1188 }
1189}
1190
1191func TestDecoderInvalidSkip(t *testing.T) {
1192 var data = []byte{

Callers

nothing calls this directly

Calls 4

DecodeTagMethod · 0.95
DecodeBoolMethod · 0.95
SkipMethod · 0.95
NewDecoderFunction · 0.92

Tested by

no test coverage detected