1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Pass the original field number into the generate function

This commit is contained in:
joshvera 2018-06-11 18:30:13 -04:00
parent 1a49b3e197
commit 2063798b24

View File

@ -107,10 +107,10 @@ infixContext context left right operators = uncurry (&) <$> postContextualizeThr
instance (Apply Message1 fs, Generate Message1 fs fs, Generate Named1 fs fs) => Message1 (Sum fs) where instance (Apply Message1 fs, Generate Message1 fs fs, Generate Named1 fs fs) => Message1 (Sum fs) where
liftEncodeMessage encodeMessage num fs = Encode.embedded (FieldNumber . fromIntegral . succ $ elemIndex fs) message liftEncodeMessage encodeMessage num fs = Encode.embedded (FieldNumber . fromIntegral . succ $ elemIndex fs) message
where message = apply @Message1 (liftEncodeMessage encodeMessage num) fs where message = apply @Message1 (liftEncodeMessage encodeMessage num) fs
liftDecodeMessage decodeMessage _ = Decode.oneof undefined listOfParsers liftDecodeMessage decodeMessage num' = Decode.oneof undefined listOfParsers
where where
listOfParsers = listOfParsers =
generate @Message1 @fs @fs (\ (_ :: proxy f) i -> let num = FieldNumber (fromInteger (succ i)) in [(num, fromJust <$> Decode.embedded (inject @f @fs <$> liftDecodeMessage decodeMessage num))]) generate @Message1 @fs @fs (\ (_ :: proxy f) i -> let num = fromInteger (succ i) in [(num, fromJust <$> Decode.embedded (inject @f @fs <$> liftDecodeMessage decodeMessage num'))])
liftDotProto _ = liftDotProto _ =
[Proto.DotProtoMessageOneOf (Proto.Single "syntax") (generate @Named1 @fs @fs (\ (_ :: proxy f) i -> [Proto.DotProtoMessageOneOf (Proto.Single "syntax") (generate @Named1 @fs @fs (\ (_ :: proxy f) i ->
let let