1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15-- Test `.emb` for the `bits` construct. 16 17[$default byte_order: "LittleEndian"] 18[(cpp) namespace: "emboss::test"] 19 20 21bits OneByte: 22 7 [+1] Flag high_bit 23 6 [+1] Flag less_high_bit 24 2 [+4] UInt mid_nibble 25 1 [+1] Flag less_low_bit 26 0 [+1] Flag low_bit 27 28 29bits FourByte: 30 bits TwoByteWithGaps: 31 15 [+1] Flag high_bit 32 6 [+4] UInt mid_nibble 33 0 [+1] Flag low_bit 34 35 28 [+4] UInt high_nibble 36 20 [+8] OneByte one_byte 37 4 [+16] TwoByteWithGaps two_byte 38 0 [+4] UInt raw_low_nibble 39 # Check that the [requires] attribute works on bits fields just like it does 40 # on struct fields. 41 [requires: 1 <= this <= 15] 42 let low_nibble = raw_low_nibble + 100 43 44 45bits ArrayInBits: 46 15 [+1] Flag lone_flag 47 0 [+12] Flag[] flags 48 49 50struct ArrayInBitsInStruct: 51 0 [+2] ArrayInBits array_in_bits 52 53 54struct StructOfBits: 55 0 [+1] OneByte one_byte 56 1 [+2] FourByte.TwoByteWithGaps two_byte 57 3 [+4] FourByte four_byte 58 one_byte.mid_nibble [+1] UInt located_byte 59 60 61struct BitArray: 62 0 [+8] OneByte[8] one_byte 63