( ctx context.Context, messageRef buffetch.MessageRef, functionOptions *functionOptions, )
| 1111 | } |
| 1112 | |
| 1113 | func (c *controller) getImageForMessageRef( |
| 1114 | ctx context.Context, |
| 1115 | messageRef buffetch.MessageRef, |
| 1116 | functionOptions *functionOptions, |
| 1117 | ) (_ bufimage.Image, retErr error) { |
| 1118 | readCloser, err := c.buffetchReader.GetMessageFile(ctx, c.container, messageRef) |
| 1119 | if err != nil { |
| 1120 | return nil, err |
| 1121 | } |
| 1122 | defer func() { |
| 1123 | retErr = errors.Join(retErr, readCloser.Close()) |
| 1124 | }() |
| 1125 | data, err := io.ReadAll(readCloser) |
| 1126 | if err != nil { |
| 1127 | return nil, err |
| 1128 | } |
| 1129 | |
| 1130 | protoImage := &imagev1.Image{} |
| 1131 | var imageFromProtoOptions []bufimage.NewImageForProtoOption |
| 1132 | |
| 1133 | switch messageEncoding := messageRef.MessageEncoding(); messageEncoding { |
| 1134 | // we have to double parse due to custom options |
| 1135 | // See https://github.com/golang/protobuf/issues/1123 |
| 1136 | case buffetch.MessageEncodingBinpb: |
| 1137 | if err := protoencoding.NewWireUnmarshaler(nil).Unmarshal(data, protoImage); err != nil { |
| 1138 | return nil, err |
| 1139 | } |
| 1140 | case buffetch.MessageEncodingJSON: |
| 1141 | resolver, err := bootstrapResolver(protoencoding.NewJSONUnmarshaler(nil), data) |
| 1142 | if err != nil { |
| 1143 | return nil, err |
| 1144 | } |
| 1145 | if err := protoencoding.NewJSONUnmarshaler(resolver).Unmarshal(data, protoImage); err != nil { |
| 1146 | return nil, err |
| 1147 | } |
| 1148 | // we've already re-parsed, by unmarshalling 2x above |
| 1149 | imageFromProtoOptions = append(imageFromProtoOptions, bufimage.WithNoReparse()) |
| 1150 | case buffetch.MessageEncodingTxtpb: |
| 1151 | resolver, err := bootstrapResolver(protoencoding.NewTxtpbUnmarshaler(nil), data) |
| 1152 | if err != nil { |
| 1153 | return nil, err |
| 1154 | } |
| 1155 | if err := protoencoding.NewTxtpbUnmarshaler(resolver).Unmarshal(data, protoImage); err != nil { |
| 1156 | return nil, err |
| 1157 | } |
| 1158 | // we've already re-parsed, by unmarshalling 2x above |
| 1159 | imageFromProtoOptions = append(imageFromProtoOptions, bufimage.WithNoReparse()) |
| 1160 | case buffetch.MessageEncodingYAML: |
| 1161 | // No need to apply validation - Images do not use protovalidate. |
| 1162 | resolver, err := bootstrapResolver(protoencoding.NewYAMLUnmarshaler(nil), data) |
| 1163 | if err != nil { |
| 1164 | return nil, err |
| 1165 | } |
| 1166 | if err := protoencoding.NewYAMLUnmarshaler(resolver).Unmarshal(data, protoImage); err != nil { |
| 1167 | return nil, err |
| 1168 | } |
| 1169 | // we've already re-parsed, by unmarshalling 2x above |
| 1170 | imageFromProtoOptions = append(imageFromProtoOptions, bufimage.WithNoReparse()) |
no test coverage detected