anz-bank / sysl

Sysl (pronounced "sizzle") is a system specification language
https://sysl.io
Apache License 2.0
122 stars 42 forks source link

Implement bytes length #995

Closed andrewemeryanz closed 3 years ago

andrewemeryanz commented 4 years ago

Description

The bytes type does not currently support the length constraint as the string type does currently.

For example, the following string.sysl:

App:
  !table T:
    s <: string(0..1024)

Produces the following in the generated proto structure (trimmed for brevity): sysl pb string.sysl

key: "s"
value: {
  primitive: STRING
  constraint: {
    length: {
      max: 1024
    }
  }
}

However, the following bytes.sysl:

App:
  !table T:
    b <: bytes(0..1024)

Produces an error while parsing.

Expected behavior

The bytes type should support the length constraint: sysl pb bytes.sysl

key: "b"
value: {
  primitive: BYTES
  constraint: {
    length: {
      max: 1024
    }
  }
}

Your Environment

$ sysl info
Build:
  Version      : v0.170.0
  Git Commit   : cb1ad4b5d238c3a7c78694b04466b15ec9de75ee
  Date         : 2020-07-31T07:22:34Z
  Go Version   : go1.13.14 linux/amd64
  OS           : darwin/amd64
andrewemeryanz commented 4 years ago

Upon inspection, this may be a simple as adding sysl.Type_BYTES to makeTypeConstraint in listener_impl.go.